HDU Sad Love Story StL 暴搜

73 篇文章 21 订阅
56 篇文章 0 订阅

 

 

米啥好讲滴。。就是StL <set>的用法。。。。

 

Sad Love Story

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


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 p i(x i, y i).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 x 1, x 2, ..., x n,we let x 0 = 0,and give you 3 parameters:A,B,C. Then x i = (x i-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 A x B x C x A y B y C y.
    A x,B x,C x is the given parameters for x 1, ..., x n.
    A y,B y,C y is the given parameters for y 1, ..., y n.
    T <= 10.
    n <= 5 * 10 5.
    10 4 <= A,B,C <= 10 6.
 

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.
 
 
#include <cstdio>
#include <cstdlib>
#include <set>
#include <iostream>
using namespace std;

#define LL long long
const int MAXN=555555;
LL x[MAXN],y[MAXN];
struct node{
    LL x,y;
    bool const operator < (const node& tmp) const{
        return x<tmp.x||(x==tmp.x&&y<tmp.y);
    }
};

void calcin(int n,LL s[]){
    LL a,b,c;
    cin>>a>>b>>c;
    s[0]=0;
    for(int i=1;i<=n;i++){
        s[i]=(s[i-1]*a+b)%c;
       // printf("s[%d]=%lld\n",i,s[i]);
    }
}
void solve(int n){
    calcin(n,x);
    calcin(n,y);
    set<node> s;
    set<node>::iterator it,t1,t2;
    node tmp;
    LL ans=1LL<<60,k,ret=0;
    for(int i=1;i<=n;i++){
        tmp.x=x[i],tmp.y=y[i];
        if(i>1){
            it=s.lower_bound(tmp);
            for(t1=it;t1!=s.end();t1++){
                k=(t1->x-tmp.x)*(t1->x-tmp.x);
                if(k>ans)
                    break;
                k+=(t1->y-tmp.y)*(t1->y-tmp.y);
                ans=min(k,ans);
            }
            for(t2=it;t2!=s.begin();){
                --t2;
                k=(t2->x-tmp.x)*(t2->x-tmp.x);
                if(k>=ans)
                    break;
                k+=(t2->y-tmp.y)*(t2->y-tmp.y);
                ans=min(k,ans);
            }
            ret+=ans;
        }
        s.insert(tmp);
    }
    cout<<ret<<endl;
}
int main(){
    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        solve(n);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值