我是靠谱客的博主 儒雅春天,这篇文章主要介绍贪心 No Time for Dragons Gym - 101149B,现在分享给大家,希望可以做个参考。

国王要杀死n条龙,杀死每条龙需要a人,会战死b人,问杀死n条龙至少需要多少人。

因为杀死每条龙需要的人是一定的且战死的人是一定的,所以先杀战死的人最少的龙。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 200005 using namespace std; typedef struct { int x,y; }Point; Point a[maxn]; int cmp(Point b,Point c) { return b.y> c.y; } int main() { long long ans=0; int n; cin>>n; for(int i=1;i<=n;i++) { int x1,y1; cin>>x1>>y1; a[i].x=x1,a[i].y=x1-y1; } sort(a+1,a+n+1,cmp); ans+=a[1].x; for(int i=2;i<=n;i++) { if(a[i].x>a[i-1].y) ans+=(a[i].x-a[i-1].y); else a[i].y+=(a[i-1].y-a[i].x); } cout<<ans<<endl; }

 

转载于:https://www.cnblogs.com/Twsc/p/7253851.html

最后

以上就是儒雅春天最近收集整理的关于贪心 No Time for Dragons Gym - 101149B的全部内容,更多相关贪心内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部