HDU 4941 Magical Forest

用map存信息,各种标记,各种。。。写的很乱,表在意。。。

 

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <map>
 5 using namespace std;
 6 
 7     map <int,int> mm[100005];
 8     map <int,int> c;
 9     map <int,int> r;
10     map <int,int> ys;
11 int main (){
12     int n,m,k;
13     int w;
14     scanf ("%d",&w);
15     for (int kase=1;kase<=w;kase++){
16         c.clear();
17         r.clear();
18         ys.clear() ;
19         scanf ("%d%d%d",&n,&m,&k);//n>>m>>k;
20         for (int i=0;i<=k;i++)
21             mm[i].clear() ;
22         for (int i=1;i<=k;i++){
23             int x,y,p;
24             scanf ("%d%d%d",&x,&y,&p);
25             //cin>>x>>y>>p;
26             x++;y++;
27             r[x]=x;c[y]=y;
28             //mm[z]=c;
29             if (ys[x]==0)
30                 ys[x]=i;
31             mm[ys[x]][y]=p;
32         }
33         int t;
34         scanf ("%d",&t);
35         //cin>>t;
36         printf ("Case #%d:\n",kase);
37         //cout<<"Case #"<<kase<<":"<<endl;
38         while (t--){
39             int q,a,b;
40                 int temp;
41             scanf ("%d%d%d",&q,&a,&b);
42             //cin>>q>>a>>b;
43             a++;b++;
44             if (q==1){
45                 if (r[a]&&r[b])
46                     temp=r[a];r[a]=r[b];r[b]=temp;
47             }
48             else if (q==2){
49                 if (c[a]&&c[b])
50                     temp=c[a];c[a]=c[b];c[b]=temp;
51             }
52             else {
53                 if (r[a]&&c[b])
54                     printf ("%d\n",mm[ys[r[a]]][c[b]]);
55                 else printf ("0\n");
56             }
57         }
58     }
59     return 0;
60 }

 

你可能感兴趣的:(REST)