hdu 4941 Magical Forest
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4941
Magical Forest
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$(X_i, Y_i)$ and the energy can be provided $C_i$.
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 \leq W \leq 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 \leq N, M \leq 2*10^9,\ 0 \leq K \leq 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 \leq X \leq N-1,\ 0 \leq Y \leq M-1,\ 1 \leq C \leq 1000)$
The next line has one integer $T.$ $(0 \leq T \leq 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.
Sample 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
Sample Output
Case #1:
1
2
1
map映射。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::swap;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::vector;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int Max_N = ;
typedef unsigned long long ull;
struct Node {
int x, y, val;
Node(int i = , int j = , int k = ) :x(i), y(j), val(k) {}
inline bool operator<(const Node &a) const {
return x == a.x ? y > a.y : x > a.x;
}
};
set<Node> st;
set<Node>::iterator ite;
map<int, int> x, y;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t, n, m, a, b, v, q, k, p = ;
scanf("%d", &t);
while (t--) {
st.clear(), x.clear(), y.clear();
scanf("%d %d %d", &n, &m, &k);
while (k--) {
scanf("%d %d %d", &a, &b, &v);
if (x.find(a) == x.end()) x[a] = a;
if (y.find(b) == y.end()) y[b] = b;
st.insert(Node(a, b, v));
}
printf("Case #%d:\n", p++);
scanf("%d", &k);
while (k--) {
scanf("%d %d %d", &q, &a, &b);
if ( == q) {
if (x.find(a) == x.end()) x[a] = a;
if (x.find(b) == x.end()) x[b] = b;
swap(x[a], x[b]);
} else if ( == q) {
if (y.find(a) == y.end()) y[a] = a;
if (y.find(b) == y.end()) y[b] = b;
swap(y[a], y[b]);
} else {
ite = st.find(Node(x[a], y[b]));
printf("%d\n", ite == st.end() ? : ite->val);
}
}
}
return ;
}
hdu 4941 Magical Forest的更多相关文章
- 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容器)
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(2014 Multi-University Training Contest 7)
思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行 . r[i] 表示第 i 行存的是 原先的哪行 c[j] 表示 第 j ...
- 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.交换两列 ...
- hdu4941 Magical Forest (stl map)
2014多校7最水的题 Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit ...
随机推荐
- 【考试】简单的sql语句
)显示正好为5个字符的员工的姓名 HR@ORA11GR2>select last_name,first_name from employees ; )显示不带有"R"的员工的 ...
- NOIP1998 拼数
http://www.luogu.org/problem/show?pid=1012 题目描述 设有n个正整数(n≤20),将它们联接成一排,组成一个最大的多位整数. 例如:n=3时,3个整数13,3 ...
- USACO Section 3.2 香甜的黄油 Sweet Butter
本题是多源最短路问题 但使用弗洛伊德算法会超时 而因为边数目比较少 所以用队列优化后的迪杰斯特拉算法可以通过 #include<iostream> #include<cstring& ...
- java基础回顾(一)—— sleep和wait的区别
sleep是Thread类的一个方法,wait是Object类的一个方法 sleep是线程被调用时,占着cpu去睡觉,其他线程不能占用cpu,os认为该线程正在工作,不会让出系统资源 wait是进入等 ...
- WP8__实现ListBox横向滑动及子项绑定图片等控件
<!--实现绑定的图片等信息 ListBox水平滚动--> <Grid> <Grid.Resources> <Style x:Key="horizo ...
- 编程规范 html部分
不管有多少人共同参与同一项目,一定要确保每一行代码都像是同一个人编写的. HTML 部分 语法 对于属性的定义,确保全部使用双引号,绝不要使用单引号. 为每个 HTML 页面的第一行添加标准模式(st ...
- hibernate 问题
如果hibernate中反转的表中没有主键的话,会生产三个文件. table.java tableADO.java tableId.java 并且在执行findByProperty时,会提示:coul ...
- .NET如何从配置文件中获取连接字符串
一.设置配置文件 <configuration> <!--在configuration下创建一个connectionStrings--> <connectionStrin ...
- Javascript中的一种深复制实现
在javascript中,所有的object变量之间的赋值都是传地址的,可能有同学会问哪些是object对象.举例子来说明可能会比较好: typeof(true) //"boolean&qu ...
- Linux文件和目录管理常用重要命令
一.目录与路径 1.相对路径与绝对路径 因为我们在Linux系统中,常常要涉及到目录的切换,所以我们必须要了解 "路径" 以及 "相对路径" 与 "绝 ...