hdu 4941 Magical Forest (map容器)
Magical Forest
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 135 Accepted Submission(s): 69
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.
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
Case #1:
1
2
1HintNo two fruits at the same location.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<time.h>
#include<string.h>
using namespace std;
const double pi=acos(-1.0);
#define LL __int64
#define N 100005
const int M=26;
struct node
{
int x,y;
bool operator<(const node&a)const
{ //结构体内重载运算符
if(x!=a.x)
return x<a.x;
return y<a.y;
}
}tmp;
/*
bool operator<(const node&a,const node&b)
{
if(a.x!=b.x) //结构体外重载运算符
return a.x<b.x;
return a.y<b.y;
}*/
map<int,int>u,v; //把题目所给坐标映射为范围较小的坐标 [0,...]
int cntx,cnty; //相应坐标值
map<node,int>p; //把新的坐标和能量C建立映射关系
int main()
{
int W,n,m,k,T;
int i,c,x,y,cas=1;
scanf("%d",&W);
while(W--){
scanf("%d%d%d",&n,&m,&k);
cntx=cnty=0;
for(i=0;i<k;++i){
scanf("%d%d%d",&x,&y,&c);
if(u[x]==0)
u[x]=cntx++;
if(v[y]==0)
v[y]=cnty++;
tmp.x=u[x];
tmp.y=v[y];
p[tmp]=c;
}
int q,a,b,t;
scanf("%d",&T);
printf("Case #%d:\n",cas++);
while(T--){
scanf("%d%d%d",&q,&a,&b);
if(q==1){
t=u[a];
u[a]=u[b];
u[b]=t;
}
else if(q==2){
t=v[a];
v[a]=v[b];
v[b]=t;
}
else{
tmp.x=u[a];
tmp.y=v[b];
cout<<p[tmp]<<endl;
}
}
}
return 0;
}
hdu 4941 Magical Forest (map容器)的更多相关文章
- hdu 4941 Magical Forest
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...
- STL : map函数的运用 --- hdu 4941 : Magical Forest
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...
- HDU 4941 Magical Forest 【离散化】【map】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...
- HDU 4941 Magical Forest --STL Map应用
题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...
- hdu 4941 Magical Forest ( 双重map )
题目链接 题意: 有一个n*m的田地,里边有k棵树,每棵树的位置为(xi,yi),含有能量值ci.之后又q个询问,分三种; 1)1 a b,将a行和b行交换 2)2 a b,将a列和b列交换 3)3 ...
- HDU 4941 Magical Forest (Hash)
这个题比赛的时候是乱搞的,比赛结束之后学长说是映射+hash才恍然大悟.因此决定好好学一下hash. 题意: M*N的格子,里面有一些格子里面有一个值. 有三种操作: 1.交换两行的值. 2.交换两列 ...
- HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)
思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行 . r[i] 表示第 i 行存的是 原先的哪行 c[j] 表示 第 j ...
- hdu 4941 stl的map<node,int>用法
#include<iostream> #include<cstdio> #include<cstring> #include<map> using na ...
随机推荐
- spring-framework-4.1.x源码阅读环境搭建(导入Eclipse)
注意:搭建spring-framework-4.1.x源码 eclipse工作空间需要安装jdk8. spring-framework-4.1.x项目采用目前主流的项目管理工具gradle进行构建,至 ...
- 把多种验证规则用到一个model上
基于标记特性的Model验证,真的太棒了,与jquery validate结合后激情四射,有木有,一句话完成前后端验证.简直让人秒爱... 但是爱是爱了,生活中总会有些小摩擦,这不问题来了:看图中那个 ...
- 图解TCP/IP笔记(1)——TCP/IP协议群
转载请注明:https://www.cnblogs.com/igoslly/p/9167916.html TCP/IP制定 制定:IETF 记录:RFC - Request for comment ...
- Android各种函数单位
该博客随时更新.因为每次写函数都会考虑这个单位是什么,所以嫌比较麻烦,在这里总结一下,方便以后使用. paint.setStrokeWidth() 单位是 px . paint.getStrokeWi ...
- js 翻页
翻页功能是js很基础的一个算法,且用得很多,所以必须掌握此项技能. 我们要想清楚在实现翻页的过程中需要哪几个步骤: 1.我们首先需要的变量有哪些,必须的有一个存放当前页码的变量nowPage.一个存放 ...
- CAD调用移动命令
主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数,详细说明如下: 参数 说明 IDispatch* pParam 命令参数,IMx ...
- 如何使用 Python 创建一名可操控的角色玩家
在 这个系列的第一篇文章 中,我解释了如何使用 Python 创建一个简单的基于文本的骰子游戏.在第二部分中,我向你们展示了如何从头开始构建游戏,即从 创建游戏的环境 开始.但是每个游戏都需要一名玩家 ...
- altera quartus 百度云分享 quartus prime 17.1 16.1 13.0
quartus prime 17.1 标准版 链接:https://pan.baidu.com/s/10QWejKdDobVxDSqnVPJ0xQ 提取码:hhvj 复制这段内容后打开百度网盘手机Ap ...
- js 包管理工具
环境 Windows10 + node 12.x + Webstorm 2019.1.3 工具 npm cnpm yarn npm/cnpm Webstorm 中第一次安装包一定几率卡死,很烦 不使用 ...
- 国密SSL证书免费试用申请指南
沃通提供国密SSL证书免费申请试用服务,一次申请可同时签发SM2/RSA双算法证书,试用周期1个月,用于测试国密SM2 SSL证书的运行效果和SM2/RSA双证书部署效果. 试用产品:SM2/RSA双 ...