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. HDU5807 Keep In Touch DP

    // HDU5807 Keep In Touch DP // 思路:直接暴力是O(n^6).所以要优化一下 // dp[i][j][k][0]:当前点i j k的方案数 // dp[i][j][k][ ...

  2. 关于登录的会话控制, 终极解决方案 - chunyu

    登录是用cookie还是session实现,一直有争议,普遍认为session更安全,可是有些功能,用cookie最方便也最高效,比如“记住我一周”.   cookie还是session,我的答案是两 ...

  3. RabbitMQ (四) 路由选择 (Routing) -摘自网络

    本篇博客我们准备给日志系统添加新的特性,让日志接收者能够订阅部分消息.例如,我们可以仅仅将致命的错误写入日志文件,然而仍然在控制面板上打印出所有的其他类型的日志消息. 1.绑定(Bindings) 在 ...

  4. homework-10

    不多不说这是一次神奇的作业,作业一拖再拖,到最后发现.... 首先,在一开始的最大字数和问题实现图形界面主要是由我的小伙伴邹同学完成的,所以当我第一次看到说要显示详细运行过程的时候感到很迷茫. 第一感 ...

  5. Web Service学习之六:CXF解决无法处理的数据类型

    CXF不能够处理像Map复杂的数据类型,需要单独转换处理. 总体思路:创建一个转换器和一个对应的可以处理的数据结构类型,将不能处理的类型转换成可以处理的类型: 步骤: 一.创建一个可以处理的类型 举例 ...

  6. CodeForces 455B A Lot of Games (博弈论)

    A Lot of Games 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/J Description Andrew, Fedo ...

  7. HDU 3072 Intelligence System (强连通分量)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. 转载 C#使用Salt + Hash来为密码加密

    转载 http://www.csharpwin.com/csharpspace/13412r9615.shtml (一) 为什么要用哈希函数来加密密码 如果你需要保存密码(比如网站用户的密码),你要考 ...

  9. SGU 171 Sarov zones (贪心)

    题目   SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有 ...

  10. 百度地图 >> 自定义控件

    前言 百度地图API中预定义的UI控件,比如NavigationControl平移缩放控件,CopyrightControl版权控件,MapTypeControl地图类型控件....,这些都继承自抽象 ...