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. Codeforces Round #364

    http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...

  2. Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

    Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing   ...

  3. [cocos2d-x]File文件的IO读写处理

    转载:http://blog.csdn.net/chiuan/article/details/8618411 为了保存自定义数据文件,需要保存文件和读取文件,也就是File的IO处理: 针对cocos ...

  4. Linux下的scp拷贝命令详解

    相同Linux系统中对文件复制拷贝可以用CP命令: cp [options] source dest cp [options] source... directory 说明:将一个档案拷贝至另一档案, ...

  5. 关闭Linux里边的selinux

    首先我们可以用命令来查看selinux的状态 getenforce   这个命令可以查看到selinux的状态,当前可以看到是关闭状态的.   还有一个命令也可以查看出selinux的状态. sest ...

  6. POJ 3660 Cow Contest (Floyd)

    题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...

  7. HDU 2045 不容易系列之(3)—— LELE的RPG难题 (递推)

    题意:略. 析:首先是假设前n-2个已经放好了,那么放第 n 个时,先考虑一下第 n-1 放的是什么,那么有两种情况. 如果n-1放的是和第1个一样的,那么第 n 个就可以在n-2的基础上放2个,也就 ...

  8. java.lang.OutOfMemory总结分析

    OOM浅析 相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的认识 ...

  9. PictureEdit中拖放图片

    public partial class Form2 : Form { string fileName = string.Empty; public Form2() { InitializeCompo ...

  10. 用ConfigurationManager读取和修改配置文件

    为了方便有时我们会把一些简单的配置的信息放入web.config文件里. 放到appSettings添加key   value等信息. ConfigurationManager.AppSettings ...