LA 6530 Football 贪心

题意:给出一系列比赛和结果,可以花钱买任意一场比赛或几场比赛的进球,问买完后最多能得多少分。胜3分,平1分,负0分。

思路:贪心。策略:1.赢的直接+3  2.其他的按净胜球升序排序,能买赢就买赢,不然买平。详见代码:

/*********************************************************
  file name: LA6530.cpp
  author : kereo
  create time:  2015年02月06日 星期五 22时54分16秒
*********************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int sigma_size=26;
const int N=100+50;
const int MAXN=100000+50;
const int inf=0x3fffffff;
const double eps=1e-8;
const int mod=100000000+7;
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define PII pair<int, int>
#define mk(x,y) make_pair((x),(y))
int n,m;
int a[MAXN];
int main(){
    while(~scanf("%d%d",&n,&m)){
        int ans=0,cnt=0;
        for(int i=1;i<=n;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            if(x>y)
                ans+=3;
            else
                a[cnt++]=y-x;
        }
        sort(a,a+cnt);
        int k=0;
        while(m && k<cnt){
            if(m>=a[k]+1){
                m-=a[k]+1;
                ans+=3;
                k++;
            }
            else if(m>=a[k]){
                m-=a[k];
                ans++;
                k++;
            }
            else
                break;
        }
        for(int i=k;i<cnt;i++)
            if(a[i] == 0)
                ans++;
        printf("%d\n",ans);
    }
	return 0;
}
时间: 2024-08-24 11:08:25

LA 6530 Football 贪心的相关文章

【贪心】UVALive 6530——Football

Your favorite football team is playing a charity tournament, which is part of a worldwide fundraising e ort to help children with disabilities. As in a normal tournament, three points are awarded to the team winning a match, with no points to the los

UVALive 6530 Football (水

题目链接:点击打开链 #include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef long long ll; vector<int> s; int main() { int n, k; while (~scanf("%d%d", &n, &k)) { s.clear(); int sum = 0, cnt = 0

LA 4945 Free Goodies(贪心)

Description B  Free Goodies Petra and Jan have just received a box full of free goodies, and want to divide the goodies between them. However, it is not easy to do this fairly, since they both value different goodies differently. To divide the goodie

UVA LA 7146 2014上海亚洲赛(贪心)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosmsg=Submission+received+with+ID+1708713 /** UVA LA 7146 2014上海亚洲赛(贪心) 题目大意:给定敌我双方士兵的数量和每个士兵的攻击力和防守力,如果两个士兵对战,一方

LA 3266 Tian Ji -- The Horse Racing 田忌赛马 【贪心】

题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33702 贪心: 1,如果田忌的最快马快于齐王的最快马,则两者比. (因为若是田忌的别的马很可能就赢不了了,所以两者比) 2,如果田忌的最快马慢于齐王的最快马,则用田忌的最慢马和齐王的最快马比. (由于所有的马都赢不了齐王的最快马,所以用损失最小的,拿最慢的和他比) 3,若相等,则比较田忌的最慢马和齐王的最慢马 3.1,若田忌最慢马快于齐王最慢马,两者比. (田忌

LA 4254 Processor 处理器 【二分 贪心 优先队列】

题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21663 二分: 最大值最小的问题通过二分来求解.对处理器速度进行二分之后,问题就转化成了对于给定的处理速度,问处理器是否可以将这些问题处理完. 贪心: 一个贪心的思路就是每个时刻应该尽量 做可以做的任务中,结束时间最早的那个,这样最起码不会使结果更糟.这样就可以枚举每个单位时间,然后去找可以做的并且结束时间最早的那个去做,直到用完这一单位时间或者无任务可做为止.

湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心

2007: Football Training Camp[原创-转载请说明] Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 228     Solved: 30 Description 在一次足球联合训练中一共有n支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为平局则两支队伍各得1分. Input 输入包含不超过1000组数据. 每组数据的第

LA 6979 Known Notation 构造+贪心 铜牌题

6979 Known NotationDo you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics andcomputer science. It is also known as postfix notation since every operator in an expression follows allof its operands. Bob is a stude

LA 3266 (贪心) Tian Ji -- The Horse Racing

题意: 田忌和齐王各有n匹马,如果马的速度比齐王的快就赢200,慢则输200,相等不赔不赚. 已知两人每匹马的速度(为整数)和齐王所排出的马的顺序,问田忌该如何应对才能使收益最大. 分析: 本以为是一道很简单的贪心,上来就贪,结果什么都没贪出来. 看了题解才发现贪心是比较复杂的. 这里贴上poj某牛的神分析. 贪心策略: 1,如果田忌的最快马快于齐王的最快马,则两者比. (因为若是田忌的别的马很可能就赢不了了,所以两者比) 2,如果田忌的最快马慢于齐王的最快马,则用田忌的最慢马和齐王的最快马比.