codeforces 984a
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 int num[1010]; 5 int main(){ 6 scanf("%d",&n); 7 for(int i=1;i<=n;i++) scanf("%d",&num[i]); 8 sort(num+1,num+n+1); 9 if(n%2==1) printf("%d",num[(n+1)/2]); 10 else printf("%d",num[n/2]); 11 return 0; 12 }
codeforces 984b
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m; 4 char sz[110][110]; 5 int divs[8][2]={{0,1},{0,-1},{1,0},{-1,0},{-1,-1},{1,-1},{-1,1},{1,1}}; 6 int main(){ 7 while(scanf("%d%d",&n,&m)!=EOF){ 8 for(int i=1;i<=n;i++) scanf("%s",sz[i]+1); 9 for(int i=1;i<=n;i++){ 10 for(int j=1;j<=m;j++){ 11 if(sz[i][j]==‘*‘) continue; 12 else if(sz[i][j]==‘.‘){ 13 for(int k=0;k<8;k++){ 14 int x=i+divs[k][0],y=j+divs[k][1]; 15 if(x>=1&&x<=n&&y>=1&&y<=m){ 16 if(sz[x][y]==‘*‘){printf("NO\n");return 0;} 17 } 18 } 19 }else{ 20 int num=sz[i][j]-‘0‘; 21 for(int k=0;k<8;k++){ 22 int x=i+divs[k][0],y=j+divs[k][1]; 23 if(x>=1&&x<=n&&y>=1&&y<=m){ 24 if(sz[x][y]==‘*‘){num--;} 25 } 26 } 27 if(num!=0) { printf("NO\n");return 0;} 28 } 29 //if(i==n&&j==m) printf("sbsbsbsb\n"); 30 } 31 } 32 //printf("sbbsbsbsbsb\n"); 33 printf("YES\n"); 34 } 35 return 0; 36 }
先跳过c题补一下d题
codeforces984d 先贴一下链接:看了别人的代码: https://blog.csdn.net/qq_39599067/article/details/80335949
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,q; 4 int num[5010]; 5 int dp[5010][5010],f[5010][5010]; 6 int main(){ 7 scanf("%d",&n); 8 for(int i=1;i<=n;i++){ 9 scanf("%d",&num[i]); 10 dp[i][i]=f[i][i]=num[i]; 11 } 12 for(int j=2;j<=n;j++){ 13 for(int i=j-1;i>=1;i--){ 14 f[i][j]=f[i][j-1]^f[i+1][j]; 15 dp[i][j]=max(f[i][j],max(dp[i][j-1],dp[i+1][j])); 16 } 17 } 18 scanf("%d",&q); 19 while(q--){ 20 int l,r; 21 scanf("%d%d",&l,&r); 22 cout<<dp[l][r]<<endl; 23 } 24 return 0; 25 }
codeforces c题 还是贴一个别人的链接 https://blog.csdn.net/xs18952904/article/details/80331434
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 int n; 5 LL p,q,c; 6 7 LL gcd(LL a,LL b){ 8 if(b==0) return a; 9 else return gcd(b,a%b); 10 } 11 12 int main(){ 13 scanf("%d",&n); 14 while(n--){ 15 scanf("%lld%lld%lld",&p,&q,&c); 16 //printf("%d\n",gcd(p,q)); 17 q=q/gcd(p,q); 18 //printf("%d\n",q); 19 while(gcd(q,c)!=1){ 20 LL tmp=gcd(q,c); 21 while(q%tmp==0) q=q/tmp; 22 } 23 if(q==1) printf("Finite\n"); 24 else printf("Infinite\n"); 25 } 26 return 0; 27 }
原文地址:https://www.cnblogs.com/pandaking/p/9739624.html
时间: 2024-10-12 22:15:39