标签:
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<math.h> 7 #include<algorithm> 8 #include<queue> 9 #include<set> 10 #include<bitset> 11 #include<map> 12 #include<vector> 13 #include<stdlib.h> 14 using namespace std; 15 #define ll long long 16 #define eps 1e-10 17 #define MOD 1000000007 18 #define N 1000000 19 #define inf 1e12 20 int a,b,c; 21 int mp[3][27]; 22 int mpp[3][27]; 23 int vis[27]; 24 int main() 25 { 26 int t; 27 scanf("%d",&t); 28 while(t--){ 29 memset(mpp,0,sizeof(mpp)); 30 31 scanf("%d%d%d",&a,&b,&c); 32 char s[2]; 33 int cnt; 34 for(int i=0;i<a;i++){ 35 scanf("%s%d",s,&cnt); 36 int index = s[0]-‘A‘; 37 mpp[0][index]+=cnt; 38 //printf("1---%d\n",mp[0][index]); 39 } 40 for(int i=a;i<a+b;i++){ 41 scanf("%s%d",s,&cnt); 42 int index = s[0]-‘A‘; 43 mpp[1][index]+=cnt; 44 //printf("2---%d\n",mp[1][index]); 45 } 46 for(int i=a+b;i<a+b+c;i++){ 47 scanf("%s%d",s,&cnt); 48 int index = s[0]-‘A‘; 49 mpp[2][index]+=cnt; 50 //printf("3---%d\n",mp[2][index]); 51 } 52 53 int i,j; 54 int flag=0; 55 for(i=1;i<=1006;i++){ 56 for(j=1;j<=1006;j++){ 57 for(int k=0;k<26;k++){ 58 mp[0][k]=mpp[0][k]; 59 mp[1][k]=mpp[1][k]; 60 mp[2][k]=mpp[2][k]; 61 } 62 memset(vis,0,sizeof(vis)); 63 for(int k=0;k<26;k++){ 64 mp[0][k]*=i; 65 mp[1][k]*=j; 66 } 67 int w=1; 68 for(int k=0;k<26;k++){ 69 if(mp[2][k]){ 70 if(mp[0][k]+mp[1][k] == mp[2][k]){ 71 vis[k]=1; 72 }else{ 73 w=0; 74 break; 75 } 76 } 77 } 78 79 if(w==1){ 80 for(int k=0;k<26;k++){ 81 if(vis[k]==0 && (mp[0][k] || mp[1][k] || mp[2][k])){ 82 w=0; 83 break; 84 } 85 } 86 } 87 if(w==1){ 88 flag=1; 89 break; 90 } 91 } 92 if(flag==1) break; 93 } 94 if(flag==1){ 95 printf("%d %d\n",i,j); 96 }else{ 97 printf("NO\n"); 98 } 99 } 100 return 0; 101 } 102 103 //A 6 2 12 104 //B 6 3 18 105 //C 12 5 60
标签:
原文地址:http://www.cnblogs.com/UniqueColor/p/5188319.html