HDU
来源:互联网 发布:高性能网络编程1 编辑:程序博客网 时间:2024/06/10 19:24
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941
题目大意:一张地图上有若干个水果,有3个询问,一个是交换两列,一个是交换两行,一个是询问水果能量,交换保证交换的是同时没水果的或同时有水果的。
解题思路:其实交换两行或两列不用真的交换他们,只要记录交换后他们的行和列的位置就可以了。用map存水果的能量,减小空间开销
AC代码:
#include<cstdio>#include<map>using namespace std;struct Node{ int x, y; Node(int x = 0, int y = 0) :x(x), y(y) {} bool operator<(const Node& a)const { if (x != a.x) return x < a.x; return y < a.y; }};map<Node, int> mm;map<int, int> col;map<int, int> row;int main(){ int cas = 0; int w;scanf("%d", &w); while (w--) { printf("Case #%d:\n", ++cas); col.clear(); row.clear(); mm.clear(); int n, m, k, col_num = 0, row_num = 0; scanf("%d%d%d", &n, &m, &k); while (k--) { int x, y, c; scanf("%d%d%d", &x, &y, &c); if (!row[x]) row[x] = row_num++; x = row[x]; if (!col[y]) col[y] = col_num++; y = col[y]; mm[Node(x,y)] = c; } int t;scanf("%d", &t); while (t--) { int q, a, b; scanf("%d%d%d", &q, &a, &b); if (q == 1) swap(row[a], row[b]); else if (q == 2) swap(col[a], col[b]); else printf("%d\n", mm[Node(row[a], col[b])]); } } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- hdu6127Hard challenge(思维+扫描)
- 使用 ML Pipeline 构建机器学习工作流
- centos升级gcc到4.8.1(支持c++11)步骤
- Linux的squid代理服务配置
- caffe编译时出现undefined reference错误的原因与解决办法
- HDU
- 集合(五)Map及其子类
- load-on-startup的作用
- 虚幻4中的动画技术【1】资源准备和概念初探
- Java集合---HashMap源码剖析
- Ecilpse上运行SVN报找不到SVNConnector最有效解决方法
- 经典java题
- rbtree原理及应用--前世今生及性质
- webupload文件上传过程中遇到的一个问题