Sicily 13983. Milk Scheduling

13983. Milk Scheduling

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk.

Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow i produces g_i gallons of milk (1 <= g_i <= 1000), but only if she is milked before a deadline at time d_i (1 <= d_i <= 10,000). Time
starts at t=0, so at most x total cows can be milked prior to a deadline at time t=x.

Please help Farmer John determine the maximum amount of milk that he can obtain if he milks the cows optimally.

Input

* Line 1: The value of N.

* Lines 2..1+N: Line i+1 contains the integers g_i and d_i.

Output

* Line 1: The maximum number of gallons of milk Farmer John can obtain.

Sample Input

4
10 3
7 5
8 1
2 1

Sample Output

25

Hint

In the sample, there are 4 cows. The first produces 10 gallons of milk if milked by time 3, and so on. Farmer John milks cow 3 first, giving up on cow 4 since she cannot be milked by her deadline due to the conflict with cow 3. Farmer John then milks cows 1
and 2.

Problem Source

2015年每周一赛第六场

按照g大优先、d小优先排序,对于一个奶牛,优先放到尽量靠近d的时间点,这样尽可能的延后,给了其他的奶牛充分的时间……

#include <iostream>
#include <algorithm>
using namespace std;

struct cow {
	int g, d;
	cow(int g = 0, int d = 0) {
		this->g = g;
		this->d = d;
	}
};

bool cmp(const cow & c1, const cow & c2) {
	if (c1.g == c2.g) return c1.d < c2.d;
	else return c1.g > c2.g;
}

cow c[10005];
bool used[10005];

int haveTime(int d) {
	for (int i = d; i > 0; i--) if (!used[i]) return i;
	return 0;
}

int main() {
	std::ios::sync_with_stdio(false);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> c[i].g >> c[i].d;
	sort(c, c + n, cmp);
	int t = 4, ans = 0;
	for (int i = 0; i < n; i++) {
		int feedDay = haveTime(c[i].d);
		if (feedDay) {
			used[feedDay] = true;
			ans += c[i].g;
		}
	}
	cout << ans << endl;

	return 0;
}
时间: 2024-11-05 13:53:08

Sicily 13983. Milk Scheduling的相关文章

洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling

题目描述 Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow

P3093 [USACO13DEC]牛奶调度Milk Scheduling——贪心

其实可以用dp   f[j]表示到j时间最大的收益 #include<bits/stdc++.h>using namespace std;int n,f[100000];struct node{ int d,g;}a[1000000];bool cmp(node a,node b){ return a.d<b.d;}int main(){ cin>>n; for(int i=1;i<=n;i++) { cin>>a[i].g>>a[i].d; }

P3093 [USACO13DEC]牛奶调度Milk Scheduling - 贪心+二叉堆

传送门 思路:一个贪心策略就是"在不挤超过截至时间的奶牛的前提下,尽量挤奶量大的奶牛".So我们将奶牛按截至日期从小到大排序,对于每个截至时间t,将所有截至时间为t的奶牛的奶量加入一个大根堆,只留下前t大的数,剩下的直接删去.由于priority_queue没有clear函数,所以我手写了一个堆...(请不要问我为什么不用小根堆,每次弹出前size()-t个数,但这样做会WA得很惨...) AC Code:(代码略鬼畜,但我觉得应该没多少人看我这博客吧..) #include<c

Milk Scheduling

题面: 思路: 代码: uses math; var ans,n,m,tot,x,y,i,j:longint; next,last,tail:array[0..100005] of longint; t,c,d:array[0..10005] of longint; f:Array[0..10005] of boolean; procedure add(x,y:longint); begin inc(tot); next[tot]:=y; last[tot]:=tail[x]; tail[x]:

中大周赛15年第6场

13983. Milk Scheduling Constraints Time Limit: 1 secs, Memory Limit: 256 MB Description Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refu

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

BZOJ-USACO被虐记

bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 3889: [Usaco2015 Jan]Cow Routing 双键值最短路,预处理出代价跑一遍最短路就可以. ★3890: [Usaco2015 Jan]Meeting Time 维护一个小根堆,把边不断地插进去,然后维护一个ans,如果说ans>q.top().t且两个边权都走到n的话,就直接输出答案.否则答案只可能比当前答案还要大. 3891: [Usaco2014 Dec]Piggy Back 做3遍最短路,然

Milk(杭电1070)

Milk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13983    Accepted Submission(s): 3447 Problem Description Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose

[BZOJ1717][Usaco2006 Dec]Milk Patterns 产奶的模式

1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1297  Solved: 705 [Submit][Status][Discuss] Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠.我们称之为一个"模式". John的牛奶按质量可以被赋予一个0到100