HDU 4941 Magical Forest _(:зゝ∠)_ 模拟题

模拟大法保平安_(:зゝ∠)_

#include <cstdio>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
const int N = 1;
struct node{
    int x, y, val;
    node(int a=0,int b=0,int c=0):x(a),y(b),val(c){}
    bool operator<(const node&a)const{
        if(a.x!=x)return a.x<x;
        return a.y<y;
    }
};
set<node>s;
set<node>::iterator it;
map<int, int> mp;
map<int, int> mp2;
int main() {
    int T; scanf("%d", &T);
    for(int cas = 1; cas <= T; cas ++){
        mp.clear();mp2.clear();s.clear();
        int n, m, k, x, y, p;
        scanf("%d%d%d", &n, &m, &k);
        while(k-- > 0) {
            scanf("%d%d%d", &x, &y, &p);
            s.insert(node(x, y ,p));
            if(mp.find(x)==mp.end())mp[x] = x;
            if(mp2.find(y)==mp2.end())mp2[y] = y;
        }
        scanf("%d", &k);
        printf("Case #%d:\n", cas);
        while(k-- > 0) {
            scanf("%d%d%d", &p, &x, &y);
            if(p == 1) {
                if(mp.find(x)==mp.end())mp[x] = x;
                if(mp.find(y)==mp.end())mp[y] = y;
                int tmp = mp[x];
                mp[x] = mp[y];
                mp[y] = tmp;
            } else if(p == 2) {
                if(mp2.find(x)==mp2.end())mp2[x] = x;
                if(mp2.find(y)==mp2.end())mp2[y] = y;
                int tmp = mp2[x];
                mp2[x] = mp2[y];
                mp2[y] = tmp;
            } else {

                it = s.find(node(mp[x],mp2[y],0));
                if(it == s.end()) puts("0");
                else printf("%d\n", it->val);
            }
        }
    }
    return 0;
}

HDU 4941 Magical Forest _(:зゝ∠)_ 模拟题

时间: 2024-08-14 19:38:37

HDU 4941 Magical Forest _(:зゝ∠)_ 模拟题的相关文章

hdu 4941 Magical Forest(Map)

http://acm.hdu.edu.cn/showproblem.php?pid=4941 因为地图的行和列很大,操作次数也很多,直接循环模拟肯定不行.但可以用map映射一下,当交换行和列的时候,直接交换它们的映射值,直接O(1)进行交换. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <list> #include <stack

hdu 4941 Magical Forest (map容器)

Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 135    Accepted Submission(s): 69 Problem Description There is a forest can be seen as N * M grid. In this forest, there is so

hdu 4941 Magical Forest(STL map &amp; 结构体运用)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 220    Accepted Submission(s): 105 Problem Description There is a forest c

HDU 4941 Magical Forest STL

这明明就是给纯C选手的大杀器啊. 题意:给你k坐标,表示 X,Y 有值C,有 3种操作 1) 交换A,B两行 2) 交换A,B两列 3) 询问(A,B)的值 解题思路:map离散化 解题代码: // File Name: 1007.cpp // Author: darkdream // Created Time: 2014年08月12日 星期二 21时05分18秒 #include<vector> #include<list> #include<map> #includ

hdu 4941 Magical Forest

被虐了一下午..离散化,开一个rr[mnx], cc[mnx],初始化为rr[i] = i, cc[i],然后换的时候就换这两个数组就好了.. 然后就是不断的lower_bound 1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdio> 5 #include<string> 6 #include<queue> 7 #includ

HDU 4941 Magical Forest 【离散化】【map】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点,每个点有一个数值,点的xy坐标是0~10^9,点存在于矩阵中.然后给出10^5个操作,1代表交换行,2代表交换列,3代表查询坐标为xy点的数值. 数据量很大........ 所以一直没有思路 后来赛后看了题解是先用离散化然后存在线性map里面. #include <iostream> #include <cstdio> #include <map

HDU 4941 Magical Forest(离散化)

HDU 4941 Magical Forest 题目链接 题意:给定一些点,点有值,现在3种操作交换行,列,询问某个点值 思路:这是签到题,坐标系很大,所以把坐标离散化储存,每次交换的时候只要把相应的行列坐标交换即可,查询就在交换过的上面查就可以了 代码: #include <cstdio> #include <cstring> #include <algorithm> #include <map> using namespace std; #define

hdu 4941 Magical Forest(hash映射)

题目链接:hdu 4941 Magical Forest 题目大意:给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是: 1 a b :交换a和b两行 2 a b : 交换a和b两列 3 a b :查询a b这个位置上棋子的值,没有棋子的话输出0 解题思路:一开始X[i]=i,X[j]=j,如果需要交换i和j,那么就令X[i]=j,X[j]=i即可,因为N和M很大,所以用map映射. #include <cstdio> #include <

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 a b,询问(a,b)位置的果树的能量值. 分析: hdu 4941 Magical Forest ( 双重map )