链接: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. 关于conversation generation的论文笔记

    对话模型此前的研究大致有三个方向:基于规则.基于信息检索.基于机器翻译.基于规则的对话系统,顾名思义,依赖于人们周密设计的规则,对话内容限制在特定领域下,实际应用如智能客服,智能场馆预定系统.基于信息 ...

  2. 高校应该使用 Drupal 的10大理由

    使用 Drupal 已经成为全球顶尖高校中的一种潮流,它已经被全球数以百计的院校选择并应用,无论是哈佛.斯坦福.杜克.布朗.罗格斯.剑桥.耶鲁还是其它众多知名高校,都已经选择 Drupal 作为它们理 ...

  3. Virtualenv介绍

    [翻译]http://virtualenv.readthedocs.org/en/latest/index.html virtualenv是创建独立python环境的一种工具. 环境搭建的过程中,有一 ...

  4. 国内外CDN服务商CNAME特征串调研

    总结 此篇博文给特定需求的人群使用,通过CNAME的某些特征串,确定其使用的是哪家CDN,大多是国外的CDN,国内的CDN厂商只有几个,格式为:[来源地址]+[截图]+[猜测的特征串],整体博文较长, ...

  5. 【LeetCode】19. Remove Nth Node From End of List

    题目: 思路:如果链表为空或者n小于1,直接返回即可,否则,让链表从头走到尾,每移动一步,让n减1. 1.链表1->2->3,n=4,不存在倒数第四个节点,返回整个链表 扫过的节点依次:1 ...

  6. 操作系统是怎么工作的——函数的堆栈框架/嵌入式代码

    1.函数堆栈框架 1.1框架模型 call指令: 1)将eip中的下一条指令的地址A保存在栈顶: 2)设置eip指向被调用程序的代码处. ret指令:将地址A恢复到eip中 这样就将函数的调用变为顺序 ...

  7. org.springframework.jdbc.BadSqlGrammarException

    org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLExc ...

  8. spring batch学习笔记

    Spring Batch是什么?       Spring Batch是一个基于Spring的企业级批处理框架,按照我师父的说法,所有基于Spring的框架都是使用了spring的IoC特性,然后加上 ...

  9. SVN与TortoiseSVN实战:补丁详解

    硬广:<SVN与TortoiseSVN实战>系列已经写了五篇,第二篇<SVN与TortoiseSVN实战:标签与分支>和第三篇<SVN与TortoiseSVN实战:Tor ...

  10. ostack