题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941

题目大意:给你10^5个点。每一个点有一个数值。点的xy坐标是0~10^9。点存在于矩阵中。然后给出10^5个操作。1代表交换行。2代表交换列,3代表查询坐标为xy点的数值。

数据量非常大........ 所以一直没有思路

后来赛后看了题解是先用离散化然后存在线性map里面。

用hx,hy来存放离散化后的点的坐标,用linkx,linky来存放点离散化之后的点的坐标的行与列。

还是对于STL里面的基础运用掌握不牢。

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
#define maxn 100010 struct node {
     int u,v,w;
} point[maxn]; //其基本的原理是用一个线性的map存放。
//map里面的<int,int>是map一个特征。最后其所占的空间还是maxn这么多
map<int,int> p_w[maxn];
map<int,int> hx,hy; bool  cmpx(node A,node B)
{
     return A.u<B.u;
} bool cmpy(node A,node B)
{
     return A.v<B.v;
} int main ()
{
     int W;
     scanf("%d",&W);
     for(int w=1; w<=W; w++) {
          ///初始化
          for(int i=0; i<maxn; i++) p_w[i].clear();
          hx.clear();
          hy.clear();           int N,M,K;
          scanf("%d%d%d",&N,&M,&K);
          for(int i=0; i<K; i++)
               scanf("%d%d%d",&point[i].u,&point[i].v,&point[i].w);           int tx=1;
          sort(point,point+K,cmpx);
          for(int i=0; i<K; i++) if(!hx[point[i].u]) hx[point[i].u]=tx++;           int ty=1;
          sort(point,point+K,cmpy);
          for(int i=0; i<K; i++) {
               if(!hy[point[i].v]) hy[point[i].v]=ty++;
               p_w[hx[point[i].u]][hy[point[i].v]]=point[i].w;
          }           int linkx[maxn];
          int linky[maxn];
          for(int i=0; i<maxn; i++) linkx[i]=i,linky[i]=i;           printf("Case #%d:\n",w);           int T;
          int Q,A,B;
          scanf("%d",&T);
          while(T--) {
               scanf("%d%d%d",&Q,&A,&B);                if(Q==1) {
                    int tem=linkx[hx[A]];
                    linkx[hx[A]]=linkx[hx[B]];
                    linkx[hx[B]]=tem;
               }
               if(Q==2) {
                    int tem=linky[hy[A]];
                    linky[hy[A]]=linky[hy[B]];
                    linky[hy[B]]=tem;
               }
               if(Q==3)
                    printf("%d\n",p_w[linkx[hx[A]]][linky[hy[B]]]);
          }
     }
}

HDU 4941 Magical Forest 【离散化】【map】的更多相关文章

  1. hdu 4941 Magical Forest (map容器)

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  2. HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...

  3. 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 ...

  4. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  5. hdu 4941 Magical Forest

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...

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

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  7. HDU 4941 Magical Forest (Hash)

    这个题比赛的时候是乱搞的,比赛结束之后学长说是映射+hash才恍然大悟.因此决定好好学一下hash. 题意: M*N的格子,里面有一些格子里面有一个值. 有三种操作: 1.交换两行的值. 2.交换两列 ...

  8. HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)

    思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   . r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j ...

  9. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

随机推荐

  1. PHP 转义详解

    php中数据的魔法引用函数 magic_quotes_gpc  或 magic_quotes_runtime 设置为on时,为我们引用的数据碰到 单引号' 和 双引号" 以及 反斜线\ 时自 ...

  2. Unity 内置着色器(转)

    Unity包括超过40种内置的shader. 标准着色器家族 Normal Shader Family 这些着色器都是Unity基本的着色器.适用于大多数的不透明物体,如果想要物体有透明.发光效果等, ...

  3. Java多线程的五种状态

    新建状态:new Thread(参数)之后,建立了一个线程对象; 就绪状态:线程对象建立之后,调用start()方法,进入就绪状态,此时并不会直接调用run()方法,线程进入运行状态还需要抢占CPU资 ...

  4. 【LeetCode】189 - Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  5. Protocol Buffer详解

    1.Protocol Buffer 概念 Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 ...

  6. c++ List、Vector、Stack、Queue使用

    一.List使用 引入头文件#include <list> List基本函数Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比 ...

  7. HDU5874:Friends and Enemies

    题目链接: Friends and Enemies 分析: 是一道想法题,我们假设x个人互相敌对,然后有y个人与这x个人都是朋友,而这y个人互相敌对. 则有 x+y=m x*y<=n 举个例子: ...

  8. NetBeans IDE 7.4 Beta版本build JavaFX时生成的可执行jar包执行时找不到依赖的jar包

    现象,执行时抛出java.lang.ClassNotFoundException异常: Executing E:\secondegg\secondegg-reversi\dist\run8022211 ...

  9. [转]模拟HttpContext 实现ASP.NET MVC 的单元测试

    众所周知 ASP.NET MVC 的一个显著优势即可以很方便的实现单元测试,但在我们测试过程中经常要用到HttpContext,而默认情况下单元测试框架是不提供HttpContext的模拟的,本文通过 ...

  10. HDU 1564 Play a game (找规律博弈)

    Play a game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...