STL map 记录对应原图是第几行/列
1 3 3 2 1 1 1 2 2 2 5 3 1 1 1 1 2 2 1 2 3 1 1 3 2 2
Case #1: 1 2 1HintNo two fruits at the same location.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pII;
map<pII,int> go;
map<int,int> hang;
map<int,int> lie;
int n,m,k,t;
int main()
{
int T_T,cas=1;
scanf("%d",&T_T);
while(T_T--)
{
go.clear(); hang.clear(); lie.clear();
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<k;i++)
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
go[make_pair(x,y)]=c;
hang[x]=x; lie[y]=y;
}
scanf("%d",&t);
printf("Case #%d:\n",cas++);
while(t--)
{
int q,x,y;
scanf("%d%d%d",&q,&x,&y);
if(q==1)
{
int tx,ty;
if(hang.count(x)==0)
hang[x]=x;
tx=hang[x];
if(hang.count(y)==0)
hang[y]=y;
ty=hang[y];
hang[x]=ty; hang[y]=tx;
}
else if(q==2)
{
int tx,ty;
if(lie.count(x)==0)
lie[x]=x;
tx=lie[x];
if(lie.count(y)==0)
lie[y]=y;
ty=lie[y];
lie[x]=ty; lie[y]=tx;
}
else if(q==3)
{
int tx,ty;
if(hang.count(x)==0)
tx=x;
else tx=hang[x];
if(lie.count(y)==0)
ty=y;
else ty=lie[y];
printf("%d\n",go[make_pair(tx,ty)]);
}
}
}
return 0;
}
HDOJ 4941 Magical Forest,布布扣,bubuko.com
原文:http://blog.csdn.net/ck_boss/article/details/38523739