HDU4631(杭电2013多校第三场1011)

Sad Love Story

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
2013 Multi-University Training Contest 3
 
这道题目的意思就是不断加入n个点。

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

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

The data of this problem is randomly generated.

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

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

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

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

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


#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 = 500010;
struct Point
{
    int x,y;
    int id;
    int index;
    Point(int _x = 0,int _y = 0,int _index = 0)
    {
        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<<50);
    if(left == right)return make_pair(left,right);
    if(left + 1 == right)
        return make_pair(left,right);
    int mid = (left+right)/2;
    pair<int,int>pr1 = Closest_Pair(left,mid);
    pair<int,int>pr2 = Closest_Pair(mid+1,right);
    long long d1,d2;
    if(pr1.first == pr1.second)
        d1 = (1LL<<50);
    else d1 = dist(p[pr1.first],p[pr1.second]);

    if(pr2.first == pr2.second)
        d2 = (1LL<<50);
    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 = 0;
    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 = 0;i <k;i++)
    {
        for(int j = i+1;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[0] = Point(0,0,0);
        for(int i = 1;i <= n;i++)
        {
            long long x= ((long long)P[i-1].x*Ax + Bx)%Cx;
            long long y = ((long long)P[i-1].y*Ay + By)%Cy;
            P[i] = Point(x,y,i);
        }
        int end = n;
        long long ans = 0;
        while(end > 1)
        {
            for(int i = 0;i < end;i++)
                p[i] = P[i+1];
            sort(p,p+end,cmpxy);
            for(int i = 0;i < end;i++)
                p[i].id = i;
            pair<int,int>pr = Closest_Pair(0,end-1);
            int Max = max(p[pr.first].index,p[pr.second].index);
            ans += (long long)(end-Max+1)*dist(p[pr.first],p[pr.second]);
            end = Max-1;
        }
        printf("%I64d\n",ans);


    }
    return 0;
}


资源下载链接为: https://pan.quark.cn/s/d3128e15f681 罗技MX Master 2S是一款高端无线鼠标,凭借其卓越的性能和舒适性,深受专业设计师、程序员以及需要长时间使用鼠标的人群的喜爱。它在macOS平台上表现出色,功能丰富。而“LogiMgr Installer 8.20.233.zip”是该鼠标在macOS系统上对应的软件安装程序,版本号为8.20.233,主要功能如下: 驱动安装:该安装包可确保MX Master 2S在macOS系统中被正确识别和配置,发挥出最佳硬件性能,同时保证良好的兼容性。它会安装必要的驱动程序,从而启用鼠标的高级功能。 自定义设置:借助此软件,用户能够根据自己的工作习惯,对MX Master 2S的各个按钮和滚轮功能进行自定义。比如设置特定快捷键、调整滚动速度和方向等,以满足个性化需求。 Flow功能:罗技Flow是一项创新技术,允许用户在台设备间无缝切换。只需在软件中完成设备配置,鼠标就能在不同电脑之间进行复制、粘贴操作,从而大幅提升工作效率。 电池管理:软件具备电池状态监控功能,可帮助用户实时了解MX Master 2S的电量情况,并及时提醒用户充电,避免因电量不足而影响工作。 手势控制:MX Master 2S配备独特的侧边滚轮和拇指按钮,用户可通过软件定义这些手势,实现诸如浏览页面、切换应用等操作,进一步提升使用便捷性。 兼容性优化:罗技的软件会定期更新,以适应macOS系统的最新变化,确保软件与操作系统始终保持良好的兼容性,保障鼠标在不同系统版本下都能稳定运行。 设备配对:对于拥有个罗技设备的用户,该软件能够方便地管理和配对这些设备,实现快速切换,满足设备使用场景下的需求。 在安装“LogiMgr Installer 8.20.233.app”时,用户需确保macOS系统满足软件的最低要求,并
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值