Sad Love Story

Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 16    Accepted Submission(s): 2

Problem Description
There's a really sad story.It could be about love or about money.But love will vanish and money will be corroded.These points will last forever.So this time it is about points on a plane.
We have a plane that has no points at the start.
And at the time i,we add point pi(xi, yi).There is n points in total.
Every time after we add a point,we should output the square of the distance between the closest pair on the plane if there's more than one point on the plane.
As there is still some love in the problem setter's heart.The data of this problem is randomly generated.
To generate a sequence x1, x2, ..., xn,we let x0 = 0,and give you 3 parameters:A,B,C. Then xi = (xi-1 * A + B) mod C.
The parameters are chosen randomly.
To avoid large output,you simply need output the sum of all answer in one line.
 
Input
The first line contains integer T.denoting the number of the test cases.
Then each T line contains 7 integers:n Ax Bx Cx Ay By Cy.
Ax,Bx,Cx is the given parameters for x1, ..., xn.
Ay,By,Cy is the given parameters for y1, ..., yn.
T <= 10. 
n <= 5 * 105.
104 <= A,B,C <= 106.
 
Output
For each test cases,print the answer in a line.
 
Sample Input
2
5 765934 377744 216263 391530 669701 475509
5 349753 887257 417257 158120 699712 268352
 
Sample Output
8237503125
49959926940

Hint

If there are two points coincide,then the distance between the closest pair is simply 0.

 
Source
 
Recommend
zhuyuanchen520
 

这道题目的意思就是不断加入n个点。

当点数>=2的时候,每加入一个点累加两点间最近距离的平方。

按照给定的Ax,Bx,Cx,Ay,By,Cy,以及递推式可以产生n个点。

The data of this problem is randomly generated.

根据这句话,知道数据是随机产生,没有极端数据。

所有首先n个点,做一下最近点对,复杂度O(nlogn)

然后产生的最近点对,对于编号在最近点对后面的结果都可以累加了,同时后面的点也不需要了。

所有去掉一部分点再次进行最近点对。

这样不断重复,直到剩下一个点为止。

/*
* Author:kuangbin
* 1011.cpp
*/ #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <math.h>
using namespace std;
const int MAXN = ;
struct Point
{
int x,y;
int id;
int index;
Point(int _x = ,int _y = ,int _index = )
{
x = _x;
y = _y;
index = _index;
}
}; Point P[MAXN]; long long dist(Point a,Point b)
{
return ((long long)(a.x-b.x)*(a.x-b.x) + (long long)(a.y-b.y)*(a.y-b.y));
}
Point p[MAXN];
Point tmpt[MAXN];
bool cmpxy(Point a,Point b)
{
if(a.x != b.x)return a.x < b.x;
else return a.y < b.y;
}
bool cmpy(Point a,Point b)
{
return a.y < b.y;
}
pair<int,int> Closest_Pair(int left,int right)
{
long long d = (1LL<<);
if(left == right)return make_pair(left,right);
if(left + == right)
return make_pair(left,right);
int mid = (left+right)/;
pair<int,int>pr1 = Closest_Pair(left,mid);
pair<int,int>pr2 = Closest_Pair(mid+,right);
long long d1,d2;
if(pr1.first == pr1.second)
d1 = (1LL<<);
else d1 = dist(p[pr1.first],p[pr1.second]); if(pr2.first == pr2.second)
d2 = (1LL<<);
else d2 = dist(p[pr2.first],p[pr2.second]); pair<int,int>ans;
if(d1 < d2)ans = pr1;
else ans = pr2; d = min(d1,d2); int k = ;
for(int i = left;i <= right;i++)
{
if((long long)(p[mid].x - p[i].x)*(p[mid].x - p[i].x) <= d)
tmpt[k++] = p[i];
}
sort(tmpt,tmpt+k,cmpy);
for(int i = ;i <k;i++)
{
for(int j = i+;j < k && (long long)(tmpt[j].y - tmpt[i].y)*(tmpt[j].y - tmpt[i].y) < d;j++)
{
if(d > dist(tmpt[i],tmpt[j]))
{
d = dist(tmpt[i],tmpt[j]);
ans = make_pair(tmpt[i].id,tmpt[j].id);
}
}
}
return ans;
} int main()
{
//freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int T;
int n,Ax,Ay,Bx,By,Cx,Cy;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d%d%d",&n,&Ax,&Bx,&Cx,&Ay,&By,&Cy);
P[] = Point(,,);
for(int i = ;i <= n;i++)
{
long long x= ((long long)P[i-].x*Ax + Bx)%Cx;
long long y = ((long long)P[i-].y*Ay + By)%Cy;
P[i] = Point(x,y,i);
}
int end = n;
long long ans = ;
while(end > )
{
for(int i = ;i < end;i++)
p[i] = P[i+];
sort(p,p+end,cmpxy);
for(int i = ;i < end;i++)
p[i].id = i;
pair<int,int>pr = Closest_Pair(,end-);
int Max = max(p[pr.first].index,p[pr.second].index);
ans += (long long)(end-Max+)*dist(p[pr.first],p[pr.second]);
end = Max-;
}
printf("%I64d\n",ans); }
return ;
}

HDU 4631 Sad Love Story (2013多校3 1011题 平面最近点对+爆搞)的更多相关文章

  1. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  2. HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)

    Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  3. HDU 4671 Backup Plan (2013多校7 1006题 构造)

    Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  4. HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)

    Building Fence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  5. HDU 4658 Integer Partition (2013多校6 1004题)

    Integer Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDU 4611 Balls Rearrangement(2013多校2 1001题)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  7. HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)

    Cut Pieces Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  8. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  9. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

随机推荐

  1. 64_f2

    flxmlrpc-0.1.4-5.fc26.x86_64.rpm 22-May-2017 21:32 57950 flxmlrpc-devel-0.1.4-5.fc26.i686.rpm 22-May ...

  2. golang锁记

    golang中有两个锁实现 atomic的CAS实现锁 首先是inter cpu,熟悉汇编的人都知道,inter指令集有个lock,如果某个指令集前面加个lock,那么在多核状态下,某个核执行到这个前 ...

  3. 【ZJOI2016】大森林

    这题理论上可以用ETT,但是用LCT建虚点可以解决这个问题. 对于最晚的操作1建立一个虚点,然后把操作0挂上去. #include<bits/stdc++.h> ; using names ...

  4. VPS性能综合测试(7):服务器压力测试,VPS系统负载测试

    1.可能有的VPS主机使用性能测评工具得出的结果很优秀,但是最终运用到实际生产时却发现VPS主机根本无法承受理论上应该达到的流量压力,这时我们就不得不要怀疑VPS商是不是对VPS主机的参数进行了“篡改 ...

  5. display:inline、block、inline-block三者之间的区别

    1. display:block就是将元素显示为块级元素. block元素的特点: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度:(<d ...

  6. python_day1学习笔记

    一.Python 2.7.x 和 3.x 版本的区别小结 print函数 1.python2 import platform print ‘Python’, platform.python_versi ...

  7. Http请求加签、验证操作

    加签.验签的作用 常见的http请求交互过程中,请求参数通过url或者request body等形式传输.但是由于http请求的开放性,使得请求参数很容易被拦截篡改.因此,需要对请求参数进行加签,然后 ...

  8. 六:ZooKeeper的java客户端api的使用

    一:客户端链接测试 package com.yeepay.sxf.createConnection; import java.io.IOException; import org.apache.zoo ...

  9. poj 2104(线段树)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 45653   Accepted: 15177 Ca ...

  10. 自己编译生成k8s的rpm包

    我指的是以下几个安装包: -rw-r--r--. 1 root root 8976134 Jul 13 10:19 kubeadm-1.7.0-0.x86_64.rpm-rw-r--r--. 1 ro ...