Magical Forest
However, the forest will make the following change sometimes:
1. Two
rows of forest exchange.
2. Two columns of forest exchange.
Fortunately,
two rows(columns) can exchange only if both of them contain fruits or none of
them contain fruits.
Your superior attach importance to these magical
fruit, he needs to know this forest information at any time, and you as his best
programmer, you need to write a program in order to ask his answers quick every
time.
The
first line has one integer W. Indicates the case
number.(1<=W<=5)
For each case, the first line has three integers
N, M, K. Indicates that the forest can be seen as maps N rows, M columns, there
are K fruits on the map.(1<=N, M<=2*10^9, 0<=K<=10^5)
The
next K lines, each line has three integers X, Y, C, indicates that there is a
fruit with C energy in X row, Y column. (0<=X<=N-1, 0<=Y<=M-1,
1<=C<=1000)
The next line has one integer T.
(0<=T<=10^5)
The next T lines, each line has three integers Q, A, B.
If Q = 1 indicates that this is a map of the row switching operation, the A
row and B row exchange.
If Q = 2 indicates that this is a map of the column
switching operation, the A column and B column exchange.
If Q = 3 means that
it is time to ask your boss for the map, asked about the situation in (A, B).
(Ensure that all given A, B are legal. )
In each case, for
every time the boss asked, output an integer X, if asked point have fruit, then
the output is the energy of the fruit, otherwise the output is 0
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm> using namespace std; struct Node
{
int x;
int y;
int c;
}l[]; map <int, map<int, int> > fmap;
map <int ,int>hashx,hashy;
int T,n,m,k,mapx,mapy,t,cas,lianx[],liany[],Q,A,B,X,Y; bool cmpx(Node a,Node b)
{
return a.x<b.x;
}
bool cmpy(Node a,Node b)
{
return a.y<b.y;
} int main()
{
int CAS;
scanf("%d", &CAS);
for(int cas=;cas<=CAS;cas++)
{
scanf("%d%d%d",&n,&m,&k);
printf("Case #%d:\n",cas);
for(int i=;i<k;i++)scanf("%d%d%d",&l[i].x,&l[i].y,&l[i].c);
fmap.clear();hashx.clear();hashy.clear();mapx=mapy=;
sort(l,l+k,cmpx);
for(int i=;i<k;i++)if(!hashx[l[i].x])hashx[l[i].x]=++mapx;
sort(l,l+k,cmpy);
for(int i=;i<k;i++)
{
if(!hashy[l[i].y])hashy[l[i].y]=++mapy;
fmap[hashx[l[i].x]][hashy[l[i].y]]=l[i].c;
}
for(int i=;i<=mapx;i++)lianx[i]=i;
for(int i=;i<=mapy;i++)liany[i]=i;
scanf("%d",&t);
for(int i=;i<t;i++)
{
scanf("%d%d%d",&Q,&A,&B);
if(Q==)
{
X=hashx[A];Y=hashx[B];
if(X && Y)swap(lianx[X],lianx[Y]);
}
else if(Q==)
{
X=hashy[A];Y=hashy[B];
if(X && Y)swap(liany[X],liany[Y]);
}
else if(Q==)
{
X=hashx[A];Y=hashy[B];
if(X && Y)printf("%d\n",fmap[lianx[X]][liany[Y]]);
else printf("0\n");
}
}
}
return ;
}
Magical Forest的更多相关文章
- STL : map函数的运用 --- hdu 4941 : Magical Forest
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- hdu4941 Magical Forest (stl map)
2014多校7最水的题 Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit ...
- hdu 4941 Magical Forest
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...
- hdu 4941 Magical Forest (map容器)
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- hdu4941 Magical Forest
Problem Description There is a forest can be seen as N * M grid. In this forest, there is some magic ...
- HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)
思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行 . r[i] 表示第 i 行存的是 原先的哪行 c[j] 表示 第 j ...
- HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...
- HDU 4941 Magical Forest --STL Map应用
题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...
- HDU 4941 Magical Forest 【离散化】【map】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...
随机推荐
- java StreamTokenizer使用
注意:用JAVA解题一般用Scanner类来进行输入,但对时间要求严格的题,用它可能会超时,我.解POJ1823的时候就遇到这样的问题,后改用StreamTokenizer类进行输入,就过了.看来后者 ...
- 转载:mac系统XAMPP配置虚拟主机
安装完xampp后,想添加一个virsualhost,一直报错.查了半天资料,都是乱说,后来看到了一篇国外的文章,终于弄出来了,整理一下. 第一步,配置本地hosts sudo vi /etc/hos ...
- GCC4.8对new和delete的参数匹配新要求
一段通信协议的代码,早年在GCC 4.4.VS2013下编译都挺好的,移植到GCC 4.8 ,为C++ 11做准备,在编译的时候发现问题 源代码省略后的版本如下: class Zerg_App_Fra ...
- Makefile 知识点
$@ $@ is the name of the target. $? The $? macro stores the list of dependents more recent than the ...
- Java缓存学习之二:浏览器缓存机制
浏览器端的九种缓存机制介绍 浏览器缓存是浏览器端保存数据用于快速读取或避免重复资源请求的优化机制,有效的缓存使用可以避免重复的网络请求和浏览器快速地读取本地数据,整体上加速网页展示给用户.浏览器端缓存 ...
- nginx 502 错误
今天帮朋友处理一个程序报错,重启nginx服务之后,发现首页打不开了,但是静态文件可以打开 经检查nginx 服务器正常运行,重启无数次仍然502错误,考虑到静态文件可以打开,怀疑可能是php 脚本程 ...
- [C语言 - 5] 预处理
编译之前的处理指令 A.宏定义 a. //Like static constant #define NUM 6 //The truth of macro define is replacing the ...
- 做XH2.54杜邦线材料-导线
好多市场上买的杜邦线质量一般,今天选了一种别的线 线色:红 黑 黄 绿 白 棕 蓝 线规:正标UL1007-24AWG 产品说明: * UL1007电子连接线 * 线号:24 ...
- POJ1062昂贵的聘礼(dijkstra)
昂贵的聘礼 题目大意是说有N个物品,每个物品都有自己的价格,但同时某些物品也可以由其他的(可能不止一个)替代品,这些替代品的价格比较“优惠”,问怎么样选取可以让你的花费最少来购买到物品1 由于有N个物 ...
- 苹果所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程(精)
holydancer原创,如需转载,请在显要位置注明: 转自holydancer的CSDN专栏,原文地址:http://blog.csdn.net/holydancer/article/details ...