AtCoder Beginner Contest 090
A - Diagonal String
水题:记录直接输出就好
// // main.cpp // atcoder // // Created by cfhaiteeh on 11/03/2018. // Copyright © 2018 cfhaiteeh. All rights reserved. // #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std; char ch[4][4]; int main() { for(int i=1;i<=3;i++)scanf("%s",ch[i]+1); for(int i=1;i<=3;i++)printf("%c",ch[i][i]); printf("\n"); return 0; }
B - Palindromic Numbers
数据较小,判断记录总的多少就好
// // main.cpp // atcoder // // Created by cfhaiteeh on 11/03/2018. // Copyright © 2018 cfhaiteeh. All rights reserved. // #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std; char ch[4][4]; int ai[123456]; int ci[6]; int main() { for(int i=10000;i<=99999;i++){ int st=0; int t=i; while(t>0){ int p=t%10; t=t/10; ci[++st]=p; } bool flag=1; for(int j=1;j<=2;j++){ if(ci[j]==ci[5-j+1]){ continue; } flag=0; break; } if(flag)ai[i]=1; } for(int i=10000;i<=99999;i++)ai[i]+=ai[i-1]; int l,r; while(scanf("%d%d",&l,&r)!=EOF){ printf("%d\n",ai[r]-ai[l-1]); } return 0; }
C - Flip,Flip, and Flip......
找规律,特判就行
// // main.cpp // atcoder // // Created by cfhaiteeh on 11/03/2018. // Copyright © 2018 cfhaiteeh. All rights reserved. // #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #define LL long long using namespace std; LL n,m; LL ans; int main() { while(scanf("%lld%lld",&n,&m)!=EOF){ if(n>m)swap(n,m); if(n==1&&m==1)printf("1\n"); else { if(n==1)printf("%lld\n",m-2); else { LL ans=(n-2)*(m-2); printf("%lld\n",ans); } } } return 0; }
D - Remainder Reminder
对于除数进行枚举,易知当除数为i时,1~n的余数为1,2,。。。。0,1,2.。。。0 循环。所以只要直接判断n里有多少组1.2.。。0即可,对于不能整除时进行特判就行。复杂度为O(n)本人对0也进行了特判,主要感觉0怪怪的。。。//
// main.cpp // atcoder // // Created by cfhaiteeh on 11/03/2018. // Copyright © 2018 cfhaiteeh. All rights reserved. // #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #define LL long long using namespace std; LL n,m; LL ans; int main() { while(scanf("%lld%lld",&n,&m)!=EOF){ ans=0; if(m==0){ ans=n; for(int i=2;i<=n;i++){ LL p=n/i; ans+=p; } m=1; } for(LL i=m+1;i<=n;i++){ LL p=n/i; LL q=(n%i)-m+1; if(q<0)q=0; LL z=i-m; ans=ans+z*(p)+q; } printf("%lld\n",ans); } return 0; }