HDU 3420 Bus Fair(贪心)
来源:互联网 发布:手机频谱软件 编辑:程序博客网 时间:2024/05/17 22:30
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3420
题意:这是一辆神奇的公交,每次只检查你身上带的钱够不,你的钱不够乘车时你就必须下车,你的钱够乘车时你就可以继续乘车,且不用付车钱,走第一个公里的钱是1人1元,第二公里的钱是1人2元,依次类推,问最少花多少钱就能让你的朋友都乘上车
思路:刚开始就全部上车,求出阶段中的最大值即可
AC代码:
暴力每个阶段,比较费时
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long ll;const int maxn = 100010;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int a[1010];int main(){ int n; while(scanf("%d",&n) != EOF) { for(int i=1; i<=n; i++) scanf("%d",&a[i]); int max1 = 0; sort(a+1,a+n+1); for(int i=1; i<=a[n]; i++) { int sum = 0; for(int j=1; j<=n; j++) { if(a[j] >= i) sum++; } int l = sum * i; max1 = max(max1,l); } printf("%d\n",max1); } return 0;}暴力每个人下车的阶段,这一定是上一个人下车之后的最大值
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long ll;const int maxn = 100010;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int a[1010];int main(){ int n; while(scanf("%d",&n) != EOF) { for(int i=1; i<=n; i++) scanf("%d",&a[i]); int max1 = 0; sort(a+1,a+n+1); for(int i=1; i<=n ;i++) { max1 = max(max1,a[i] * (n-i+1)); } printf("%d\n",max1); } return 0;}
0 0
- HDU 3420 Bus Fair(贪心)
- hdu 3420 Bus Fair
- hdu 3420 Bus Fair
- HDU:3420 Bus Fair, 3090 Go Home+uva:11729 Commando War(简单贪心)
- hdoj 3420 bus Fair
- HDUOj BUS Fair 题目3420
- HDOJ 3420 Bus Fair(动规)
- HDU3420 Bus Fair
- Codeforce Round #438 C.Bus(贪心)
- hdu Bus System(floyd)
- hdu 1690Bus System,(最短路)
- hdu 1690 Bus System(最短路)
- hdu 1690 Bus System(Floyd)
- hdu 5163 Taking Bus(模拟)
- HDU 1690 Bus System(Floyd)
- hdu 5163 Taking Bus(模拟)
- HDU-1690 Bus System(Floyd)
- hdu 1690 Bus System (有点恶心)
- Android生命周期
- leetcode_342 Power of Four
- 加油站
- 谈谈分布式事务
- Myeclipse错误:Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project
- HDU 3420 Bus Fair(贪心)
- CSS清除浮动:清除float浮动
- 磁盘占用率100%——多番尝试
- Java 学习日志1.1 声明变量和常量。
- 动态规划背包类型例题-饭卡
- JVM 并发性: Java 8 并发性基础
- 合作必备助手——SVN
- Notification
- hdu1257 最少拦截系统