[NOIp2008]题解
ISBN号码 T1:
1 #include<iostream> 2 #include<stdio.h> 3 #include<string> 4 using namespace std; 5 char ch; 6 string buf; 7 int n,t,k,f[20],sum; 8 int main() 9 { 10 freopen("isbn.in","r",stdin); 11 freopen("isbn.out","w",stdout); 12 char s[13]; 13 int a[10]; 14 int sum=0,i,k; 15 gets(s); 16 a[0]=s[0]-'0'; 17 a[1]=s[2]-'0'; 18 a[2]=s[3]-'0'; 19 a[3]=s[4]-'0'; 20 a[4]=s[6]-'0'; 21 a[5]=s[7]-'0'; 22 a[6]=s[8]-'0'; 23 a[7]=s[9]-'0'; 24 a[8]=s[10]-'0'; 25 a[9]=s[12]-'0'; 26 for(i=0; i<9; i++) 27 sum=sum+a[i]*(i+1); 28 k=sum%11; 29 if(k==a[9]||s[12]=='X'&&k==10) 30 cout<<"Right"; 31 else 32 { 33 for(i=0;i<12;i++) 34 cout<<s[i]; 35 if(k==10) cout<<"X"; 36 else cout<<k; 37 } 38 return 0; 39 }
排座位 T2:
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #define min(a,b) a<b?a:b 5 #define N 2000 6 using namespace std; 7 struct note{int set,num;}K[N+10],L[N+10]; 8 int m,n,k,l,d,x,y,p,q,oputk[N+10],oputl[N+10]; 9 bool comp(note x,note y) 10 { 11 return x.num>y.num; 12 } 13 void init() 14 { 15 scanf("%d%d%d%d%d",&m,&n,&k,&l,&d); 16 for(int i=1;i<m;++i) 17 K[i].set=i,K[i].num=0; 18 for(int i=1;i<n;++i) 19 L[i].set=i,L[i].num=0; 20 for(int i=1;i<=d;++i) 21 { 22 scanf("%d%d%d%d",&x,&y,&p,&q); 23 if(x!=p) ++K[min(x,p)].num; 24 else ++L[min(y,q)].num; 25 } 26 } 27 int main() 28 { 29 freopen("seat.in","r",stdin); 30 freopen("seat.out","w",stdout); 31 init(); 32 sort(K+1,K+m,comp); 33 sort(L+1,L+n,comp); 34 for(int i=1;i<=k;++i) oputk[i]=K[i].set; 35 for(int i=1;i<=l;++i) oputl[i]=L[i].set; 36 sort(oputk+1,oputk+k+1); 37 sort(oputl+1,oputl+l+1); 38 for(int i=1;i<=k;++i) 39 printf("%d ",oputk[i]); 40 printf("\n"); 41 for(int i=1;i<=l;++i) 42 printf("%d ",oputl[i]); 43 }
传球游戏 T3:
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int n,m,dp[30][30]; 5 int main() 6 { 7 freopen("ball.in","r",stdin); 8 freopen("ball.out","w",stdout); 9 scanf("%d%d",&n,&m); 10 dp[0][1]=1; 11 for(int i=1;i<=m;++i) 12 for(int j=1;j<=n;++j) 13 { 14 if(j==1) 15 dp[i][n]+=dp[i-1][j],dp[i][j+1]+=dp[i-1][j]; 16 else 17 if(j==n) 18 dp[i][j-1]+=dp[i-1][j],dp[i][1]+=dp[i-1][j]; 19 else 20 dp[i][j-1]+=dp[i-1][j],dp[i][j+1]+=dp[i-1][j]; 21 } 22 23 printf("%d",dp[m][1]); 24 }