hdu 4941 stl的map<node,int>用法

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef struct node{
    int x,y;
    bool operator<(const node &b)const
    {
        if(x==b.x)
            return y<b.y;
        else
            return x<b.x;
    }
}node;
int main() {
   map<node,int>ma;
   map<int,int>f,ff;
   node e;
   int n,m,i,j,k,t,id,idd,ss,s,num=0;
   scanf("%d",&t);
   while(t--) {
    scanf("%d%d%d",&n,&m,&k);
    id=0;idd=0;
    while(k--) {
        scanf("%d%d%d",&i,&j,&s);
        if(f[i]==0)
            f[i]=++id;
            if(ff[j]==0)
            ff[j]=++idd;
            e.x=f[i];
            e.y=ff[j];
            ma[e]=s;
    }
    scanf("%d",&j);
  printf("Case #%d:\n",++num);
    while(j--) {
        scanf("%d",&i);
        if(i==1) {
            scanf("%d%d",&id,&idd);
            ss=f[id];
            f[id]=f[idd];
            f[idd]=ss;
        }
        if(i==2) {
            scanf("%d%d",&id,&idd);
            ss=ff[id];
            ff[id]=ff[idd];
            ff[idd]=ss;
        }
        if(i==3) {
            scanf("%d%d",&id,&idd);
            e.x=f[id];
            e.y=ff[idd];
          //  printf("%d %d\n",f[id],ff[idd]);
            printf("%d\n",ma[e]);
        }
    }
   }
return 0;
}

hdu 4941 stl的map<node,int>用法

时间: 2024-10-24 07:24:46

hdu 4941 stl的map<node,int>用法的相关文章

hdu 4941 STL HASH 模拟

http://acm.hdu.edu.cn/showproblem.php?pid=4941 比赛的时候现学的map的find...以前都是用下标做的,但是map用下标查询的话,如果查询的元素不存在,会插入一个新的元素. 贴一个map查找元素找到和找不到的模板 map<pair<int,int>,int>::iterator it=poshash.find(tmppos);//pair<int,int>poshash; int pp; if(it == poshash.

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

[转] C++ STL中map.erase(it++)用法原理解析

总结一下map::erase的正确用法. 首先看一下在循环中使用vector::erase时我习惯的用法: for(vector<int>::iterator it = vecInt.begin(); it != vecInt.end();) { if(*it == 0) { it = vecInt.erase(it); } else { it++; } } 程序从一个vector中删除值为0的元素,利用了vector::erase函数根据iterator删除某个元素时会返回下一个元素的ite

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 (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应用)2014多校训练第7场

Magical Forest                                                                       Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description There is a forest can be seen as N * M grid. In this fore

STL : map函数的运用 --- hdu 4941 : Magical Forest

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

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 【离散化】【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