zoukankan      html  css  js  c++  java
  • HDU 4393 Throw nails [水题]

      题解写了N多方法,我用的是最水的那种。。

      起始区间只有(0 <= Fi <= 500),500秒之后排名必然不会变化了。。所以,暴力500秒,然后排个序就行了。

      

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 #define MAXN 50010
     5 struct stt{
     6     int s,t,v,id;
     7     bool operator <(const stt& st)const{
     8         return t>st.t||(t==st.t&&s>st.s)
     9         ||(t==st.t&&s==st.s&&id<st.id);
    10     }
    11 }st[MAXN];
    12 int cas,n;
    13 int main(){
    14     //freopen("test.in","r",stdin);
    15     scanf("%d",&cas);
    16     for(int ca=1;ca<=cas;ca++){
    17         scanf("%d",&n);
    18         for(int i=0;i<n;i++){
    19             scanf("%d%d",&st[i].s,&st[i].t);
    20             st[i].v=0,st[i].id=i+1;
    21         }
    22         printf("Case #%d:\n",ca);
    23         for(int i=0;i<510&&i<n;i++){
    24             int minid=-1;
    25             for(int j=0;j<n;j++){
    26                 if(st[j].v==0&&(minid==-1||st[j].s+st[j].t*i>st[minid].s+st[minid].t*i))
    27                     minid=j;
    28             }
    29             if(i!=0)printf(" ");
    30             printf("%d",st[minid].id);
    31             st[minid].v=1;
    32         }
    33         std::sort(st,st+n);
    34         for(int i=0;i<n;i++){
    35             if(!st[i].v)printf(" %d",st[i].id);
    36         }
    37         printf("\n");
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    Greedy Gift Givers 贪婪的送礼者
    USACO 1.1.3 Friday the Thirteenth 黑色星期五
    Prime Matrix(暴力出奇迹)
    博弈论
    好车牌
    C语言中动态内存的分配(malloc,realloc)
    Saruman's Army(贪心)
    Python练习——循环2
    Fox and Number Game
    Repair the Wall (贪心)
  • 原文地址:https://www.cnblogs.com/swm8023/p/2698811.html
Copyright © 2011-2022 走看看