hdu 4941 map的使用
来源:互联网 发布:长款流苏耳环淘宝价 编辑:程序博客网 时间:2024/06/05 20:39
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;}
0 0
- hdu 4941 map的使用
- HDU 1113(map的使用)
- hdu 1004 map的使用
- hdu 4941map的运用
- hdu 2648(Shopping) STL map的使用
- hdu 1251 统计难题 (Map的使用)
- HDU 1004map的初步使用
- HDU 1004 map使用
- hdu 2112 HDU Today(map与dijkstra的结合使用)
- hdu 4941 map结构体的用法
- hdu 1029 Ignatius and the Princess IV //map的使用
- HDU 1082 Matrix Chain Multiplication(栈和map的使用)
- hdu 1263 水果(map的使用2)
- HDU 6015 Skip the Class 优先队列 map的使用
- HDU 1228 A + B(map的简单使用)
- 【Map】Map.Entry的使用
- HDU 2648 map的应用
- HDU 4287 map的用法
- oozie sqoop 定位到出错的行
- 解决Android与服务器传输中文出现乱码的问题。
- uploadify上传注意
- javascript学习-原生javascript的小特效(多个运动效果整理)
- 自定义UIPageCrontroll的圆点大小和间距
- hdu 4941 map的使用
- 答读者问(20):一个在读研究生有关在校学习的相关疑问
- 矩形类
- Shell脚本入门(八) - 循环控制语句: while
- 批量修改文件格式
- 二维码图片生成和解析工具类
- 圆圈加载效果
- AngularJS学习资源
- 在code::block中创建console application