zoukankan      html  css  js  c++  java
  • HDU4631+Set+最近点对

    题意:一个空平面,每次增加一个点,
    其坐标根据上一个点算出:(x[i-1] * Ax + Bx ) mod Cx,(y[i-1] * Ay + By ) mod Cy

    求出现有点集中的最近点对的距离的平方,共增加n个点,求每次求得的平方的和


    http://blog.csdn.net/liuledidai/article/details/9664031

     1 /*
     2 set+最近点对
     3 每次对于一个新插入的点,找出x与之最近的,然后分别向两侧搜
     4 题意:一个空平面,每次增加一个点,
     5 其坐标根据上一个点算出:(x[i-1] * Ax + Bx ) mod Cx,(y[i-1] * Ay + By ) mod Cy
     6 求出现有点集中的最近点对的距离的平方,共增加n个点,求每次求得的平方的和
     7 */
     8 #include<stdio.h>
     9 #include<string.h>
    10 #include<stdlib.h>
    11 #include<algorithm>
    12 #include<iostream>
    13 #include<queue>
    14 #include<map>
    15 #include<set>
    16 #include<math.h>
    17 using namespace std;
    18 typedef long long int64;
    19 //typedef __int64 int64;
    20 const int maxn = 5e5+5;
    21 const int64 inf = 999999999999;
    22 const double pi=acos(-1.0);
    23 const double eps = 1e-8;
    24 struct Node{
    25     int64 x,y;
    26 };
    27 Node cur,nxt;
    28 typedef pair<int64,int64> PII;
    29 #define MP(a,b) make_pair((a),(b)) 
    30 set< pair<int64,int64> > s;
    31 int main(){
    32     int T;
    33     scanf("%d",&T);
    34     while( T-- ){
    35         int64 Ax,Bx,Cx,Ay,By,Cy;
    36         int n;
    37         scanf("%d%I64d%I64d%I64d%I64d%I64d%I64d",&n,&Ax,&Bx,&Cx,&Ay,&By,&Cy);
    38         //scanf("%d%lld%lld%lld%lld%lld%lld",&n,&Ax,&Bx,&Cx,&Ay,&By,&Cy);
    39         s.clear();
    40         cur.x = cur.y = 0;
    41         nxt.x = (Ax*cur.x+Bx)%Cx;
    42         nxt.y = (Ay*cur.y+By)%Cy;
    43         cur = nxt;
    44         s.insert( MP(cur.x,cur.y) );
    45         n--;
    46         int64 res,Min;
    47         res = 0;
    48         Min = inf;
    49         while( n-- ){
    50             if( Min==0 ) break; 
    51             nxt.x = (Ax*cur.x+Bx)%Cx;
    52             nxt.y = (Ay*cur.y+By)%Cy;
    53             cur = nxt;
    54             if( s.count(MP(cur.x,cur.y)) ) {
    55                 res += 0;
    56                 break;
    57             }
    58             s.insert( MP(cur.x,cur.y) );
    59             set<PII>::iterator it,tmp;
    60             it = s.lower_bound( MP(cur.x,cur.y) );
    61             for( tmp=it,tmp++;tmp!=s.end();tmp++ ){
    62                 int64 tx = (*tmp).first;
    63                 int64 ty = (*tmp).second;
    64                 if( (tx-cur.x)*(tx-cur.x)>=Min ) break;
    65                 else{
    66                     int64 Dis = (tx-cur.x)*(tx-cur.x)+(ty-cur.y)*(ty-cur.y);
    67                     Min = min( Min,Dis );
    68                 }
    69             }
    70             for( tmp=it,tmp--;it!=s.begin();tmp-- ){
    71                 int64 tx = (*tmp).first;
    72                 int64 ty = (*tmp).second;
    73                 if( (tx-cur.x)*(tx-cur.x)>=Min ) break;
    74                 else{
    75                     int64 Dis = (tx-cur.x)*(tx-cur.x)+(ty-cur.y)*(ty-cur.y);
    76                     Min = min( Min,Dis );
    77                 }
    78                 if( tmp==s.begin() ) break;
    79             }
    80             res += Min;
    81         }
    82         //printf("%lld
    ",res);
    83         printf("%I64d
    ",res);
    84     }
    85     return 0;
    86 }
    View Code
    keep moving...
  • 相关阅读:
    Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA
    mysql使用instr
    swagger错误:Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body
    java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result异常的解决方法
    平行四边形
    transition
    transform
    box-shadow
    text-shadow文字阴影
    linear-gradient线性渐变
  • 原文地址:https://www.cnblogs.com/xxx0624/p/3254002.html
Copyright © 2011-2022 走看看