hdu 4941 map的使用
http://acm.hdu.edu.cn/showproblem.php?pid=4941
给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是:
1 a b :交换a和b两行
2 a b : 交换a和b两列
3 a b :查询a b这个位置上棋子的值,没有棋子的话输出0
不能直接模拟,对应行列交换,只需交换map映射值,查询时输出map[x],map[y]上值即可
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
struct node {
int x;
int y;
int c;
}; node a[110000]; int main() {
int _;
RD(_);
for (int i = 1; i <= _; i++) {
printf("Case #%d:\n", i);
int n, m, k;
RD2(n,m);RD(k); map<int, int> row;
map<int, int> col;
map<pair<int, int>, int> graph;
for (int i = 0; i < k; i++) {
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].c);
row.insert(make_pair(a[i].x, a[i].x));
col.insert(make_pair(a[i].y, a[i].y));
graph.insert(make_pair(make_pair(a[i].x, a[i].y), a[i].c));
} int T;RD(T);
while (T--) {
int q, x, y;
scanf("%d%d%d", &q, &x, &y);
if (q == 1) {
if (row.find(x) != row.end() && row.find(y) != row.end()) {
swap(row[x], row[y]);
}
}
if (q == 2) {
if (col.find(x) != col.end() && col.find(y) != col.end()) {
swap(col[x], col[y]);
}
}
if (q == 3) {
if (row.find(x) == row.end() || col.find(y) == col.end()) {
puts("0");
} else {
printf("%d\n", graph[make_pair(row[x], col[y])]);
}
}
}
}
return 0;
}
hdu 4941 map的使用的更多相关文章
- 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.点存在于矩阵中.然后 ...
- 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 --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 stl的map<node,int>用法
#include<iostream> #include<cstdio> #include<cstring> #include<map> using na ...
- 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
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...
- hdu 1075 (map)
http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...
随机推荐
- 体验godaddy域名转入,添加A记录,及使用dnspod的NS
有两个域名一直放在朋友那,这个朋友是个神人,经常换电话号码,联系非常不方便. 近日将域名转入到godaddy下面了,第一次做域名转移,很是好奇. 之前域名在21.cn注册的,朋友帮我申请域名转出后,2 ...
- PAT 1027 打印沙漏(20)(思路)
1027 打印沙漏(20)(20 分) 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓& ...
- poj 2777(线段树+lazy思想) 小小粉刷匠
http://poj.org/problem?id=2777 题目大意 涂颜色,输入长度,颜色总数,涂颜色次数,初始颜色都为1,然后当输入为C的时候将x到y涂为颜色z,输入为Q的时候输出x到y的颜色总 ...
- Scrum 敏捷开发
使用敏捷开发一个月的事件,基本的开发模式跟我遇到的这个文章介绍的基本类似,暂时简单Copy到了这里...... http://www.scrumcn.com/agile/scrum-knowledge ...
- 乘积最大(NOIP2000&NOIP水题测试(2017082301))
题目链接:乘积最大 这道题显然是道区间dp. 难度不是很大. 思路也很清晰. 我们设计一个三维状态. ans[l][r][k] 这里表示在闭区间[l,r]上操作k次的最大值. 操作就是加乘号. 转移也 ...
- java.lang.SuppressWarnings的注解简介
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...
- web-Amazon
一 准备实验数据 1.1.下载数据 wget http://snap.stanford.edu/data/amazon/all.txt.gz 1.2.数据分析 1.2.1.数据格式 product/p ...
- Codeforces 1107 简要题解
文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 A题 传送门 题意简述:问你能不能把一个数字串切成若干块,使得切出来的kkk个数k≤2k\le2k≤2满足a1<a2<...&l ...
- 2019.01.22 hdu5195 DZY Loves Topological Sorting(贪心+线段树)
传送门 题意简述:给出一张DAGDAGDAG,要求删去不超过kkk条边问最后拓扑序的最大字典序是多少. 思路:贪心帮当前不超过删边上限且权值最大的点删边,用线段树维护一下每个点的入度来支持查询即可. ...
- 2018.11.03 NOIP模拟 图(bfs/最短路)
传送门 显然如果AAA到BBB或者CCC到DDD走的不是最短路一定是有一段路径重合了,于是可以O(n2)bfsO(n^2)bfsO(n2)bfs出两点之间的最短距离然后枚举两个点作为重合的端点来更新答 ...