标签:des style blog http io ar color os sp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 646 Accepted Submission(s): 284
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <vector> 6 #include <queue> 7 using namespace std; 8 9 #define N 105 10 11 int max(int x,int y){return x>y?x:y;} 12 int min(int x,int y){return x<y?x:y;} 13 int abs(int x,int y){return x<0?-x:x;} 14 15 int a[N]; 16 int n, m, k; 17 int from[N]; 18 bool visited[N]; 19 vector<int>ve[N]; 20 21 int march(int u){ 22 int i, v; 23 for(i=0;i<ve[u].size();i++){ 24 v=ve[u][i]; 25 if(!visited[v]){ 26 visited[v]=true; 27 if(from[v]==-1||march(from[v])){ 28 from[v]=u; 29 return 1; 30 } 31 } 32 } 33 return 0; 34 } 35 36 main() 37 { 38 int i, j; 39 cin>>m; 40 while(m--){ 41 scanf("%d %d",&n,&k); 42 for(i=1;i<=n;i++) scanf("%d",&a[i]); 43 for(i=0;i<=n;i++) ve[i].clear(); 44 bool flag; 45 for(i=1;i<=n;i++){ 46 flag=false; 47 for(j=0;j<=i;j++){ 48 if(a[i]+j*k<=n&&(a[i]+j*k)) { 49 ve[i].push_back(a[i]+j*k); 50 } 51 else break; 52 } 53 } 54 55 memset(from,-1,sizeof(from)); 56 int ans=0; 57 for(i=1;i<=n;i++){ 58 memset(visited,false,sizeof(visited)); 59 if(march(i)) ans++; 60 } 61 if(ans!=n) printf("Tom\n"); 62 else printf("Jerry\n"); 63 } 64 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/qq1012662902/p/4127488.html