6.4周四训练课
wenxuan1086 · · 个人记录
T710875 小田的修行
题意分析
他是要我们统计每次统计数字出现次数
然后按数字从小到大输出 数字 个数
思路
用桶就行了,没什么好讲的。
::::success[正确代码]
#include <bits/stdc++.h>
using namespace std;
int a[100005],b[10005];
bool f[10005];
int main()
{
memset(b,0,sizeof(b));
int n,x;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
b[a[i]+1000]++;
}
for(int i = 1; i <= n; i++)
{
if(!f[a[i]+1000]) cout << a[i] << " " << b[a[i]+1000] << "\n";
f[a[i]+1000]=1;
}
return 0;
}
:::: ::::info[备注]
-
a \bmod b = 0 , c \bmod b=0
每个数都得分组,如果不行,就输出-1
思路
用桶统计
1.特判
如果有质数(-1(没有整除)
列举可能
只有3种可能:
- 1.1 3 6
- 2.1 2 4
- 3.1 2 6
1 2 6重复了,而且刚好是第3种,就拿他们消除(不消除的计数有多少个这种可能),1 2 6数量一样,直接拿来统计第3种(如果个数不同,就输出-1)
3.消除
每一次消除最后有判定,消除后是否<0,是就输出-1
1,6的个数-3的个数
1,2的个数-4的个数
1,2,6的个数直接拿来统计第3种(如果个数不同,就输出-1)
4.输出
用
::::error[错误代码]
#include <bits/stdc++.h>
#define endl '\n';
using namespace std;
int a[1000005];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,cnt=0;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a+1,a+n+1);
for(int i = 1; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
for(int k = j; k <= n; k++)
{//a[k]
if(a[j]%a[i]==0 && a[k]%a[j]==0 && a[j]>a[i] && a[k]>a[j]) {cout << a[i] << " " << a[j] << " " << a[k] << "\n";cnt++;}
if(cnt==n/3) return 0;
}
}
}
cout << "-1";
return 0;
}
:::: ::::success[正确代码]
#include <bits/stdc++.h>
#define endl '\n';
using namespace std;
int a[9];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
int x;
cin >> x;
a[x]++;
}
if(a[5]>0 || a[7]>0)
{
cout << -1;
return 0;
}
a[1]-=a[3];
a[6]-=a[3];
if(a[1]<0 || a[6]<0)
{
cout << -1;
return 0;
}
a[1]-=a[4];
a[2]-=a[4];
if(a[1]<0 || a[2]<0)
{
cout << -1;
return 0;
}
if(a[1]!=a[2] || a[2]!=a[6])
{
cout << -1;
return 0;
}
while(a[3]--)
{
cout << "1 3 6\n";
}
while(a[4]--)
{
cout << "1 2 4\n";
}
while(a[1]--)
{
cout << "1 2 6\n";
}
return 0;
}
:::: ::::warning[错因] 哎呀妈呀,这么难做,只能挨搞 ::::