小数坐标离散化:
#include"string.h"
#include"stdio.h"
#include"iostream"
#include"algorithm"
#include"queue"
#include"stack"
#include"stdlib.h"
#include"map"
#include"string"
#include"math.h"
#define inf 10000000
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
const double r2=sqrt(2.0);
const int M=100;
const int N=1010*502*2;
const double g=9.8;
#define eps 1e-10
using namespace std;
struct node
{
double x,y;
node(){}
node(double xx,double yy)
{
x=xx;
y=yy;
}
bool operator<(const node &b)const
{
if(fabs(x-b.x)<eps)
return y<b.y;
else
return x<b.x;
}
};
int main()
{
int n,i;
while(scanf("%d",&n)!=-1)
{
map<node,int>mp;
int cnt=0;
for(i=1;i<=n;i++)
{
node e;
scanf("%lf%lf",&e.x,&e.y);
if(!mp[e])
mp[e]=++cnt;
}
double a,b;
while(scanf("%lf%lf",&a,&b)!=-1)
{
node t(a,b);
printf("%d\n",mp[t]);
}
}
}

整数二维坐标离散化:

#include"string.h"
#include"stdio.h"
#include"iostream"
#include"algorithm"
#include"queue"
#include"stack"
#include"stdlib.h"
#include"map"
#include"string"
#include"math.h"
#define inf 10000000
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
const double r2=sqrt(2.0);
const int M=100;
const int N=1010*502*2;
const double g=9.8;
#define eps 1e-10
using namespace std;
struct node
{
int x,y;
node(){}
node(int xx,int yy)
{
x=xx;
y=yy;
}
bool operator<(const node &b)const
{
if(x==b.x)
return y<b.y;
else
return x<b.x;
}
};
int main()
{
int n,i;
while(scanf("%d",&n)!=-1)
{
map<node,int>mp;
int cnt=0;
for(i=1;i<=n;i++)
{
node e;
scanf("%d%d",&e.x,&e.y);
if(!mp[e])
mp[e]=++cnt;
}
int a,b;
while(scanf("%d%d",&a,&b)!=-1)
{
node t(a,b);
printf("%d\n",mp[t]);
}
}
}

同理三维多维也可以:

#include"string.h"
#include"stdio.h"
#include"iostream"
#include"algorithm"
#include"queue"
#include"stack"
#include"stdlib.h"
#include"map"
#include"string"
#include"math.h"
#define inf 10000000
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
const double r2=sqrt(2.0);
const int M=100;
const int N=1010*502*2;
const double g=9.8;
#define eps 1e-10
using namespace std;
struct node
{
int x,y,z;
node(){}
node(int xx,int yy,int zz)
{
x=xx;
y=yy;
z=zz;
}
bool operator<(const node &b)const
{
if(z==b.z)
{
if(y==b.y)
return x<b.x;
else
return y<b.y;
}
else
return z<b.z;
}
};
int main()
{
int n,i;
while(scanf("%d",&n)!=-1)
{
map<node,int>mp;
int cnt=0;
for(i=1;i<=n;i++)
{
node e;
scanf("%d%d%d",&e.x,&e.y,&e.z);
if(!mp[e])
mp[e]=++cnt;
}
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=-1)
{
node t(a,b,c);
printf("%d\n",mp[t]);
}
}
}

map容器结构体离散化的更多相关文章

  1. map中结构体做关键字的注意事项

    序: 今天做一道题,由于递归函数比较恶心,如果用记忆化搜索,数据范围极大却又用不全(二维数组存的话直接炸).所以决定干脆使用stl::map存储(反正有O2优化),但是执行insert的时候,编译器却 ...

  2. go 数组(array)、切片(slice)、map、结构体(struct)

    一 数组(array) go语言中的数组是固定长度的.使用前必须指定数组长度. go语言中数组是值类型.如果将数组赋值给另一个数组或者方法中参数使用都是复制一份,方法中使用可以使用指针传递地址. 声明 ...

  3. c++中数据表如何转成业务实体--map和结构体的相互转换

    应用场景:如何把数据库表中的一行转换成一个业务实体结构体,c#和java中都有实体框架,表到实体的转换很方便,c++中缺少这些框架,但是有一些折中的办法去做.其实问题的本质是:map如何转成结构体. ...

  4. (三十八)golang--json(对切片、map、结构体进行序列化)

    JSON(javascript object notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成.key-val JSON是在2001年开始推广的数据格式,目前已 ...

  5. std::map使用结构体自定义键值

    使用STL中的map时候,有时候需要使用结构题自定义键值,比如想统计点的坐标出现的次数 struct Node{ int x,y; }; ...... map<Node,int>mp; m ...

  6. C:结构体

    结构体 构造类型:就是有基本的类型组成的 1.结构体  结构体是一种自定义的数据类型 和 int float 是一样的都可以定义变量 数组 只能存放一种类型的容器 结构体   可以存放多种数据类型  ...

  7. 用set、map等存储自定义结构体时容器内部判别各元素是否相同的注意事项

    STL作为通用模板极大地方便了C++使用者的编程,因为它可以存储任意数据类型的元素 如果我们想用set与map来存储自定义结构体时,如下 struct pp { double xx; double y ...

  8. Qt中文件操作遇到的(变量,容器,结构体)

    咳咳!总结了一下我在使用QT文件操作时所用到的,再接再厉!再接再厉!! 1.保存到文件: QFile file("test.txt"); if (!file.open(QIODev ...

  9. c++ STL map 结构体

    Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候 ...

随机推荐

  1. EasyUi---searchbox 条件查询

    前台UI参考代码: <script type="text/javascript" charset="utf-8"> $(function(){ /* ...

  2. 数学符号arg含义

    argument of the maximum/minimum arg max f(x): 当f(x)取最大值时,x的取值 arg min f(x):当f(x)取最小值时,x的取值 表示使目标函数取最 ...

  3. 《FPGA全程进阶---实战演练》第二章之PCB layout注意事项以及投板几点说明

           上一篇博客讲述了各个部分的原理图,那么根据原理图画出PCB,其实PCB是一门很大的学问,想要掌握谈何容易.就笔者在画PCB时的一些注意事项做一些说明.        1.电源部分的电源线 ...

  4. 关于Java获取文件路径的几种方法

    第一种:File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f);  ...

  5. 【转】【Android】Android不同版本下Notification创建方法

    使用 new Notification(int icon, CharSequence tickerText, long when)构造函数时,Eclipse却提示:" The constru ...

  6. debian下系列下的apt-get 命令与deb包的手动安装的dpkg命令

    手动下载的deb包的相关操作: 操作deb 使用dpkg 命令工具, dpkg 是Debian package的简写. 下面列举常用的 操作: dpkg –I name.deb  查看 包的详细信息( ...

  7. Servlet程序的入口点是?( )

    Servlet程序的入口点是?( ) A.init() B.main() C.service() D.doGet() 解答:C

  8. Kernel.org 被黑,获取 Android 源码方法一则

    8 月底 9 月初,作为 Linux 的老窝,Kernel.org 被黑客攻击了,其攻击原因众说纷纭.一直以来 Linux 对于我来说不是很感兴趣,所以从来不会关注类似事件,可是这次这个攻击,却影响到 ...

  9. css制作上下左右的箭头

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. [转]JVM运行时内存结构

    [转]http://www.cnblogs.com/dolphin0520/p/3783345.html 目录[-] 1.为什么会有年轻代 2.年轻代中的GC 3.一个对象的这一辈子 4.有关年轻代的 ...