Buy One Get One Free--贪心
来源:互联网 发布:什么是数据生态圈 编辑:程序博客网 时间:2024/06/06 12:53
分析:贪心,对两种稻草排序,然后,直接满足条件从大到小取
Code:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std; const int maxn = 10000+5;int a[maxn], b[maxn];int n, m; int main() { while(~scanf("%d%d", &n, &m)) { for(int i = 0; i < n; i++) scanf("%d", &a[i]); for(int i = 0; i < m; i++) scanf("%d", &b[i]); sort(a, a+n); sort(b, b+m); int q = m-1; int ans = 0; for(int i = n-1; i >= 0; i--) { ans++; for(; q >= 0; q--){ if(a[i] > b[q]) { ans++; q--; break; } } } printf("%d\n", ans); } return 0;}
0 0
- Buy One Get One Free--贪心
- Buy One Get One Free
- TOJ 2761.Buy One Get One Free
- UVA 10983 - Buy one, get the rest free(网络流)
- Uva 10983 Buy one, get the rest free(网络流/时序模型)
- #UVA10983#Buy one,Get the rest free(网络流 + 分层拆点经典+二分)
- Uva 10983 Buy one, get the rest free(二分+最大流)
- One
- one
- one:
- One
- ONE
- one
- one
- one
- one
- one
- one
- 18.2 CSDN牛人博客!随时更新!...
- Python学习之ThreadLocal
- JDK环境变量设置
- JavaScript核心基础语法
- 正则表达式小知识
- Buy One Get One Free--贪心
- 指针总结
- 第三周项目-本月有几天?
- MySQL数据库总结(9)触发器
- 活动管理器Activitycolletor(一键退出所有活动)
- 解决:eclipse报错:target runtime com.genuitec.runtime.generic.java is not defined
- LINUX和UNIX的关系是什么?
- C#匿名方法和lambda
- hdu1077 catching fish