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. nodejs学习笔记之mongoDB

    这两天在学习nodejs,但是发现那本书nodejs入门指南上所用的好多方法都报错. 这里主要说下数据库部分 关于注册部分:书上创建数据库那里可能要小心点,用户名不存在的时候,下面调用save的对象要 ...

  2. bzoj 1090 [SCOI2003]字符串折叠(区间DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1090 [题意] 给定一个字符串,问将字符串折叠后的最小长度. [思路] 设f[i][j ...

  3. 区间DP+next求循环节 uva 6876

    // 区间DP+next求循环节 uva 6876 // 题意:化简字符串 并表示出来 // 思路:dp[i][j]表示 i到j的最小长度 // 分成两部分 再求一个循环节 #include < ...

  4. Machine Learning & Data Mining 资料整合

    机器学习常见算法分类汇总 | 码农网 数据挖掘十大经典算法 | CSDN博客 (内含十个算法具体介绍) 支持向量机通俗导论(理解 SVM 的三层境界)| CSDN博客 (强烈推荐关注博主) 教你如何迅 ...

  5. Zookeeper实现分布式选举算法

    分布式系统中经常采用Master/Slave架构.(截止到目前为止我还没有碰到过其他架构...)这种架构中如果Master发生故障就会导致整个集群停止服务,为了提高系统的高可用性通常采用选举算法来选出 ...

  6. 转】Maven学习总结(七)——eclipse中使用Maven创建Web项目

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4054814.html 感谢! 一.创建Web项目 1.1 选择建立Maven Project 选择File -& ...

  7. codeforces 630R Game

    R. Game time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input outp ...

  8. POJ 3922A Simple Stone Game

    题目链接 A Sample Stone Game 题目大意:给定n,k,表示最初时有n个石头,两个人玩取石子游戏,第一个人第一次可以取1~n-1个石头,后面每个人最多可以拿走前面一个人拿走的个数的K倍 ...

  9. SOURCES的文件格式

    SOURCES的文件格式: TARGETNAME=drivername , -本参数用于指定生成的设备驱动程序名称(不需后缀名),所产生的文件 -为drivername.sys. TARGETPATH ...

  10. 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    如果你是maven项目,tomcat在发布项目的时候没有同时发布maven依赖所添加的jar包,你需要设置一下eclipse:项目 —> 属性 -> Deployment Assembly ...