题目连接

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映射。。

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. using std::cin;
  10. using std::cout;
  11. using std::endl;
  12. using std::swap;
  13. using std::sort;
  14. using std::set;
  15. using std::map;
  16. using std::pair;
  17. using std::vector;
  18. using std::multiset;
  19. #define pb(e) push_back(e)
  20. #define sz(c) (int)(c).size()
  21. #define mp(a, b) make_pair(a, b)
  22. #define all(c) (c).begin(), (c).end()
  23. #define iter(c) decltype((c).begin())
  24. #define cls(arr,val) memset(arr,val,sizeof(arr))
  25. #define cpresent(c, e) (find(all(c), (e)) != (c).end())
  26. #define rep(i, n) for (int i = 0; i < (int)(n); i++)
  27. #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
  28. const int Max_N = ;
  29. typedef unsigned long long ull;
  30. struct Node {
  31. int x, y, val;
  32. Node(int i = , int j = , int k = ) :x(i), y(j), val(k) {}
  33. inline bool operator<(const Node &a) const {
  34. return x == a.x ? y > a.y : x > a.x;
  35. }
  36. };
  37. set<Node> st;
  38. set<Node>::iterator ite;
  39. map<int, int> x, y;
  40. int main() {
  41. #ifdef LOCAL
  42. freopen("in.txt", "r", stdin);
  43. freopen("out.txt", "w+", stdout);
  44. #endif
  45. int t, n, m, a, b, v, q, k, p = ;
  46. scanf("%d", &t);
  47. while (t--) {
  48. st.clear(), x.clear(), y.clear();
  49. scanf("%d %d %d", &n, &m, &k);
  50. while (k--) {
  51. scanf("%d %d %d", &a, &b, &v);
  52. if (x.find(a) == x.end()) x[a] = a;
  53. if (y.find(b) == y.end()) y[b] = b;
  54. st.insert(Node(a, b, v));
  55. }
  56. printf("Case #%d:\n", p++);
  57. scanf("%d", &k);
  58. while (k--) {
  59. scanf("%d %d %d", &q, &a, &b);
  60. if ( == q) {
  61. if (x.find(a) == x.end()) x[a] = a;
  62. if (x.find(b) == x.end()) x[b] = b;
  63. swap(x[a], x[b]);
  64. } else if ( == q) {
  65. if (y.find(a) == y.end()) y[a] = a;
  66. if (y.find(b) == y.end()) y[b] = b;
  67. swap(y[a], y[b]);
  68. } else {
  69. ite = st.find(Node(x[a], y[b]));
  70. printf("%d\n", ite == st.end() ? : ite->val);
  71. }
  72. }
  73. }
  74. return ;
  75. }

hdu 4941 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. hdu 4941 Magical Forest (map容器)

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  3. HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...

  4. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

  5. HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)

    思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   . r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j ...

  6. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  7. 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 ...

  8. HDU 4941 Magical Forest (Hash)

    这个题比赛的时候是乱搞的,比赛结束之后学长说是映射+hash才恍然大悟.因此决定好好学一下hash. 题意: M*N的格子,里面有一些格子里面有一个值. 有三种操作: 1.交换两行的值. 2.交换两列 ...

  9. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

随机推荐

  1. Adobe AIR and Flex - 实现堆栈容器

    1.需求描述: 在对云平台的监控中,我们经常需要在一张图上可视化的描述集群下的物理机所虚拟的虚拟机使用情况,以及超卖情况.那么传统的chart图就不满足我们的需求了,那么要实现这样一个定制化的char ...

  2. JAVA编写WEB服务器

    一.超文本传输协议  1.1 HTTP请求  1.2 HTTP应答  二.Socket类  三.ServerSocket类  四.Web服务器实例  4.1 HttpServer类  4.2 Requ ...

  3. No.003 Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters Total Accepted: 167158 Total Submissions: 735821 Diff ...

  4. Java程序员面试宝典——重要习题整理

    1.下面程序的输出结果是() public class Test { public static void main(String[] args) { int j = 0 ; for(int i = ...

  5. [Nginx 2] form表单提交,图片上传

    导读:昨晚恶补了一些Nginx服务器的东西,从整体上对Nginx有一个初步的了解.上午去找师哥问了问目前项目中的使用情况,然后就开始上传图片了.这里就简单总结整理一下今天的成果,以后接着提升.简单粗暴 ...

  6. oracle线程数更改

    查看Oracle最大进程数: SQL> select count(*) from v$session #连接数,查看更多oracle数据库的疑问, 可点击cuug官网.http://www.cu ...

  7. poj1035 Spell checker

    这题目比较简单,把思路搞清楚就可以啦. #include <stdio.h> #include <string.h> +][]; int init(){ ; while(~sc ...

  8. JS回车事件

    <script type="text/javascript"> //当回车按下时,/=47,*=42,+=43 function keypress(form0){ if ...

  9. 网络基础知识、ASP.NET 核心知识(1)*

    为什么要写网络? 我原本的计划是这样的,连续两天梳理ASP.NET开发的核心知识.说到这呢,有人问了.“不是说好了做ASP.NET笔记吗?为啥要写网络基础知识?是不是傻?” 原因是这样的.作为网站开发 ...

  10. 在WP8项目中使用ARMASM

    由于之前项目中某些密集运算优化的需要,涉及到ARMASM相关的内容, 所以有幸可以在此分享一下自己的经验. 先铺垫一些知识: 1. ARM处理器有两种指令ARM.THUMB, 在WP8下默认是THUM ...