链接: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. Oozie 中各种类型的作业执行结果记录

    一,提交的作业被SUSPEND,然后再被KILL,记录如下: TYPE1: appType WORKFLOW_JOB id 0000002-160516095026479-oozie-oozi-W e ...

  2. PMP考试--成本管理中常用的概念

    如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 净现值(NPV)   Net Present Value 在项目计算期内,按行业基准 ...

  3. 第4章 sed命令

    1 sed命令基本用法 sed(stream editor)是流编辑器,可对文本文件和标准输入进行编辑: sed只是对缓冲区中原始文件的副本进行编辑,并不编辑原始的文件,如果需要保存改动内容,可以选择 ...

  4. childNodes在IE与Firefox中的区别

    嗯,这是前几天写一个遍历双层List集合,动态输出对应的表格并且控制固定表头的效果时发现的一个知识点,程序编好后在IE8浏览器下测试没问题,在Firefox35.0.1总是报错,后来发现是IE与FF对 ...

  5. Facebook 的系统架构(转)

    来源:http://www.quora.com/What-is-Facebooks-architecture(由Micha?l Figuière回答) 根据我现有的阅读和谈话,我所理解的今天Faceb ...

  6. Asp.Net获取IP的方法

    服务端: //方法一 HttpContext.Current.Request.UserHostAddress; //方法二 HttpContext.Current.Request.ServerVari ...

  7. 互斥对象 Mutex 和MFC中的CMutex

    互斥(Mutex)是一种用途非常广泛的内核对象.能够保证多个线程对同一共享资源的互斥访问.同临界区有些类似,只有拥有互斥对象的线程才具有访问资源的权限,由于互斥对象只有一个,因此就决定了任何情况下此共 ...

  8. 在PHP5.3以上版本运行ecshop和ecmall出现的问题及解决方案

    ecshop 问题一:商城首页报错 Strict Standards: Only variables should be passed by reference in D:\wamp\ecshop\i ...

  9. php 单例设计模式 example

    <?php class User { //静态变量保存全局变量 private static $_instance=null; //私有化构造函数,防止外界实例化对象 private funct ...

  10. Oracle笔记 十一、PL/SQL函数和触发器

    --创建函数 create or replace function add_sal(sSal number) return number is begin if (sSal > 5000) th ...