map容器结构体离散化
小数坐标离散化:
#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容器结构体离散化的更多相关文章
- map中结构体做关键字的注意事项
序: 今天做一道题,由于递归函数比较恶心,如果用记忆化搜索,数据范围极大却又用不全(二维数组存的话直接炸).所以决定干脆使用stl::map存储(反正有O2优化),但是执行insert的时候,编译器却 ...
- go 数组(array)、切片(slice)、map、结构体(struct)
一 数组(array) go语言中的数组是固定长度的.使用前必须指定数组长度. go语言中数组是值类型.如果将数组赋值给另一个数组或者方法中参数使用都是复制一份,方法中使用可以使用指针传递地址. 声明 ...
- c++中数据表如何转成业务实体--map和结构体的相互转换
应用场景:如何把数据库表中的一行转换成一个业务实体结构体,c#和java中都有实体框架,表到实体的转换很方便,c++中缺少这些框架,但是有一些折中的办法去做.其实问题的本质是:map如何转成结构体. ...
- (三十八)golang--json(对切片、map、结构体进行序列化)
JSON(javascript object notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成.key-val JSON是在2001年开始推广的数据格式,目前已 ...
- std::map使用结构体自定义键值
使用STL中的map时候,有时候需要使用结构题自定义键值,比如想统计点的坐标出现的次数 struct Node{ int x,y; }; ...... map<Node,int>mp; m ...
- C:结构体
结构体 构造类型:就是有基本的类型组成的 1.结构体 结构体是一种自定义的数据类型 和 int float 是一样的都可以定义变量 数组 只能存放一种类型的容器 结构体 可以存放多种数据类型 ...
- 用set、map等存储自定义结构体时容器内部判别各元素是否相同的注意事项
STL作为通用模板极大地方便了C++使用者的编程,因为它可以存储任意数据类型的元素 如果我们想用set与map来存储自定义结构体时,如下 struct pp { double xx; double y ...
- Qt中文件操作遇到的(变量,容器,结构体)
咳咳!总结了一下我在使用QT文件操作时所用到的,再接再厉!再接再厉!! 1.保存到文件: QFile file("test.txt"); if (!file.open(QIODev ...
- c++ STL map 结构体
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候 ...
随机推荐
- python_matplotlib知识点总结
文作为学习过程中对matplotlib一些常用知识点的整理,方便查找. 强烈推荐ipython无论你工作在什么项目上,IPython都是值得推荐的.利用ipython --pylab,可以进入PyLa ...
- webstorm软件使用记录
右边的那条线的去除:setting-editor-appearance-show right margin 勾选去掉
- Hadoop集群作业调度算法
转自:http://blog.csdn.net/chen_jp/article/details/7983076 Hadoop集群中有三种作业调度算法,分别为FIFO,公平调度算法和计算能力调度算法 先 ...
- 关于Cocos2d-x的动作和动画
1.动作,在cocos2d-x中有非常多种的动作,各种移动,旋转,缩放,淡入淡出....等等非常多,但是这些动作只是作用于节点,最常作用于的就是精灵节点.而且我们可以把很多个动作放进一个Sequenc ...
- 【转】7Z命令行解压缩
7z.exe在CMD窗口的使用说明如下: 7-Zip (A) 4.57 Copyright (c) 1999-2007 Igor Pavlov 2007-12-06 Usage: 7za <co ...
- 关于解决用tutorial7教程中的代码打造一款自己的播放器中的声音噪音问题
////////////////////////////////////////////////////////////////////////////////////////////对于用FFMPE ...
- Vuforia AR实战教程
官网:https://developer.vuforia.com/ Vuforia AR实战教程 http://www.taikr.com/my/course/531. AQaVpF//////AAA ...
- Linux 同步方法剖析--内核原子,自旋锁和相互排斥锁
在学习 Linux® 的过程中,您或许接触过并发(concurrency).临界段(critical section)和锁定,可是怎样在内核中使用这些概念呢?本文讨论了 2.6 版内核中可用的锁定机制 ...
- /etc/docker/key.json
/etc/docker/key.json 描述信息: This is the dockerd key for TLS connections.in web format, that docker us ...
- [SQL]躺着也中枪的datetime类型
写在前面 本来这个东西,我是不想在这里总结的,今天有初学者的朋友问我了,那就不得不说说了,你肯定也踩过这样的坑,没遇到,说明你运气好,编码习惯好.那还是言归正传吧.避免你中枪,还是扫一眼这篇文章吧. ...