A 1145
#include<iostream>
using namespace std;
const int maxn=11111;
int msize,n,m;
int h[maxn];
bool isPrime(int x)
{
if(x==1)
return false;
for(int i=2; i*i<=x; i++)
if(x%i==0)
{
return false;
}
return true;
}
int find(int x,int &cnt)
{
int s=x%msize;
cnt=1;
for(int k=0; k<msize; k++,cnt++)
{
int t=(s+k*k)%msize;
if(!h[t] || h[t]==x)
return t;
}
return -1;
}
int main()
{
cin >> msize >> n >> m;
while(!isPrime(msize))
{
msize++;
}
for(int i=0; i<n; i++)
{
int x,count;
cin >> x;
if(find(x,count)==-1)
{
printf("%d cannot be inserted.\n",x);
}
else
h[find(x,count)]=x;
}
int cnt=0;
for(int i=0; i<m; i++)
{
int x,count;
cin >> x;
find(x,count);
cnt+=count;
}
printf("%.1lf\n",(double)cnt/m);
return 0;
}
2番目の検出方法:
A1137
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=10123;
struct node
{
int program;
int qizhong;
int qimo;
int fina;
node(): program(-1),qizhong(-1),qimo(-1),fina(-1) {
}
};
map<string,node> student;
struct node1
{
string name;
int grade;
}Node1[maxn];
int p,m,n;
bool cmp(node1 a, node1 b)
{
if(a.grade!=b.grade)
return a.grade>b.grade;
return a.name<b.name;
}
int main()
{
cin >> p >> m >> n;
string temp1;
int temp2;
for(int i=0; i<p; i++)
{
cin >> temp1 >> temp2;
student[temp1].program=temp2;
}
for(int i=0; i<m; i++)
{
cin >> temp1 >> temp2;
student[temp1].qizhong=temp2;
}
for(int i=0; i<n; i++)
{
cin >> temp1 >> temp2;
student[temp1].qimo=temp2;
}
int renshu=0;
for(map<string,node>::iterator it=student.begin(); it!=student.end(); it++)
{
double G;
if(it->second.qizhong>it->second.qimo)
G=round(it->second.qizhong*0.4+it->second.qimo*0.6);
else
G=it->second.qimo;
if(it->second.program>=200 && G>=60)
{
it->second.fina=G;
Node1[renshu].name=it->first;
Node1[renshu].grade=it->second.fina;
renshu++;
}
}
sort(Node1,Node1+renshu,cmp);
for(int i=0; i<renshu; i++)
{
cout << Node1[i].name << " " << student[Node1[i].name].program << " " << student[Node1[i].name].qizhong << " " << student[Node1[i].name].qimo << " " << Node1[i].grade << endl;
}
return 0;
}
A1149
#include<iostream>
#include<unordered_set>
using namespace std;
const int maxn=10010;
int n,m;
int a[maxn],b[maxn];
int main()
{
cin >> n >> m;
for(int i=0; i<n; i++)
{
cin >> a[i] >> b[i];
}
int temp,temp1;
while(m--)
{
cin >> temp;
unordered_set<int> S;
for(int i=0; i<temp; i++)
{
cin >> temp1;
S.insert(temp1);
}
bool flag=true;
for(int i=0; i<n; i++)
{
if(S.count(a[i]) && S.count(b[i]))
{
flag=false;
break;
}
}
if(flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
A1144
#include<iostream>
#include<set>
using namespace std;
int n;
set<int> a;
int main()
{
cin >> n;
int temp1;
for(int i=1; i<=n; i++)
{
cin >> temp1;
a.insert(temp1);
}
int k=1;
while(a.count(k))
{
k++;
}
cout << k;
return 0;
}
A1120
#include<iostream>
#include<set>
using namespace std;
set<int> a;
int n;
int he(int x)
{
int ans=0;
while(x!=0)
{
ans+=x%10;
x/=10;
}
return ans;
}
int main()
{
cin >> n;
int temp1;
for(int i=0; i<n; i++)
{
cin >> temp1;
a.insert(he(temp1));
}
cout << a.size() << endl;
for(set<int>::iterator it=a.begin(); it!=a.end(); it++)
{
if(it!=a.begin())
cout << " ";
cout << *it;
}
}