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 Boot (24) 使用Spring Cache集成Redis
Spring 3.1引入了基于注解(annotation)的缓存(cache)技术,它本质不是一个具体的缓存实现方案,而是一个对缓存使用的抽象,通过在既有代码中添加少量它定义的个助攻annotatio ...
- Cookie localStorage sessionStorage
三者的异同 特性 Cookie localStorage sessionStorage 数据的生命期 可设置失效时间,默认是关闭浏览器后失效 除非被清除,否则永久保存 仅在当前会话下(tab标签页)有 ...
- 基于TensorFlow的车牌号识别系统
简介 过去几周我一直在涉足深度学习领域,尤其是卷积神经网络模型.最近,谷歌围绕街景多位数字识别技术发布了一篇不错的paper.该文章描述了一个用于提取街景门牌号的单个端到端神经网络系统.然后,作者阐述 ...
- JS——百度背景图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- VHDL之Serial-Parallel Multiplier
1 Serial-parallel multiplier Figure 12.1 shows the RTL diagram of a serial-parallel multiplier. One ...
- Android中Application类总结
本文出处: 炎之铠csdn博客:http://blog.csdn.net/totond 炎之铠邮箱:yanzhikai_yjk@qq.com 本文原创,转载请注明本出处! 前言 最近的开发中经常使用到 ...
- C# null
var t0est = Convert.ToString(""+null);//结果"" var t1est = ("" + null).T ...
- 通过offset值的设置使html元素对齐
今天是我第一次写这个随笔,为了记录我发现的一个jquery的offset的值的问题. 这个offset的值会因为页面标签是否处于隐藏状态而表现出不同的值,隐藏状态时,offset的值是相对于直接父亲的 ...
- Redis 之sentinel运维监控
有三台redis服务器6379.6380.6381,配置6379为主服务器,6380与6381都为6379的从服务器.如果主服务器6379挂掉了,我们怎么办? 方式一:手动修改从服务器的配置,将638 ...
- c#符号含义
属性:(带手型图标)方法:(紫红色菱形)事件:(闪电)字段:(蓝色菱形) 还有很多,具体图标不好描述命名空间,类,接口,值类,枚举,清单或类信息项等