TOJ 2761.Buy One Get One Free
来源:互联网 发布:windows打印原理 编辑:程序博客网 时间:2024/05/29 03:22
题目链接:http://acm.tju.edu.cn/toj/showp2761.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1117 Accepted Runs: 409 Multiple test files
The deal, however, is restricted: the larger bale must be high quality hay and the smaller one must be low quality hay. FJ, being a frugal and thrifty fellow, does not care: any quality of hay will do as long as he saves some money.
Given a list of the sizes of N (1 ≤ N ≤ 10,000) bales of high quality hay and M (1 ≤ M ≤ 10,000) bales of low quality hay, find the maximum number of bales of hay Farmer John can purchase. He can buy bales of high quality hay without getting the free bale of low quality hay, but he cannot buy bales of low quality hay (i.e., he must get them for free in the deal).
Input
* Line 1: Two space-separated integers: N and M.* Lines 2..N + 1: Line i + 1 contains a single integer which is the size of the i-th bale of high quality hay.
* Lines N + 2 .. N + M + 1: Line i + N + 1 contains a single integer which is the size of the i-th bale of low quality hay.
Output
* Line 1: The maximum total number of bales of hay Farmer John can obtain.Sample Input
3 46131534
Sample Output
5
Input Details
There are 3 bales of high quality hay, with sizes 6, 1, and 3, and 4 bales of low quality hay, with sizes 1, 5, 3, and 4.Output Details
Obviously, Farmer John can buy all the bales of high quality hay. When he buys the size 6 high quality bale, he can get any low quality bale for free (say, the bale of size 3). When he buys the size 3 high quality bale, he can get the size 1 low quality bale for free. When he buys the size 1 high quality bale, however, he cannot get any low quality bales for free (since the size must be strictly less). The total, no matter how clever FJ is, comes to five bales.Source: USACO 2007 February Competition
水题,直接贪心就可,莫名其妙的过了(本来以为会超时的。。)
#include <stdio.h>#include <algorithm>using namespace std;int low[10001],high[10001];int main(){int n,m;scanf("%d%d",&n,&m);for(int i=0;i<n;i++)scanf("%d",&high[i]);for(int i=0;i<m;i++)scanf("%d",&low[i]);sort(high,high+n);sort(low,low+m);int sum=0;for(int i=n-1;i>=0;i--)for(int j=m-1;j>=0;j--){if(high[i]>low[j] && low[j]!=-1){sum++;low[j]=-1;break;}}printf("%d\n",sum+n);}
- TOJ 2761.Buy One Get One Free
- Buy One Get One Free
- 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
- hdoj 5620 KK's Steel (数学思维,那波婓切)
- JS中mouseover和mouseout多次触发问题如何解决
- CI的验证码代替类库(ci怎么加入验证码)
- 继续背单词,8个月过去了
- nginx代理后,获取request的ip
- TOJ 2761.Buy One Get One Free
- 常用的刷新技术(一)——SwipeRefresh
- 【CF 583C】
- 4、Java 包及访问控制权限
- 《构建之法》读书笔记——第9章 项目经理
- Spring 的使用与配置
- 数据绑定
- 一个很详细的web.xml讲解
- C++ bitset类的使用与简介