zoukankan      html  css  js  c++  java
  • UVa 11729 Commando War

      也是很直接的一道题,排序比较,无语的是又WA了一次,原因是输出格式"Case X: Y“我没看多输了个#号,好粗心啊。。。

      代码如下:

    View Code
     1 #include <cstdio>
     2 #include <algorithm>
     3 using namespace std;
     4 
     5 const int maxn = 1000+10;
     6 
     7 struct Soldier
     8 {
     9     int b,j;
    10     bool operator < (const Soldier& a) const{
    11         return j > a.j;
    12     }
    13 } s[maxn];
    14 
    15 int main()
    16 {
    17 #ifdef LOCAL
    18     freopen("in", "r", stdin);
    19 #endif
    20     int n, kase = 0;
    21     while(scanf("%d", &n) != EOF && n)
    22     {
    23         kase++;
    24         for(int i = 0; i < n; i++)
    25             scanf("%d%d", &s[i].b, &s[i].j);
    26         sort(s, s+n);
    27         int t, max;
    28         t = max = 0;
    29         for(int i = 0; i < n; i++)
    30         {
    31             t += s[i].b;
    32             if(t + s[i].j > max)   max = t+s[i].j;
    33         }
    34         printf("Case %d: %d\n", kase, max);
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    A+B Problem
    迭代平方根
    猴子报数
    分数求和
    猴子吃桃
    钻石
    杨辉三角形
    MYSQL 5.7 修改密码、登录问题
    SQL 语句 explain 分析
    重构CMDB,避免运维之耻
  • 原文地址:https://www.cnblogs.com/xiaobaibuhei/p/2986870.html
Copyright © 2011-2022 走看看