UVA - 11389(贪心)
来源:互联网 发布:网络平台推广好做吗 编辑:程序博客网 时间:2024/06/03 21:02
很好证明啊,直接用最大的和一个最小的相加
因为这样总不会丢失最优解,用交换证明法即可,
若夜间最大的并未和白天最小的在一起,那么与和白天最小的在一起的夜间班相交换,不会丢失最优解,
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <cmath>#include <map>#include <set>#include <cctype>#include <deque>using namespace std;typedef long long LL;#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)#define rep1(i,n) for(int (i)=1;(i)<=(n);(i)++)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int cmp(int a,int b){ return a<b;}int cmp2(int a,int b){ return a>b;}const int maxn = 110;int n,d,r,a[maxn],b[maxn];int main(){ while(scanf("%d %d %d",&n,&d,&r)==3 && n){ rep(i,n) scanf("%d",&a[i]); rep(i,n) scanf("%d",&b[i]); sort(a,a+n,cmp); sort(b,b+n,cmp2); int res =0; for(int i=0;i<n;i++){ res+= (a[i]+b[i] > d ? a[i]+b[i]-d:0); } printf("%d\n",res*r); } return 0;}
0 0
- uva 11389(贪心)
- UVA - 11389(贪心)
- uva 11389 贪心
- UVA 11389 - The Bus Driver Problem (贪心)
- UVA - 11389 The Bus Driver Problem 贪心
- UVA 11389 The Bus Driver Problem(贪心)
- Uva 11100(贪心)
- uva 1388 - Graveyard(贪心)
- UVA 10037 - Bridge(贪心)
- uva 10037 - Bridge(贪心)
- Uva 10382 贪心
- UVa:10148 Advertisement(贪心)
- Commando War-uva 贪心
- UVA 10714 蚂蚁贪心
- uva 11292 贪心
- File Fragmentation+uva+贪心
- Add All +uva+贪心
- Bit Mask uva+贪心
- Spark知识系统化整理分享
- 第五周项目四 -静态成员应用 由老师版本的完善版
- 【J2EE】快速搭建 Spring MVC 开发框架(一)
- [LeetCode][Database]Duplicate Emails
- java,web学习之MVC模式的搭建。
- UVA - 11389(贪心)
- 数据库笔记--三层模型
- 常用的 DOCTYPE 声明有哪些?
- presentModalViewController的使用
- Leetcode---Unique Binary Search Trees II
- jQuery ajax提交
- uml
- 原android 涂鸦(清屏,画笔,粗细,保存)以及canvas源码学习
- 网络编程-listen函数