Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛过来看一下,测试数据通过了,就是wa,郁闷呀#include <stdio.h> #include <math.h> #include <algorithm> using namespace std; #include <string.h> int a[35],b[20],c[40]; int com(int m,int n) { int i; double result=1; if(n>=m-n) n=m-n; for(i=1;i<=n;i++) result*=(m-i+1)/double(i); if(result==(int)result) return result; return result+1; } int solve(char *s) { int len,sum=0,i; len=strlen(s); for(i=0;i<len;i++) { s[i]=s[i]-'0'; sum+=s[i]*pow(2.0,double(len-i-1)); } return sum; } int main() { int n,k,i,len,p,q,j; char s[50]; //printf("%d\n",com(10,2)); while(scanf("%d",&n)!=EOF&&n) { for(i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&k); for(i=1;i<=k;i++) { p=0; for(j=0;j<40;j++) c[j]=0; scanf("%s",s); for(j=1;j<=n/2;j++) { scanf("%d",&b[j]); for(q=1;q<=n;q++) { if(a[q]==b[j]) { c[++p]=q; break; } } } sort(c+1,c+n/2+1); /*for(j=1;j<=n/2;j++) printf("%d ",c[j]); printf("\n");*/ int sum=0; for(j=1;j<=n/2;j++) { for(q=c[j-1]+1;q<c[j];q++) sum+=com(n-q,n/2-j); //printf("%d\n",sum); } //printf("%d %d\n",sum,solve(s)); if(sum==solve(s)) printf("TRUE\n"); else printf("FALSE\n"); //printf("%d\n",sum); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator