2014 Multi-University Training Contest 7
官方解题报告:http://blog.sina.com.cn/s/blog_a19ad7a10102uzd4.html
Magical Forest http://acm.hdu.edu.cn/showproblem.php?pid=4941
1 #include<cstdio> 2 #include<map> 3 using namespace std; 4 typedef pair<int,int> pii; 5 map<pii,int> cost; 6 map<int,int> mpx,mpy; 7 int main(){ 8 int t,n,m,k,x,y,z; 9 while(~scanf("%d",&t)){ 10 for(int cas=1;cas<=t;cas++){ 11 scanf("%d%d%d",&n,&m,&k); 12 cost.clear(); 13 mpx.clear(); 14 mpy.clear(); 15 while(k--){ 16 scanf("%d%d%d",&x,&y,&z); 17 x++; 18 y++; 19 mpx[x]=x; 20 mpy[y]=y; 21 cost[make_pair(x,y)]=z; 22 } 23 scanf("%d",&k); 24 printf("Case #%d:\n",cas); 25 while(k--){ 26 scanf("%d%d%d",&z,&x,&y); 27 x++; 28 y++; 29 if(z==1){ 30 if(mpx[x]&&mpx[y]){ 31 swap(mpx[x],mpx[y]); 32 } 33 } 34 else if(z==2){ 35 if(mpy[x]&&mpy[y]){ 36 swap(mpy[x],mpy[y]); 37 } 38 } 39 else{ 40 printf("%d\n",cost[make_pair(mpx[x],mpy[y])]); 41 } 42 } 43 } 44 } 45 return 0; 46 }
end