2016 GDUT Individual Contest2_A题_codeforces 416C(贪心)(重要)
来源:互联网 发布:seo研究中心官方网站 编辑:程序博客网 时间:2024/04/29 11:48
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are n booking requests received by now. Each request is characterized by two numbers: ci and pi — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.
We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.
Unfortunately, there only are k tables in the restaurant. For each table, we know ri — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.
Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≤ ci, pi ≤ 1000) — the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.
The next line contains integer k (1 ≤ k ≤ 1000) — the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≤ ri ≤ 1000) — the maximum number of people that can sit at each table.
In the first line print two integers: m, s — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.
If there are multiple optimal answers, print any of them.
310 502 1005 3034 6 9
2 1302 13 2
题意: 有一个饭店有k张桌子,每张桌子可以坐ri个人,现在有n个团队要来吃饭,每个团队有ci个人,消费为pi,问选择哪些团队,可以再座位足够的情况下,赚取尽可能多的钱。
思路:贪心,把这些团队先按消费金额降序排列(优先选择钱多的),如果消费金额相同,则按人数多少升序排列(优先选择人少的)。此外,桌子也要排列,从小到大排(第一次WA就是因为没有做这步),因为如果不按升序排列的话,有可能大桌子会被人数少的团队占了,后面就用不了了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>using namespace std;const int INF = 0x7fffffff;struct Node{ int x; int y; int no;};struct Node2{ int z; int no;};Node a[1500];Node2 t[1500];bool cmp1(Node a, Node b){ if(a.y == b.y) return a.x < b.x; else return a.y > b.y;}bool cmp2(Node2 a, Node2 b){ return a.z < b.z;}int vis[1500];int main(){ int n; cin >> n; for(int i = 0; i < n; ++i) { cin >> a[i].x >> a[i].y; a[i].no = i+1; } int k; cin >> k; for(int i = 0; i < k; ++i) { cin >> t[i].z; t[i].no = i+1; } sort(a, a+n, cmp1); sort(t, t+k, cmp2); int cnt = 0; int sum = 0; int j = 0; vector<Node> ren; vector<Node2> zhuo; for(int i = 0; i < k; ++i) { for(int j = 0; j < n; ++j) { if(vis[j]) continue; if(t[i].z >= a[j].x) { cnt++; sum+=a[j].y; vis[j] = 1; zhuo.push_back(t[i]); ren.push_back(a[j]); break; } } } cout << cnt << " " << sum << endl; for(int i = 0; i < ren.size(); ++i) cout << ren[i].no << " " << zhuo[i].no << endl; return 0;}
- 2016 GDUT Individual Contest2_A题_codeforces 416C(贪心)(重要)
- 2016 GDUT Individual Contest2_A题_codeforces 416A(双指针)
- 2016 GDUT Individual Contest2_A题_codeforces 416B(暴力)
- 2016Y GDUT新生杯初赛 Problem C: 算罚时
- gdut
- 2016Y GDUT新生杯初赛 Problem B: 签到题
- GDUT 2016新生赛D题 有趣的游戏
- GDUT-2016校赛决赛
- [GDUT]:1057: 5C还是5S
- gdut月赛C: 魔幻任务
- 【WHUST 2016 Individual Contest #1】解题报告
- 【WHUST 2016 Individual Contest #2】解题报告
- 【WHUST 2016 Individual Contest #3 】解题报告
- 广东工业大学(GDUT)2016校赛决赛
- 二分——GDUT #C 进击的调查兵团
- 简单的贪心题 c
- GDUT 2016 A Krito的讨伐 (BFS + 优先队列)
- gdut 2016校赛决赛 Problem F我是好人4
- 利用HTML5定位功能,实现在百度地图上定位
- Java EE 配置Tomcat 不能显示3个小猫图标
- UDP的epoll并发框架-UDP Listener解决OpenVPN的并发问题
- 几种基本的数字正则表达式[转]
- 记录——《C Primer Plus (第五版)》第十二章编程练习第1-8题
- 2016 GDUT Individual Contest2_A题_codeforces 416C(贪心)(重要)
- java 判断对象是否为某个类的实例
- js中form的onsubmit不管用
- 递归函数总结
- Android属性动画欣赏——ObjectAnimator与动画监听事件
- 管理公钥git
- 79. Word Search
- iOS Category小举例
- 蓝懿ios技术交流和心得分享2016年01月21日