Magical Forest

Problem 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(Xi, Yi) and the energy can be provided Ci.

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

 

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

题意:给出一个矩阵中的数字。有调换行和列的操作。操作完后问在(x,y)处的是什么数字。

sl: 很逗得模拟。 直接保留开始的位置就好了。map以下就能搞。

 1 // by caonima
 2 // hehe
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <vector>
 7 #include <map>
 8 using namespace std;
 9 const int MAX= 1e5+;
 struct node {
     int x,y,val;
 }v[MAX];
 int cas,n,m,k;
 map<pair<int,int>,int> hash;
 map<int,int> lastx,lasty;
 int Q,A,B;
 void init() {
     for(int i=;i<=k;i++) {
 //        col[v[i].x]=v[i].x;
 //        com[v[i].y]=v[i].y;
         lastx[v[i].x]=v[i].x;
         lasty[v[i].y]=v[i].y;
     }
 
 }
 void gao1() {
     scanf("%d %d",&A,&B);
     int t=lastx[A];
     lastx[A]=lastx[B];
     lastx[B]=t;
    // swap(col[A],col[B]);
 }
 void gao2() {
     scanf("%d %d",&A,&B);
     int t=lasty[A];
     lasty[A]=lasty[B];
     lasty[B]=t;
    // swap(com[A],com[B]);
 }
 void gao3() {
     scanf("%d %d",&A,&B);
     int x=lastx[A],y=lasty[B];
     int ans=hash[make_pair(x,y)];
     printf("%d\n",ans);
 }
 int main() {
     int cnt=;
     scanf("%d",&cas);
     while(cas--) {
         scanf("%d %d %d",&n,&m,&k);
         hash.clear();
 
         for(int i=;i<=k;i++) {
             scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].val);
             hash[make_pair(v[i].x,v[i].y)]=v[i].val;
         }
         init();
         int t;
         scanf("%d",&t);
         printf("Case #%d:\n",++cnt);
         while(t--) {
             scanf("%d",&Q);
             if(Q==) {
                 gao1();
             }
             else if(Q==) {
                 gao2();
             }
             else {
                 gao3();
             }
         }
     }
     return ;

75 }

HDU 4941的更多相关文章

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

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

  2. hdu 4941 Magical Forest

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...

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

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

  4. hdu 4941 map的使用

    http://acm.hdu.edu.cn/showproblem.php?pid=4941 给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是: 1 ...

  5. hdu 4941 2014 Multi-University Training Contest 7 1007

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

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

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

  7. STL : map函数的运用 --- hdu 4941 : Magical Forest

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

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

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

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

随机推荐

  1. Person p = new Person("zhangsan",20);该句话都做了什么事情?

    1,因为new用到了Person.class.所以会先找到Person.class文件并加载到内存中.2,执行该类中的static代码块,如果有的话,给Person.class类进行初始化.3,在堆内 ...

  2. 四大开源协议比较:BSD、Apache、GPL、LGPL【转载】

    四大开源协议原文链接 本文参考文献:http://www.fsf.org/licensing/licenses/ 现今存在的开源协议很多,而经过Open Source Initiative组织通过批准 ...

  3. Linux命令(009) -- tar

    tar命令可以为Linux的文件和目录创建档案(备份).利用该命令,可以为某一特定文件创建备份,也可以在档案中改变文件或向档案中加入新的文件:可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件 ...

  4. Stamus Networks的产品SELKS(Suricata IDPS、Elasticsearch 、Logstash 、Kibana 和 Scirius )的下载和安装(带桌面版和不带桌面版)(图文详解)

    不多说,直接上干货!  SELKS是什么? SELKS 是Stamus Networks的产品,它是基于Debian的自启动运行发行,面向网络安全管理.它基于自己的图形规则管理器提供一套完整的.易于使 ...

  5. selenium通过autoit实现上传和下载

    autoit安装目录如下: AutoIt Windows Info   用于帮助我们识Windows控件信息. Compile Script to.exe 用于将AutoIt生成 exe 执行文件. ...

  6. 51全志R58平台Android4.4下Camera的HAL层修改

    51全志R58平台Android4.4下Camera的HAL层修改 2018/11/7 15:20 版本:V1.0 开发板:SC5806 1.系统编译: (略) 2.全志R58平台Android4.4 ...

  7. javax.xml.bind.UnmarshalException: 意外的元素 (uri:"", local:"xml")。所需元素为(none)

    将xml转换为object时候报错:javax.xml.bind.UnmarshalException: 意外的元素 (uri:"", local:"xml") ...

  8. java 生成特定范围内的随机数

    /** * 生成[1, max]之间的随机数 */ public static Integer getRandomNumber(Integer max) { Random rd = new Rando ...

  9. 掌握Spark机器学习库-07-线性回归算法概述

    1)简介 自变量,因变量,线性关系,相关系数,一元线性关系,多元线性关系(平面,超平面) 2)使用线性回归算法的前提 3)应用例子 沸点与气压 浮力与表面积

  10. 使用VC++编写QQ群发器,MFC做UI

    由于公司业务需要,QQ群发器经常被用来发送QQ广告,购买的QQ群发器不好用不说,而且是按机器收费的,有些功能还不能修改. 所以公司派我来开发一款自己的QQ群发器,我给群发器取名叫做飞速群发器,用来给软 ...