本文主要是介绍130722练习赛CF,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A. Bit++
超水题,之间判断字符串里是否有‘+’或‘-’,然后就相应++或--。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main()
{int n,i,x,j;char a[11];cin>>n;x=0;for(i=0;i<n;++i){scanf("%s",a);for(j=0;j<strlen(a);++j){if(a[j]=='+'){x++;break;}if(a[j]=='-'){x--;break;}}}cout<<x<<endl;return 0;
}
B. Painting Eggs
贪心问题,A和G总工资小于500就行。。。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
char s[1000001];
int main()
{int n,k=0,i;long long sa=0,sg=0,a,g;scanf("%d",&n);for(i=0; i<n; ++i){scanf("%lld%lld",&a,&g);if((sa+a)<(sg+500)){sa+=a;s[k]='A';++k;}else{sg+=g;s[k]='G';++k;}}if(max(sa,sg)-min(sa,sg)>500){printf("-1\n");}else{printf("%s\n",s);}return 0;
}
YY题,只要长度都相等,并且两个字符串里都有‘1’或者两个字符串里都是‘0’(即S1=S2)。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
char a[1000005],b[1000005];
int main()
{int i,j,l1,l2,f,g;scanf("%s%s",a,b);l1=strlen(a);l2=strlen(b);if(l1==l2){f=0;for(i=0;i<l1;++i){if(a[i]=='1'){f=1;}}g=0;for(i=0;i<l2;++i){if(b[i]=='1'){g=1;}}if((f==1&&g==1)||(f==0&&g==0)){printf("YES\n");}else{printf("NO\n");}}else{printf("NO\n");}return 0;
}
D. Yet Another Number Game
三种博弈的集合体,当n=1时,为巴什博弈,当n=2时,为威佐夫博弈,当n=3时,为尼姆博弈。。所以可以分情况讨论。。。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int sg[333];
int main()
{int n,i,a[4],sum,tt;bool f=false;scanf("%d",&n);if(n==1)//巴什博弈{scanf("%d",&a[0]);f=a[0];if(!f){printf("BitAryo\n");}else{printf("BitLGM\n");}}else if(n==3)//尼姆博弈{sum=0;for(i=0;i<3;++i){scanf("%d",&a[i]);}for(i=0;i<3;++i){sum=sum^a[i];}f=sum;if(!f){printf("BitAryo\n");}else{printf("BitLGM\n");}}else if(n==2)//威佐夫博弈(还是写得复杂了){scanf("%d%d",&a[0],&a[1]);memset(sg,-1,sizeof(sg));sort(a,a+n);tt=1;for(i=1;i<=300;++i){if(sg[i]==-1){sg[i]=i+tt;if(i+tt<=300){sg[i+tt]=0;}tt++;}}if(!a[0]){f=a[1];}else{f=(sg[a[0]]!=a[1]);}if(!f){printf("BitAryo\n");}else{printf("BitLGM\n");}}return 0;
}
E题字典树,,,说实话没看出来。。。。
这篇关于130722练习赛CF的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!