hdu 4631 Sad Love Story (STL+multiset)
来源:互联网 发布:网络电话卡有哪些 编辑:程序博客网 时间:2024/05/22 17:28
Sad Love Story
Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1710 Accepted Submission(s): 548
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.
题意: 给你坐标的计算公式xi=(xi-1*A+B)%C(y计算相同,但A、B、C值的不同),然后可以得
到n个坐标,在平面上添加坐标,每添加一个坐标则计算平面上2坐标间的最小值,然后要求
输出所有最小值的和。
思路:按照题目要求,按1-n的顺序添加点。在已有的点集中按X坐标从小到大排序,每增加一
个点,找到大于等于它的位置t,分为两部分,然后从右递增计算要增加的点与点集中的点的距
离,若>=Min,则退出,然后再从t-1处从右往左递减计算要增加的点与点集中所有点的距离的最
小值。
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <set>#define LL long longusing namespace std;const LL inf=((LL)1<<62);const int maxn=500010;struct node{ LL x,y;} a[maxn],A,B,C;int n,T;bool operator < (node p,node q){ return p.x<q.x;}void input(){ scanf("%d",&n); scanf("%I64d %I64d %I64d",&A.x,&B.x,&C.x); scanf("%I64d %I64d %I64d",&A.y,&B.y,&C.y); a[0].x=a[0].y=0; for(int i=1; i<=n; i++) { a[i].x=(a[i-1].x*A.x+B.x)%C.x; a[i].y=(a[i-1].y*A.y+B.y)%C.y; }}void solve(){ multiset <node> st; multiset <node>::iterator it,t; st.insert(a[1]); LL ans=0,Min=inf; for(int i=2; i<=n; i++) { node tmp=a[i]; t=st.lower_bound(tmp); for(it=t;it!=st.begin();) { it--; LL xx=it->x-tmp.x; xx=xx*xx; if(xx>=Min) break; Min=min(Min,xx+(it->y-tmp.y)*(it->y-tmp.y)); } for(it=t;it!=st.end();it++) { LL xx=it->x-tmp.x; xx=xx*xx; if(xx>=Min) break; Min=min(Min,xx+(it->y-tmp.y)*(it->y-tmp.y)); } st.insert(a[i]); ans+=Min; } printf("%I64d\n",ans);}int main(){ scanf("%d",&T); while(T--) { input(); solve(); } return 0;}
0 0
- hdu 4631 Sad Love Story (STL+multiset)
- 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 Sad Love Story StL 暴搜
- hdu 4631 Sad Love Story(暴力)
- HDOJ 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(最近点对+暴力)
- Sad Love Story(hdu4631,模拟+set容器)
- hdu 4302 STL multiset
- 多校第三场 Hdu4631 Sad Love Story(最近点对)
- CCS+C6678LE开发记录15:多核协作(OpenMP)示例探索
- URAL 1820. Ural Steaks(数学啊 )
- Oracle Restart
- 编写一个函数,它从一个字符串中提取一个子字符串。函数原型如下: Int substr(char dst[], char src[],int start, int len) {} 目标是:从src数组
- Android 从小白到大拿之路——应用程序自动转屏
- hdu 4631 Sad Love Story (STL+multiset)
- SVN使用教程总结
- C语言学习笔记(七) -字符串 String
- 11、广告条 ViewPage
- Java设计模式——桥接模式(Bridge)
- Intersection of Two Linked Lists
- Python学习之路——内存管理
- myeclipse6.5的alt+/功能,内容辅助,快捷键设置
- Cocos2D-X 3.4 移植 Android