zoukankan      html  css  js  c++  java
  • HDU4714+三分

    题意:给定N个点,每个点有初始位置和初始速度。

    问:在哪个时刻 使得所有的点的最大距离值最小。

    分析:一开始枚举两两之间的最大值,然后在最大值中求一个最小值。。。(WA:题意严重理解不清。。)

    由两点之间的距离公式(与T一个系数有关)可知,这个公式是典型的抛物线,因此可以进行三分查找答案,正解!

     1 /*
     2 wa
     3 */
     4 #include<algorithm>  
     5 #include<iostream>  
     6 #include<string.h>  
     7 #include<stdlib.h>  
     8 #include<stdio.h>  
     9 #include<math.h>  
    10 #include<queue>  
    11 #include<stack>  
    12 #include<map>  
    13 #include<set>  
    14 using namespace std;  
    15 typedef long long int64;  
    16 //typedef __int64 int64;  
    17 typedef pair<int64,int64> PII;  
    18 #define MP(a,b) make_pair((a),(b))   
    19 const double inf =  9999999999.0;  
    20 const double inf2 = 1.0*(1e8);
    21 const double pi=acos(-1.0);  
    22 const int dx[]={1,-1,0,0};  
    23 const int dy[]={0,0,1,-1};  
    24 const double eps = 1e-8;  
    25 const int maxm = 1005;  
    26 const int maxn = 305;  
    27 
    28 struct NODE{
    29     double t,d;
    30 }mat[ maxn ][ maxn ];
    31 struct Point{
    32     double x,y;
    33     double vx,vy;
    34 }pnt[ maxn ];
    35 
    36 double solve( double t,int n ){
    37     double dis = 0;
    38     for( int i=0;i<n;i++ ){
    39         for( int j=i+1;j<n;j++ ){
    40             dis = max( dis, (pnt[i].x-pnt[j].x+pnt[i].vx*t-pnt[j].vx*t)*(pnt[i].x-pnt[j].x+pnt[i].vx*t-pnt[j].vx*t)+(pnt[i].y-pnt[j].y+pnt[i].vy*t-pnt[j].vy*t)*(pnt[i].y-pnt[j].y+pnt[i].vy*t-pnt[j].vy*t) );
    41         }
    42     }
    43     return sqrt(dis);
    44 }
    45 
    46 int main(){
    47     int T;
    48     int ca = 1;
    49     scanf("%d",&T);
    50     while( T-- ){
    51         int n;
    52         scanf("%d",&n);
    53         for( int i=0;i<n;i++ ){
    54             scanf("%lf%lf%lf%lf",&pnt[ i ].x,&pnt[ i ].y,&pnt[ i ].vx,&pnt[ i ].vy);
    55         }
    56         double L = 0;
    57         double R = inf2;
    58         double ans_d = inf;
    59         double ans_t = inf;
    60         while( L+eps<R ){
    61             double mid1 = ( L+R )/2.0;
    62             double mid2 = ( mid1+R )/2.0;
    63             double d1 = solve( mid1,n );
    64             double d2 = solve( mid2,n );
    65             if( d1<=d2 ) {
    66                 if( d1<ans_d ){
    67                     ans_t = mid1 ;
    68                     ans_d = d1;
    69                 }
    70                 else if( d1==ans_d )
    71                     ans_t = min( ans_t,mid1 );
    72                 R = mid2;
    73             }
    74             else {
    75                 if( d2<ans_d ){
    76                     ans_t = mid2 ;
    77                     ans_d = d2;
    78                 }
    79                 else if( d2==ans_d )
    80                     ans_t = min( ans_t,mid2 );
    81                 L = mid1;
    82             }
    83             //printf("L = %lf,R = %lf
    ",L,R);
    84         }
    85         printf("Case #%d: %.2lf %.2lf
    ",ca++,ans_t,ans_d);
    86     }
    87     return 0;
    88 }
    View Code
  • 相关阅读:
    Java 中的 TreeSet
    自定义全局异常处理器(Java)
    GitHub Open Feign 使用总结
    搭建 Maven 仓库
    MySQL 的 SQL 笔记
    一道算法题:查找数组 arr 中第 k 小的奇数
    Java 的参数传递
    接口限流的几种算法
    Java 实现一个自定义分布式 Session
    函数反汇编
  • 原文地址:https://www.cnblogs.com/xxx0624/p/3456540.html
Copyright © 2011-2022 走看看