zoukankan      html  css  js  c++  java
  • hdu 4932 BestCoder Round #4 1002

    这题真是丧心病狂,引来今天的hack狂潮~

    Miaomiao's Geometry

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 10    Accepted Submission(s): 3

    Problem Description
    There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length.
    There are 2 limits:
    1.A point is convered if there is a segments T , the point is the left end or the right end of T. 2.The length of the intersection of any two segments equals zero.
    For example , point 2 is convered by [2 , 4] and not convered by [1 , 3]. [1 , 2] and [2 , 3] are legal segments , [1 , 2] and [3 , 4] are legal segments , but [1 , 3] and [2 , 4] are not (the length of intersection doesn't equals zero), [1 , 3] and [3 , 4] are not(not the same length).
    Miaomiao wants to maximum the length of segements , please tell her the maximum length of segments.
    For your information , the point can't coincidently at the same position.
     
    Input
    There are several test cases. There is a number T ( T <= 50 ) on the first line which shows the number of test cases. For each test cases , there is a number N ( 3 <= N <= 50 ) on the first line. On the second line , there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
     
    Output
    For each test cases , output a real number shows the answser. Please output three digit after the decimal point.
     
    Sample Input
    3 3 1 2 3 3 1 2 4 4 1 9 100 10
     
    Sample Output
    1.000 2.000 8.000
    Hint
    For the first sample , a legal answer is [1,2] [2,3] so the length is 1. For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2. For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8.
     
    正解还在讨论中,不过有多种,,,被hack掉的。。
    后来发现正解是暴力,暴力中的暴力。。。
    枚举所有两点之间距离以及距离的一半,然后贪心的放。
    对于A[i],能往左放就往左,不行就往右。往右也放不了,就不行了,判断下一个长度。
     
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<vector>
     7 #include<map>
     8 #include<string>
     9 #include<cmath>
    10 #include<queue>
    11 #define N 1005
    12 #define MAXN 1000005
    13 #define M 200
    14 #define mod 1000000007
    15 #define ll long long
    16 using namespace std;
    17 
    18 int n,m;
    19 int T;
    20 ll a[N],b[N];
    21 ll te;
    22 ll ans;
    23 
    24 bool cmp(ll x,ll y)
    25 {
    26     return x>y;
    27 }
    28 
    29 int isok(ll v)
    30 {
    31     ll now=0;
    32     for(int i=2;i<=n-1;i++){
    33        // printf(" %I64d %I64d %I64d now=%I64d v=%I64d
    ",a[i+1],a[i],a[i-1],now,v);
    34        // printf(" %d
    ",(a[i]-a[i-1]-now) <=v);
    35         if( (a[i]-a[i-1]-now) >=v){
    36             now=0;
    37         }
    38         else{
    39             if( (a[i+1]-a[i]) ==v){
    40                 now=0;
    41                 i++;
    42             }
    43             else if( (a[i+1]-a[i]) >v){
    44                 now=v;
    45             }
    46             else return 0;
    47         }
    48     }
    49     return 1;
    50 }
    51 
    52 int main()
    53 {
    54     int i,j,k;
    55     //freopen("data.txt","r",stdin);
    56     scanf("%d",&T);
    57     //while(scanf("%d",&n)!=EOF)
    58     while(T--)
    59    // for(cnt=1;cnt<=T;cnt++)
    60     {
    61        scanf("%d",&n);
    62        m=0;
    63        for(i=1;i<=n;i++){
    64             scanf("%I64d",&a[i]);
    65             a[i]*=4;
    66        }
    67        sort(a+1,a+1+n);
    68        //for(i=1;i<=n;i++)printf(" %I64d
    ",a[i]);
    69        for(i=1;i<n;i++){
    70             te=a[i+1]-a[i];
    71             b[m]=te;m++;
    72             te/=2;
    73             b[m]=te;m++;
    74        }
    75        sort(b,b+m,cmp);
    76        //for(i=0;i<m;i++)printf(" %I64d
    ",b[i]);
    77        for(j=0;j<m;j++){
    78             if(isok(b[j])==1){
    79                 printf("%.3f
    ",(double)b[j]/4);
    80                 break;
    81             }
    82        }
    83 
    84     }
    85 
    86     return 0;
    87 }
  • 相关阅读:
    IE7下图片缩放失真可用-Ms-Interpolation-Mode解决
    Chrome 设置12px以下的字体-好像新版已经不支持了
    豆瓣底部的点排版
    认识伪类元素:before和:after
    CSS3 Media Queries
    CSS3 为不同媒介设置样式的方法(CSS3 Media Queries)(转)
    CSS3 Transform的perspective属性
    CSS3 Animation Keyframes关键帧
    .Net 逆向 Reflector之reflexil使用
    内网穿透(NAT),太牛...
  • 原文地址:https://www.cnblogs.com/njczy2010/p/3903396.html
Copyright © 2011-2022 走看看