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;
		for(int i = 0, x, y; i < n; i ++) {
			scanf("%d%d", &x, &y);
			if(x > y) sum += 3;
			else if(x == y) {
				cnt ++;
				sum ++;
			} else s.push_back(y-x);
		}

		if(k >= cnt) {
			sum += 2*cnt;
			k -= cnt;
		} else {
			sum += 2*k;
			k = 0;
		}
		sort(s.begin(), s.end());
		for(int i = 0; i < s.size() && k > 0; i ++) {
			if(k > s[i]) {
				sum += 3;
				k -= s[i]+1;
			} else if(k == s[i]) {
				sum += 1;
				k -= s[i];
			}
		}
		printf("%d\n", sum);
	}

	return 0;
}
时间: 2024-12-21 19:32:46

UVALive 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 7454 Parentheses (水题,贪心)

题意:给定一个括号序列,改最少的括号,使得所有的括号匹配. 析:贪心,从左到右扫一下,然后统计一下左括号和右括号的数量,然后在统计中,如果有多了的右括号,那么就改成左括号,最后如果两括号数量不相等, 就改一下. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #inc

LA UVaLive 6628 Grachten (水题,数学)

题意:给定一个平面图形并且且给了几条连,求一条. 析:简单么,三角形相似,很简单就AC. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cst

LA 6530 Football 贪心

题意:给出一系列比赛和结果,可以花钱买任意一场比赛或几场比赛的进球,问买完后最多能得多少分.胜3分,平1分,负0分. 思路:贪心.策略:1.赢的直接+3  2.其他的按净胜球升序排序,能买赢就买赢,不然买平.详见代码: /********************************************************* file name: LA6530.cpp author : kereo create time: 2015年02月06日 星期五 22时54分16秒 *****

LA UVaLive 7371 Triangle (水题,判矩形)

题意:给定两个三角形,问你能不能拼成矩形. 析:很明显,要想是矩形,必须是四个角是直角,那么三角形必须是直角三角形,然后就是只能斜边相对,然后呢?就没了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <functional> #include <cstdlib> #inc

LA UVaLive 7372 Excellence (水题,贪心)

题意:给定 n 个数,要求把其中两个分成一组,然后加和,问所有的都分好,最小数是几. 析:贪心策略,最大和是小的相加,就是最优的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <functional> #include <cstdlib> #include <cma

LA UVaLive 6855 Banks (水题,暴力)

题意:给定 n 个数,让你求最少经过几次操作,把所有的数变成非负数,操作只有一种,变一个负数变成相反数,但是要把左右两边的数加上这个数. 析:由于看他们AC了,时间这么短,就暴力了一下,就AC了.....并不明白 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #in

2015暑假训练赛个人赛(8.5)

  ID Origin Title   96 / 114 Problem A UVALive 4167 Parity  水题1 60 / 124 Problem B UVALive 4168 Lampyridae Teleportae  水题3 3 / 11 Problem C UVALive 4169 Hex Tile Equations   17 / 41 Problem D UVALive 4170 The Bridges of San Mochti   16 / 36 Problem E

UVaLive 6591 &amp;&amp; Gym 100299L Bus (水题)

题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set>