目录
Counterfeit Dollarhttp://noi.openjudge.cn/ch0201/15/
数字方格http://noi.openjudge.cn/ch0201/1749/
鸡兔同笼 |
完美立方 |
满足条件的整数 |
比赛排名http://noi.openjudge.cn/ch0201/2673/
和数 |
制作不易,希望对你有帮助
1.15
15 | Counterfeit Dollar |
解法:
#include<iostream> #include<cstring> using namespace std; #define ll long long int book[200]; int w[200]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin>>T; while(T--){ memset(book,-1,sizeof(book)); memset(w,0,sizeof(w)); string a[4],b[4],c[4]; for(register int i=0;i<3;i++){ cin>>a[i]>>b[i]>>c[i]; } for(register int i=0;i<3;i++){ for(register int j=0;j<a[i].size();j++){ if(c[i]=="even"){ if(book[a[i][j]]==-1) book[a[i][j]]=0; else if(book[a[i][j]]!=-1&&book[a[i][j]]!=0){ w[a[i][j]]++; book[a[i][j]]=0; } } else if(c[i]=="up"){ if(book[a[i][j]]==-1) book[a[i][j]]=2; else if(book[a[i][j]]!=2){ w[a[i][j]]++; book[a[i][j]]=2; } } else if(c[i]=="down"){ if(book[a[i][j]]==-1) book[a[i][j]]=1; else if(book[a[i][j]]!=1){ w[a[i][j]]++; book[a[i][j]]=1; } } } for(register int j=0;j<b[i].size();j++){ if(c[i]=="even"){ if(book[b[i][j]]==-1){ book[b[i][j]]=0; } else if(book[b[i][j]]!=0){ w[b[i][j]]++; book[b[i][j]]=0; } } else if(c[i]=="up"){ if(book[b[i][j]]==-1) book[b[i][j]]=1; else if(book[b[i][j]]!=1){ w[b[i][j]]++; book[b[i][j]]=1; } } else if(c[i]=="down"){ if(book[b[i][j]]==-1) book[b[i][j]]=2; else if(book[b[i][j]]!=2){ w[b[i][j]]++; book[b[i][j]]=2; } } } } int t; for(register int i=0;i<3;i++){ if(c[i]!="even") t=i; } int flag=0; for(register int i=0;i<a[t].size();i++){ if(!w[a[t][i]]){ if(c[t]=="up"){ cout<<a[t][i]<<" is the counterfeit coin and it is heavy."<<endl; } else if(c[t]=="down") cout<<a[t][i]<<" is the counterfeit coin and it is light."<<endl; flag=1; break; } } if(flag)continue; for(register int i=0;i<b[t].size();i++){ if(!w[b[t][i]]){ if(c[t]=="up") cout<<b[t][i]<<" is the counterfeit coin and it is light."<<endl; else if(c[t]=="down") cout<<b[t][i]<<" is the counterfeit coin and it is heavy."<<endl; break; } } } }
2.1749
1749 | 数字方格 |
解法:
#include<stdio.h> main() { int n,a1,a2,a3,max=0;//max要累加所以有初值 scanf("%d",&n); for(a1=0;a1<=n;a1++) { for(a2=0;a2<=n;a2++) { for(a3=0;a3<=n;a3++) { if((a1+a2)%2==0&&(a3+a2)%3==0&&(a1+a2+a3)%5==0&&max<(a1+a2+a3))//判断条件 max=a1+a2+a3; } } } printf("%d",max);//输出 }
3.1752
1752 | 鸡兔同笼 |
解法:
#include<stdio.h> main() { int a,b,c,max=0,min; scanf("%d",&a); min=a; if(a%4==0) printf("%d %d",a/4,a/2); else if(a%2==0) printf("%d %d",a/4+1,a/2); else printf("0 0"); }
4.1812
1812 | 完美立方 |
解法:
#include<stdio.h> main() { int n,a,b,c,d; scanf("%d",&n); for(a=2;a<=n;a++) { for(b=2;b<=n;b++) { for(c=2;c<=n;c++) { for(d=2;d<=n;d++) if(a*a*a==b*b*b+c*c*c+d*d*d&&b<=c&&c<=d) printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d); } } } }
5.1943
1943 | 满足条件的整数 |
解法:
#include<stdio.h> main() { int a,b,c; for(a=1;a<=100;a++) { for(b=1;b<=100;b++) { for(c=1;c<=100;c++) { if(a<=b&&b<c&&(a*a+b*b)==c*c) printf("%d*%d + %d*%d = %d*%d\n",a,a,b,b,c,c); } } } }
6.2673
2673 | 比赛排名 |
解法:
#include<bits/stdc++.h> using namespace std; int main() { printf("5\n2\n1\n3\n4\n"); }
7.2722
2722 | 和数 |
解法:
#include<stdio.h> main() { int n,i,j,k,a[1005],b[20005]={0},t=0;//变量b的空间=10000*2+5 scanf("%d",&n);//输入n for(i=1;i<=n;i++)//循环n次 scanf("%d",&a[i]);//每次输入a【i】 for(k=1;k<=n;k++)//循环n次 for(i=1;i<=n-1;i++)//循环n-1次 for(j=i+1;j<=n;j++) if(a[k]==a[i]+a[j]&&b[a[k]]==0) { t++; b[a[k]]=1; } printf("%d",t);//输出t }
点赞超过3个日更!!!
制作不易