第一题:
坑爹的题目,读了好长时间的题意,幸好最后懂了,我好多同学最后都错了
在与判断只有一个数的情况下到底输不输出的问题。
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
const int N=105;
typedef long long LL;
int xh[N],cnt[N];
int k=0;
int main()
{
int i,n;
int c2=0;
cin>>n;
for(i=0;i<n;i++)
{
scanf("%d",&xh[i]);
if(xh[i]>=10&&xh[i]<=99&&xh[i]%10==0)
{
c2=xh[i];
}
}
sort(xh,xh+n);
int vis=0,vis2=0,vis22=0;
for(i=0;i<n;i++)
{
if(xh[i]==0||xh[i]==100)
cnt[++k]=xh[i];
if(xh[i]>=1&&xh[i]<=9&&vis==0)
{
cnt[++k]=xh[i];
vis=1;
}
if(xh[i]>=10&&xh[i]<=99)
{
if(c2!=0&&vis2==0)
{
cnt[++k]=c2;
vis2=1;
}
if(c2==0)
{
if(vis==0&&vis2==0)
{
cnt[++k]=xh[i];
vis2=1;
}
}
}
}
printf("%d\n",k);
for(i=1;i<k;i++)
printf("%d ",cnt[i]);
printf("%d\n",cnt[k]);
return 0;
}
第二题:
一看 水题,直接模拟,当时过了,最后果断wa了
因为可能在乘的情况下不能约分 会越界
经别人提醒,顺着做,看每个的除数是不是等于ai。
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
const int N=105;
typedef __int64 LL;
LL xh[N],p,q;
int n,i;
bool test()
{
LL t;
for(i=1;i<=n;i++)
{
if(q==0||(p/q)<xh[i])
return false;
t=p-xh[i]*q;
p=q;
q=t;
}
if(q!=0)
return false;
return true;
}
int main()
{
scanf("%I64d%I64d",&p,&q);
cin>>n;
for(i=1;i<=n;i++)
scanf("%I64d",&xh[i]);
if(test())
printf("YES\n");
else
printf("NO\n");
return 0;
}
第三题:
题目思路想出来了,但是就是实现不了。
经高人指点,用二进制位来表示,最后有多少个0就输出多少
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
const int N=100005;
typedef __int64 LL;
int save[110000];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
map<int,int>mymap;
map<int,int>::iterator it;
for(int i=1;i<=n;i++)
{
scanf("%d",&save[i]);
it=mymap.find(save[i]);
if(it==mymap.end())
{
mymap[save[i]]=1;
}
else
{
mymap.erase(it);
int temp=save[i]+1;
while(mymap.find(temp)!=mymap.end())
{
mymap.erase(temp);
temp++;
}
mymap[temp]=1;
}
}
it=mymap.begin();
int Max=-1,cnt=0;
for(;it!=mymap.end();it++)
{
cnt++;
Max=max(Max,it->first);
}
printf("%d\n",Max+1-cnt);
}
return 0;
}
第四题:
待续。。。
第五题:
待续。。。