Magical Forest

Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 134    Accepted Submission(s): 69

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

Hint

No two fruits at the same location.

 
Author
UESTC
 
Source
 
Recommend
We have carefully selected several similar problems for you:  4944 4943 4942 4941 4940 
 
 
思路:stl。。。
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
//#include<pair> #define N 1505
#define M 105
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; map<pair<int,int>,int>v;
map<int,int>X,Y;
int n,m,k;
int q,a,b;
int x,y,c;
int tt;
int T; int main()
{
// freopen("data.in","r",stdin);
scanf("%d",&T);
for(int cnt=;cnt<=T;cnt++)
//while(T--)
//while(scanf("%d%d",&n,&m)!=EOF)
{
//
printf("Case #%d:\n",cnt);
v.clear();X.clear();Y.clear();
scanf("%d%d%d",&n,&m,&k);
while(k--){
scanf("%d%d%d",&x,&y,&c);
v[make_pair(x,y)]=c;
// printf(" %d %d %d\n",x,y,c);
X[x]=x;
Y[y]=y;
// printf(" %d:%d %d:%d\n",x,X[x],y,Y[y]);
}
scanf("%d",&tt);
while(tt--)
{
scanf("%d%d%d",&q,&a,&b);
if(q==){
swap(X[a],X[b]);
//printf(" %d:%d %d:%d\n",a,X[a],b,X[b]);
}
else if(q==){
swap(Y[a],Y[b]);
// printf(" %d:%d %d:%d\n",a,Y[a],b,Y[b]);
}
else{
printf("%d\n",v[make_pair(X[a],Y[b])]);
} } } return ;
}

hdu 4941 2014 Multi-University Training Contest 7 1007的更多相关文章

  1. hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 Parenthese sequence Time Limit: 2000/1000 MS (Ja ...

  2. hdu 4902 Nice boat--2014 Multi-University Training Contest 4

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...

  3. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  4. HDU校赛 | 2019 Multi-University Training Contest 6

    2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...

  5. HDU校赛 | 2019 Multi-University Training Contest 5

    2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...

  6. HDU校赛 | 2019 Multi-University Training Contest 4

    2019 Multi-University Training Contest 4 http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 100 ...

  7. HDU校赛 | 2019 Multi-University Training Contest 3

    2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 100 ...

  8. HDU校赛 | 2019 Multi-University Training Contest 2

    2019 Multi-University Training Contest 2 http://acm.hdu.edu.cn/contests/contest_show.php?cid=849 100 ...

  9. HDU校赛 | 2019 Multi-University Training Contest 1

    2019 Multi-University Training Contest 1 http://acm.hdu.edu.cn/contests/contest_show.php?cid=848 100 ...

随机推荐

  1. cocos2dx 通过jni调用安卓底层方法

    cocos2dx通过封装JniHelper类来调用安卓api底层函数,该文件在cocos/platform/android/jni/JniHelper.h,使用方法如下: 打开eclipse,导入co ...

  2. 【上下界网络流 二分】bzoj2406: 矩阵

    感觉考试碰到上下界网络流也还是写不来啊 Description Input 第一行两个数n.m,表示矩阵的大小. 接下来n行,每行m列,描述矩阵A. 最后一行两个数L,R. Output 第一行,输出 ...

  3. MySQL 查询优化之 Block Nested-Loop 与 Batched Key Access Joins

    MySQL 查询优化之 Block Nested-Loop 与 Batched Key Access Joins 在MySQL中,可以使用批量密钥访问(BKA)连接算法,该算法使用对连接表的索引访问和 ...

  4. 编译-LAMP基于fastcgi

    前言 最近没更新新篇幅了,今天就来点干活,过多的也不说了下面着手干!干!干! 准备环境 centos7.5 apr-1.6.3.tar.gz  apr-util-1.6.1.tar.gz      h ...

  5. init0-6(启动级别)

    一. init是Linux系统操作中不可缺少的程序之一. 所谓的init进程,它是一个由内核启动的用户级进程. 内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后, ...

  6. 预防cdn链接失效,无缝切换本地文件

    如今的前端项目追求的不仅仅是能用能看的程度,而是愈发追求项目的性能,对用户体验的影响.而现在的开发工具在性能优化方面也替我们做很大一部分的工作,想必大家对CDN的使用都是轻车熟路了,但是大家有没有考虑 ...

  7. 如何在 CentOS 7 上安装 Python 3

    当前最新的 CentOS 7.5 默认安装的是 Python 2.7.5,并且默认的官方 yum 源中不提供 Python 3 的安装包.这里主要介绍两种在 CentOS 7 中安装 Python 3 ...

  8. Form和ModelForm组件

    Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...

  9. 使用python3调用MyQR库生成动态二维码(附源代码)

    可生成普通二维码.带图片的艺术二维码(黑白与彩色).动态二维码(黑白与彩色). GitHub:https://github.com/sylnsfar/qrcode 中文版:https://github ...

  10. leetcode-27-exercise_bit maniputation

    461. Hamming Distance 解题思路: 把两个数的每一位和1比较,如果结果不同说明这两位不同.要比较32次. int hammingDistance(int x, int y) { i ...