• Uva11729 Commando War


    相邻两个士兵交换顺序,不会对其他的有所影响,贪心考虑两两之间交换策略即可。

    sort大法好。印象中这类排序题里有一种会卡sort,只能冒泡排序,然而到现在还没有遇到

     1 /**/
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 struct node{
     8     int b;
     9     int j;
    10 };
    11 int cmp(const node a,const node b){
    12     return a.j>b.j;
    13 }
    14 int main(){
    15     int n,b,j;
    16     int case_count=1;
    17     while(scanf("%d",&n)!=EOF &&n){
    18         struct node sod[10500];
    19         int i;
    20         for(i=1;i<=n;i++)
    21             scanf("%d%d",&sod[i].b,&sod[i].j);
    22         sort(sod+1,sod+n+1,cmp);
    23         int s=0;
    24         int ans=0;
    25         for(i=1;i<=n;i++){
    26             s+=sod[i].b;
    27             ans=max(ans,s+sod[i].j);
    28             }
    29         printf("Case %d: %d
    ",case_count++,ans);    
    30     }    
    31     
    32     return 0;
    33     
    34 }
  • 相关阅读:
    Centos6.8通过yum安装mysql5.7
    查看mysql已安装
    canal client leader
    es按时间段统计总数
    nginx负载
    es 查看mapping 设置max_result_window
    es 修改默认bool条件个数
    less
    Less配置环境
    JavaScript面向对象与原型
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6039040.html
Copyright © 2020-2023  润新知