码迷,mamicode.com
首页 > 其他好文 > 详细

HNU13033Football (贪心)

时间:2014-10-02 18:18:43      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   io   os   ar   for   strong   sp   

Football
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 19, Accepted users: 17
Problem 13033 : No special judgement
Problem description
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 losing team. If the game is drawn, each team receives one point.
Your team played N matches during the first phase of the tournament, which has just finished. Only some teams, the ones with more accumulated points, will advance to the second phase of the tournament. However, as the main objective of the tournament is to raise money, before the set of teams that will pass to the second phase is determined, each team is allowed to buy additional goals. These new goals count as normally scored goals, and may be used to alter the result of any of the matches the team played.
Your team‘s budget is enough to buy up to G goals. Can you tell the maximum total number of points your team can get after buying the goals, supposing the other teams will not buy any goals?
Input
The first line contains two integers N (1 ≤ N ≤ 105) and G (0 ≤ G ≤ 106) representing respectively the number of matches your team played and the number of goals your team can buy. Each of the next N lines describes a match result with two integers S and R (0 ≤ S;R ≤ 100), indicating respectively the goals your team scored and received on that match before buying goals.
Output
For each test case, output a line with an integer representing the maximum total number of points your team can get after buying the goals.
Sample Input
Sample input 1
2 1
1 1
1 1

Sample input 2
3 2
1 3
3 1
2 2

Sample input 3
4 10
1 1
2 2
1 3
0 4
Sample Output
Sample output 1
4

Sample output 2
6

Sample output 3
12
Problem Source

ICPC Latin American Regional 2013

题意:给出N场比赛的每场比分s:r, s是本队得分,从开始手里有G个比分,可以分给每一场比分,赢了则加3个点,平局加1个点。输了得0个点。再问最多能得多少个点。

#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
bool cmp(int a,int b){return a>b;}
int main()
{
    int sum,N,G,sub[100005],s,r,k,m,ss;
    while(scanf("%d%d",&N,&G)>0)
    {
        sum=0;k=0;m=0; ss=0;
        for(int i=0;i<N;i++)
        {
            scanf("%d%d",&s,&r);
           if(s-r<0) sub[k++]=s-r;
           else if(s-r==0)m++;
           else ss+=3;
        }
        
        sort(sub,sub+k,cmp);
        for(int j=0;j<=m&&j<=G;j++)
        {
            int s=m-j+j*3+ss,g=G-j;
            for(int i=0;i<k;i++)
            if(-sub[i]<g)
            {
                g+=sub[i]-1;s+=3;
            }
            else if(-sub[i]==g)
            g+=sub[i],s++;
            else break;
            if(s>sum)sum=s;
        }
        printf("%d\n",sum);
    }
}


HNU13033Football (贪心)

标签:des   style   color   io   os   ar   for   strong   sp   

原文地址:http://blog.csdn.net/u010372095/article/details/39737245

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!