hdu 4941
来源:互联网 发布:程序员客栈 专职 编辑:程序博客网 时间:2024/06/04 00:34
水题竟然没有很快A出来= =
首先对所有点的行,列离散化。
然后维护一个row[i]表示第i行现在所表示的行,同理列也是。那么第i行和第j行交换只要row[i]和row[j]交换一下就可以了。
#include <cstdio>#include <cstring>#include <vector>#include <set>#include <map>#include <algorithm>using namespace std;const int maxn = 100007;map<pair<int, int>, int> maps;struct Point { int x, y, c;};struct Point point[maxn];int row_num[maxn], col_num[maxn], num_row, num_col, row_turn[maxn], col_turn[maxn];int n, m, k, q;int main() {// freopen("in.txt", "r", stdin); int test_case; scanf("%d", &test_case); int ncase = 1; while (test_case--) { scanf("%d%d%d", &n, &m, &k); printf("Case #%d:\n", ncase); ncase++; num_row = num_col = 0; maps.clear(); for (int i = 1; i <= k; i++) { scanf("%d%d%d", &point[i].x, &point[i].y, &point[i].c); row_num[num_row++] = point[i].x; col_num[num_col++] = point[i].y; } sort(row_num, row_num + num_row); sort(col_num, col_num + num_col); int row_len = unique(row_num, row_num + num_row) - row_num; int col_len = unique(col_num, col_num + num_col) - col_num; for (int i = 1; i <= row_len; i++) { row_turn[i] = i; } for (int i = 1; i <= col_len; i++) { col_turn[i] = i; } for (int i = 1; i <= k; i++) { int cnt_row, cnt_col; cnt_row = lower_bound(row_num, row_num + row_len, point[i].x) - row_num + 1; cnt_col = lower_bound(col_num, col_num + col_len, point[i].y) - col_num + 1; maps[make_pair(cnt_row, cnt_col)] = point[i].c; } scanf("%d", &q); for (int i = 1; i <= q; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); if (a == 3) { int pre = b; b = lower_bound(row_num, row_num + row_len, b) - row_num; if (row_num[b] != pre) { printf("0\n"); continue; } b++; b = row_turn[b]; c = lower_bound(col_num, col_num + col_len, c) - col_num + 1; c = col_turn[c]; if (maps.count(make_pair(b, c))) { printf("%d\n", maps[make_pair(b, c)]); } else { printf("0\n"); } } else if (a == 1) { int pre = b; b = lower_bound(row_num, row_num + row_len, b) - row_num; if (row_num[b] != pre) { continue; } b++; c = lower_bound(row_num, row_num + row_len, c) - row_num + 1; swap(row_turn[c], row_turn[b]); } else if (a == 2) { int pre = b; b = lower_bound(col_num, col_num + col_len, b) - col_num; if (col_num[b] != pre) { continue; } b++; c = lower_bound(col_num, col_num + col_len, c) - col_num + 1; swap(col_turn[b], col_turn[c]); } } } return 0;}
0 0
- hdu 4941
- hdu 4941
- hdu 4941
- HDU-4941-Magical Forest
- HDU 4941 Magical Forest
- hdu 4941 Magical Forest
- hdu 4941 Magical Forest
- HDU - 4941 Magical Forest
- hdu 4941 Magical Forest
- HDU 4941 Magical Forest
- hdu 4941 Magical Forest
- 2014多校联合七(HDU 4937 HDU 4938 HDU 4939 HDU 4941)
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- 说说今天遇到的UIKit力学问题
- hdu1159
- VS2008自动添加ActiveX插件的MFC类
- 教你快速开发自己的微信账号
- windows sound develop
- hdu 4941
- unp笔记一 网络编程基础
- hdu 4941 Magical Forest(hash映射)
- 71道经典Android面试题和答案--重要知识点都涉及到了
- OpenCV2.4版本的camshiftdemo.cpp的详细注释
- dlmalloc 简析
- poj2777 线段树+位运算
- HDOJ 题目1102Constructing Roads(简单最小生成树,kruskal)
- 最好的微信公众平台接口