zoukankan      html  css  js  c++  java
  • POJ 1852 Ants

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #define sc(x) scanf("%d",&(x))
     6 #define sc2(x,y) scanf("%d%d", &(x), &(y))
     7 #define pf(x) printf("%d
    ", x)
     8 #define pf2(x, y) printf("%d %d
    ", x, y)
     9 #define FOR(i,b,e) for(i=b; i<=e; i++)
    10 #define CL(x,y) memset(x,y,sizeof(x))
    11 const int MAX = 1000000;
    12 int ant[MAX], Min[MAX];
    13 using namespace std;
    14 int main(int argc, char *argv[]) {
    15     int T, L, n, i, k, max;
    16     sc(T);
    17     while(T--){
    18         max = 0; k = 0;
    19         CL(Min, 0);
    20         sc2(L, n);
    21         FOR(i, 0, n-1) sc(ant[i]);
    22         sort(ant, ant+n);
    23         max = ant[n-1] > (L-ant[0]) ? ant[n-1] : (L-ant[0]);
    24         FOR(i, 0, n-1){
    25             if(ant[i] <= L/2){
    26                 Min[k++] = ant[i];
    27             }
    28             else{
    29                 Min[k++] = L- ant[i];
    30             }
    31         }
    32         sort(Min, Min+k);
    33         pf2(Min[k-1], max); 
    34     }    
    35     return 0;
    36 }
    View Code
    /*
    1.最快:找出最靠近中间的点,它走到离它最近的端点的时间就是全部蚂蚁掉下去的时间
    
    2.最慢:对于每个点,找出它到两个端点的最远距离就是全部蚂蚁掉下去的时间
    */
  • 相关阅读:
    C#随机数的使用
    英才评测 个人性格倾向 IT知识
    有点迷茫
    [转帖]2006年it人士必去的10个网站
    ASP.NET 中 Cookie 的基本知识
    Http请求方法
    Spherical Mercator
    Axure快速原型设计
    【转】Spring Insight 使用介绍
    DB2执行sql文件
  • 原文地址:https://www.cnblogs.com/ghostTao/p/4383780.html
Copyright © 2011-2022 走看看