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 ...
随机推荐
- Ambari?自动部署Hadoop集群
自动部署?Ambari Ambari 跟 Hadoop 等开源软件一样,也是 Apache Software Foundation 中的一个项目,并且是顶级项目.就 Ambari 的作用来说,就是创建 ...
- [转]Wote用python语言写的imgHash.py
#!/usr/bin/python import glob import os import sys from PIL import Image EXTS = 'jpg', 'jpeg', 'JPG' ...
- servlet的多线程并发问题
package gz.itcast.e_thread; import java.io.IOException; import javax.servlet.ServletException; impor ...
- STL_string用法总结
参考自:http://blog.csdn.net/y990041769/article/details/8763366 1:string对象的定义和初始化以及读写 string s1; 默认 ...
- js获取图片信息(二)-----js获取img的height、width宽高值为0
首先,创建一个图片对象: var oImg= new Image(); oImg.src = "apple.jpg"; 然后我们打印一下图片的信息: console.log(oIm ...
- C/C++ 之数组排序
#include <stdio.h> #include <stdlib.h> void array_sort(int *a, int len) { int i, j, tmp; ...
- 【HTTP/S】透明代理、匿名代理、混淆代理、高匿代理有什么区别?
这4种代理,主要是在代理服务器端的配置不同,导致其向目标地址发送请求时,REMOTE_ADDR, HTTP_VIA,HTTP_X_FORWARDED_FOR三个变量不同. 1.透明代理(Transpa ...
- 学习csv
1.csv文件读取,csv文件是常用的数据存储格式之一,我们使用Python模块来处理csv文件,这是一个天气信息表 import csv from matplotlib import pyplot ...
- 零基础学习Linux培训,应该选择哪个培训班?
云计算早已不是什么稀奇的概念,它的火爆让Linux运维工程师这个职业越来越重要.在当今各类云平台提供的系统中,Linux系统几乎毫无争议的独占鳌头,市场份额进一步扩张. 这也让Linux运维工程师职位 ...
- 面试:A
分析 System.Collections.Generic.List<T> 的 Remove<T> 方法和 Clear 方法的实现细节(不允许使用“移除”“清除”这种概念模糊的 ...