Problem Description
There is a forest can be seen as N * M grid. In this forest, there is some magical fruits, These fruits can provide a lot of energy, Each fruit has its location(Xi, Yi) and the energy can be provided Ci.

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.

 
Input
The input consists of multiple test cases.

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. )

Output
For each case, you should output "Case #C:" first, where C indicates the case number and counts from 1.

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

input
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
output
Case #1:
1
2
1
考察离散化的模拟题。
 #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的更多相关文章

  1. STL : map函数的运用 --- hdu 4941 : Magical Forest

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  2. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

  3. hdu 4941 Magical Forest

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...

  4. hdu 4941 Magical Forest (map容器)

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  5. hdu4941 Magical Forest

    Problem Description There is a forest can be seen as N * M grid. In this forest, there is some magic ...

  6. HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)

    思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   . r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j ...

  7. HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...

  8. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  9. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

随机推荐

  1. Google Accounts,OpenID,OAuth

    App Engine以与Google Accounts的集成为其特色.Google Accounts是被Google应用程序如:Google Mail.Google Docs.Google Calen ...

  2. ramips芯片,openwrt安装njit8021xclient

    1.软件安装包 http://pan.baidu.com/s/1tcY2p 解压并通过winscp上传至路由器,利用putty进入控制台,依次输入以下4条命令,每次输入后点一次执行opkg insta ...

  3. SCAU 07校赛 10317 Fans of Footbal Teams

    10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description Two famous footba ...

  4. VB IE 清除历史记录

    VB删除Cookie,仅适用于IE7版本 IE7版本为我们提供了命令行删除Cookie,清除临时文件缓存,清除历史记录表单的方法,下面是详细的命令运行方式. '注:以下代码仅支持IE7. '清除Int ...

  5. APACHE如何里一个站点绑定多个域名?用ServerAlias

    APACHE2如何里一个站点绑定多个域名?用ServerAlias以前很笨,要使多个域名指向同一站点总是这样写: <VirtualHost *:80>ServerAdmin i@kuigg ...

  6. 【转】iOS可执行文件瘦身方法

    http://blog.cnbang.net/tech/2544/ 缩减iOS安装包大小是很多中大型APP都要做的事,一般首先会对资源文件下手,压缩图片/音频,去除不必要的资源.这些资源优化做完后,我 ...

  7. Linux递归删除文件命令

    Linux递归删除文件命令 find . -name "*.log.*" -exec ls {} \; find . -name "*.log.*" -exec ...

  8. thymeleaf中的Literals

    Literals即为文字 一.Text literals:文本文字 文本文字只是字符串指定的单引号之间.他们可以包含任何字符,但你应避免任何单引号里面\ ' <p> Now you are ...

  9. Windows Server 2003 R2 64位简体中文版下载

    32位版 CD1: SHA1值:d0dd2782e9387328ebfa45d8804b6850acabf520 ed2k://|file|cn_win_srv_2003_r2_enterprise_ ...

  10. PsLookupProcessByProcessId分析

    本文是在讨论枚举进程的时候产生的,枚举进程有很多方法,Ring3就是ZwQuerySystemInformation(),传入SysProcessesAndThreadsInformation这个宏, ...