链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631

题意:依次给你n个点,每次求出当前点中的最近点对,输出所有最近点对的和;

思路:按照x排序,然后用set维护,每次插入只更新当前点和插入点前后几个位置~

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
const int MAX=5e5+;
typedef long long LL;
LL ax, bx, cx, ay, by, cy;
int T, N;
struct Point
{
LL x, y;
Point(){}
Point(LL a, LL b):x(a), y(b){};
bool operator < (const Point &p)const{
return x < p.x || (x == p.x && y < p.y);
} }p[MAX];
LL sqr(LL x)
{
return x*x;
}
LL Dis( Point A, Point B )
{
return sqr(A.x-B.x)+sqr(A.y-B.y);
} void Init( )
{
LL xx=, yy=;
for( int i=; i<N; ++ i ){
xx=(xx*ax+bx)%cx;
yy=(yy*ay+by)%cy;
p[i]=Point( xx, yy );
}
}
multiset<Point>st;
multiset<Point>::iterator it1, it2, it3;
void gao(){
st.clear();
LL ans = ;
st.insert(p[]);
LL mi = 1LL<<;
for (int i = ; i < N; i++){
Point t = p[i];
st.insert(t);
it1 = it2 = it3 = st.lower_bound(t);
int k = ;
while (k--){
if (it1 != st.begin()) it1--;
if (it3 != it1){
LL d1 = Dis(t,*it1);
if (d1<mi){
mi = d1;
}
}
if (it2 != st.end()) it2++;
if (it2 != st.end() && it2!= it3){
LL d2 = Dis(t,*it2);
if (d2 < mi){
mi = d2;
}
}
}
ans += mi;
if (mi == ) break;
}
printf("%I64d\n",ans);
}
int main()
{
scanf("%d", &T);
while(T--){
scanf("%d", &N);
scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &ax, &bx, &cx, &ay, &by, &cy);
Init();
gao();
}
return ;
}

hdu 4631Sad Love Story<计算几何>的更多相关文章

  1. HDU 5130 Signal Interference(计算几何 + 模板)

    HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...

  2. HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...

  3. hdu 1174:爆头(计算几何,三维叉积求点到线的距离)

    爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  4. HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)

    Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  5. HDU 4606 Occupy Cities (计算几何+最短路+最小路径覆盖)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题目:给出n个城市需要去占领,有m条线段是障碍物, ...

  6. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  7. HDU 5839 Special Tetrahedron 计算几何

    Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...

  8. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. hdu 1348:Wall(计算几何,求凸包周长)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. opencv基于HSV的肤色分割

    //函数功能:在HSV颜色空间对图像进行肤色模型分割 //输入:src-待处理的图像,imgout-输出图像 //返回值:返回一个iplimgae指针,指向处理后的结果 IplImage* SkinS ...

  2. Orchard官方文档翻译(三) 通过zip文件手动安装Orchard

    原文地址:http://docs.orchardproject.net/Documentation/Manually-installing-Orchard-zip-file 想要查看文档目录请用力点击 ...

  3. 使用AS3.0代码实现给图片添加滤镜的模糊与斜角效果

    滤镜可应用于任何显示对象(即,从 DisplayObject 类继承的对象), 例如 MovieClip.SimpleButton.TextField 和 Video 对象,以及 BitmapData ...

  4. 慕课网-安卓工程师初养成-4-6 Java条件语句之 switch

    来源:http://www.imooc.com/code/1358 当需要对选项进行等值判断时,使用 switch 语句更加简洁明了.例如:根据考试的名次,给予前 4 名不同的奖品.第一名,奖励笔记本 ...

  5. 【练习】显示MYSQL客户机选项

    [oracle@enmo ~]$ mysql --help mysql Ver , for Linux (x86_64) using EditLine wrapper Copyright (c) , ...

  6. Select的深入应用(2)

    首先创建两张表. 全连接 全连接:在检索时指定多个表,将每个表用逗号分隔,这样每个表的数据行都和其他表的每行交叉产生所有可能的组合,这样就是一个全连接.所有可能的组和数即每个表的行数的乘积. 或者: ...

  7. matlab读取txt文档中的数据

    ps:文件中只有数字! format long fp=fopen('文件路径','打开方式(r)') [num,count]=fscnaf(fp,'%f')

  8. Web 项目 中读取专用配置文件

    在 web 开发中,有时我们要为 业务逻辑处理 配置专用的 配置文件,也就是 xml 文件,这样可以极大的方便维护工作,但是读取 专用的配置文件还需要自己写一个方法,在这里,我封装了一个公用 的方法: ...

  9. AX 利用windows粘贴板功能实现批量数据快速导出EXCEL

    static void test(Args _args) { int lineNum; int titleLines; SysExcelApplication excel; SysExcelWorkb ...

  10. WP8_(windows phone环境下)上传文件从C#到php接口

    在windows phone环境下,将手机上的图片上传到服务端(php环境): 注意事项:在上传的地方,头文件中name,例如name= img,则在php服务端处理时 ,需要约定好 存取一致 php ...