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 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 (贪心)
时间: 2024-10-11 06:18:10
HNU13033Football (贪心)的相关文章
【uva 1615】Highway(算法效率--贪心 区间选点问题)
题意:给定平面上N个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个店,都有一个选出的点离它的欧几里德距离不超过D. 解法:先把问题转换成模型,把对平面的点满足条件的点在x轴的直线上可得到一个个区间,这样就是选最小的点覆盖所有的区间的问题了.我之前的一篇博文有较详细的解释:关于贪心算法的经典问题(算法效率 or 动态规划).代码实现我先空着.挖坑~
【贪心+Treap】BZOJ1691-[Usaco2007 Dec]挑剔的美食家
[题目大意] 有n头奶牛m种牧草,每种牧草有它的价格和鲜嫩度.每头奶牛要求它的牧草的鲜嫩度要不低于一个值,价格也不低于一个值.每种牧草只会被一头牛选择.问最少要多少钱? [思路] 显然的贪心,把奶牛和牧草都按照鲜嫩度由大到小排序,对于每奶牛把鲜嫩度大于它的都扔进treap,然后找出后继. 不过注意后继的概念是大于它且最小的,然而我们这里是可以等于的,所以应该是找cow[i].fresh-1的后继,注意一下…… 1 #include<iostream> 2 #include<cstdio&
POJ1017 Packets(贪心算法训练)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 51306 Accepted: 17391 Description A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These pro
ZOJ 3946 Highway Project 贪心+最短路
题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题解: 用dijkstra跑单元最短路径,如果对于顶点v,存在一系列边(ui,v)使得dis[v]最小(dis[v]表示0到v的距离).这些边能且只能选一条,那么我们自然应该选cost最小的那个边了. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #inc
CoderForce 140C-New Year Snowmen(贪心)
题目大意:有n个已知半径的雪球.堆一个雪人需要三个尺寸不同的雪球,问用这些雪球最多能堆多少个雪人? 题目分析:先统计一下每种尺寸的球的个数,从三种最多的种类中各取出一个堆成雪人,这样贪心能保证的到的数目最多. 代码如下: # include<iostream> # include<map> # include<vector> # include<cstdio> # include<queue> # include<algorithm>
计蒜客 跳跃游戏(贪心)
给定一个非负整数数组,假定你的初始位置为数组第一个下标.数组中的每个元素代表你在那个位置能够跳跃的最大长度. 请确认你是否能够跳跃到数组的最后一个下标. 例如: A = [2,3,1,1,4], return ture A = [3,2,1,0,4], return false. 格式: 第一行输入一个正整数n,接下来的一行,输入数组A[n].如果能跳到最后一个下标,输出"true",否则输出"false" 样例1 ????输入:???? ????????5 ???
BZOJ 2525 [Poi2011]Dynamite 二分+树形贪心
题意: n个点,一棵树,有些点是关键点,可以将m个点染色. 求所有关键点到最近的被染色点的距离的最大值最小. 解析: 反正从这道题我是学了一种做题思路? 大爷讲课的时候说的:一般选择某些点的代价相同的话都是贪心,代价不同的话一般都是DP. 想想也挺对的,不过就是没有感悟到过? 反正这题考试的时候我是直接D了贪心的- -! 忘了为啥D了. 显然最大值最小我们需要二分一下这个值. 然后接下来我们从下往上扫整棵树. 节点的状态有几个? 第一种是 子树内没有不被覆盖的关键点,并且子树中有一个节点的贡献可
CF 500 C. New Year Book Reading 贪心 简单题
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi. As Jaehyun's house is not large enough to have a bookshelf, he k
贪心 --- HNU 13320 Please, go first
Please, go first Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13320 Mean: n个人一起去滑雪,要坐电梯到山顶,电梯每5分钟可以送一个人上去.这n个人中有的是组好团一起滑雪的,所以要等到齐了才能开始滑. 但是他们到达电梯下的时间都不是统一的,对于单独一个人来说,他在山下等和在山上等的时间都是一样的. 但是对于n个人的集体来说,如果让他后面的人先上去,这样可能会更节省时间.