HDOJ 4631 Sad Love Story
来源:互联网 发布:试衣间软件 编辑:程序博客网 时间:2024/06/11 09:55
STL+暴力
Sad Love Story
Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1583 Accepted Submission(s): 498
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.
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.
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
25 765934 377744 216263 391530 669701 4755095 349753 887257 417257 158120 699712 268352
Sample Output
823750312549959926940HintIf there are two points coincide,then the distance between the closest pair is simply 0.
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <set>using namespace std;typedef long long int LL;typedef pair<LL,LL> pII;int T_T,n;LL A[2],B[2],C[2],pre_x,pre_y;LL get_next(LL x,int kind){ ///0...x 1...y return (x*A[kind]+B[kind])%C[kind];}LL get_dist(LL x1,LL y1,LL x2,LL y2){ return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);}int main(){ scanf("%d",&T_T);while(T_T--){ scanf("%d%I64d%I64d%I64d%I64d%I64d%I64d",&n,A,B,C,A+1,B+1,C+1); LL ans=0,mindist=0x3f3f3f3f3f3f3f3fLL; set<pII> st; pre_x=get_next(0LL,0); pre_y=get_next(0LL,1); st.insert(make_pair(pre_x,pre_y));set<pII>::iterator it,pos,item; for(int i=2;i<=n;i++) { LL X,Y; X=get_next(pre_x,0); Y=get_next(pre_y,1);pos=st.lower_bound( make_pair(X,Y) );for(it=pos;it!=st.begin();){ it--;if(((X-(*it).first)*(X-(*it).first))>=mindist) break;else mindist=min(mindist,get_dist(X,Y,(*it).first,(*it).second));}for(it=pos;it!=st.end();it++){if(((X-(*it).first)*(X-(*it).first))>=mindist) break;else mindist=min(mindist,get_dist(X,Y,(*it).first,(*it).second));}pre_x=X,pre_y=Y;st.insert(make_pair(X,Y)); ans+=mindist; } printf("%I64d\n",ans);}return 0;}
0 0
- HDOJ 4631 Sad Love Story
- hdu 4631 Sad Love Story
- hdu - 4631 - Sad Love Story
- HDU-4631-Sad Love Story
- HDU 4631 Sad Love Story
- hdu 4631Sad Love Story
- hdu 4631 Sad Love Story (STL+multiset)
- hdu 4631 Sad Love Story(暴力)
- hdu 4631 Sad Love Story 多校第三场
- 2013 多校第三场 hdu 4631 Sad Love Story
- hdu 4631 Sad Love Story (暴力set+剪枝)
- HDU 4631 - Sad Love Story(最近点对)
- 【解题报告】HDU 4631 Sad Love Story 最短点距(动态)
- hdu 4631 Sad Love Story(最近点对+暴力)
- HDU Sad Love Story StL 暴搜
- Sad Love Story(hdu4631,模拟+set容器)
- 多校第三场 Hdu4631 Sad Love Story(最近点对)
- HDU4631 Sad Love Story(最近点对)转自网络
- 保留2位小数多种方法
- IOS开发常用的开源类库5
- opencv 新环境编译步骤
- 关于Oracle10.2.0.5+linux5+raid5 IO问题分析
- java链表 约瑟夫问题
- HDOJ 4631 Sad Love Story
- IOS开发常用的开源类库6
- jfreechart 生成折线图,饼图,柱状图,堆栈柱状图
- hdu 1425 堆排序
- AOJ-AHU-OJ-662 越来越快
- 面试题目记录
- Huffman 编码压缩算法
- 创业必读:做一些“糟糕”的工作
- 一套UI控件