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.
3 10 50 2 100 5 30 3 4 6 9
2 130 2 1 3 2
题意:
给出 N(1 ~ 1000),代表有 N 个旅行团,后给出 N 个旅行团的人数和钱数。现要去一饭馆吃饭,有 K(1 ~ 1000) 张桌子,后给出每张桌子最大容纳的人数量。要如何分配旅行团的人,使其赚到的钱数最多。每个团的人必须在同一桌吃饭,一桌不能共存有两个团。
思路:
贪心。使赚到的钱最大,所以对旅行团的钱数由大到小排序,如果钱数相同则人数由小到大排序。后开始分配座位,每次分配原则为找最小适合该旅行团人数的桌子。
AC:
#include <cstdio> #include <algorithm> using namespace std; const int MAX = 1005; typedef struct { int peo, mon, num, tab; }node1; node1 p[MAX]; int t[MAX], vis[MAX]; int cmp (node1 a, node1 b) { if (a.mon != b.mon) return a.mon > b.mon; return a.peo < b.peo; } int main () { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", &p[i].peo, &p[i].mon); p[i].num = i; p[i].tab = -1; } sort (p + 1, p + 1 + n, cmp); int k; scanf("%d", &k); for (int i = 1; i <= k; ++i) { scanf("%d", &t[i]); vis[i] = 0; } int sum = 0, ans = 0; for (int i = 1; i <= n; ++i) { int min_num = MAX; for (int j = 1; j <= k; ++j) { if(p[i].peo <= t[j] && !vis[j] && min_num > t[j]) { min_num = t[j]; p[i].tab = j; } } if (p[i].tab != -1) { ans++; sum += p[i].mon; vis[p[i].tab] = 1; } } printf("%d %d\n", ans, sum); for (int i = 1; i <= n; ++i) { if (p[i].tab != -1) { printf("%d %d\n", p[i].num, p[i].tab); } } return 0; }
相关推荐
**MRBS v1.9.2 Meeting Room Booking System 安装使用详解** Meeting Room Booking System (MRBS) 是一款用于管理会议室预订的开源软件。在本文中,我们将详细阐述如何在支持PHP和MySQL或PostgreSQL的环境中安装和...
"Restaurant Table Booking System"是这样一款专门为餐饮业设计的移动应用程序,它旨在提高餐厅运营效率,优化顾客预订体验,同时也为餐厅管理者提供了便捷的后台管理工具。 一、系统概述 “Restaurant Table ...
【Coach Booking System-开源】是一个基于Visual Basic 6(VB6)开发的系统,主要针对教练操作员设计,用于管理演出和其他活动的教练预订。这个开源项目旨在满足公司的各种业务需求,提供一个全面的解决方案来规划和...
总的来说,"Meeting Room Booking System 1.4 beta1"提供了一个强大且易于扩展的平台,能够有效解决会议室管理问题,提高工作效率,是企业和组织的理想选择。通过深入研究其源代码,开发者还可以学习到PHP Web开发的...
在这个"Hotel Booking System Using AngularJS"项目中,开发者结合了ASP.NET MVC和AngularJS的优势,创建了一个功能完善的酒店客房预订系统。该系统旨在提供一个用户友好的界面,让用户能够方便地查看和预订酒店房间...
Booking System是一个正在使用Django框架开发的Web应用程序。 目录 介绍 Booking System是一个基于Django的Web应用程序。 此应用程序的主要目的是最大程度地减少时间和金钱的浪费。 先决条件 对于上面列出的...
《Python实现票务预订系统详解》 在信息技术日益发达的今天,票务预订系统已经成为各行各业不可或缺的一部分,尤其在旅游、演出、交通等领域更是扮演着重要角色。本篇将深入探讨如何利用Python语言来构建一个简单...
【标题】"Bus_Booking_System.zip_Booking_Sharp_c sharp vehicle" 概述了一个基于C#(Asp.Net)开发的在线公交和车辆预订系统。这个系统为用户提供了一个方便的平台,可以在线查找、比较并预订各类交通工具。下面将...
《CultBooking Hotel Booking System:开源酒店预订系统的深度解析》 CultBooking Hotel Booking System 是一款基于开源许可的酒店预订解决方案,旨在为酒店业提供高效、灵活且易于集成的在线预订服务。这款系统的...
1. "MULTIPLEX THEATER ONLINE BOOKING SYSTEM.pdf" - 这可能是项目的设计文档或教程,详细介绍了多厅电影院的在线预订流程和技术实现。它可能会涵盖系统架构、数据库设计、用户界面设计以及系统如何处理多用户并发...
新天煜羽毛球馆场馆预定系统_Badminton-Venue-Booking-System
Ajax-Flight-Booking-System-JavaServlets_App.zip,基于Java Servlet、Java Server页面(JSP)的模型视图控制器(MVC)架构的土耳其航空公司(Web应用)的企业级航班预订系统。实现了对用户的认证和授权。该web应用...
Booking.com MySQL数据库架构 Booking.com 作为全球最大的在线酒店预订网站,其数据库架构是基于 MySQL 的。 Booking.com 使用 MySQL 作为主要的线上数据库解决方案,目前是欧洲最大的 MySQL 用户。 数据库架构 ...
这个开源项目“Online-Movie-Ticket-Booking-System-in-php”提供了一个基础框架,开发者可以根据需求进行定制和扩展。例如,可以添加更多的支付选项,实现社交媒体登录,或者引入推荐算法来个性化用户界面。源代码...
《全面解析Java实现的房间预订系统》 在现代生活中,无论是商业办公还是教育机构,有效管理会议室、教室等公共资源的预订已经成为日常运营不可或缺的一部分。基于Java技术开发的房间预订系统,以其高效、灵活和易...
这个名为"movie-booking-system-master.zip"的压缩包包含了一个完整的电影购票后台系统,让我们来深入探讨一下这个系统可能涵盖的关键知识点。 1. **系统架构**:通常,这样的系统会采用三层架构,包括表现层(前端...
**Meeting Room Booking System (MRBS) 开源项目详解** MRBS,全称为Meeting Room Booking System,是一个专为管理会议室预订而设计的开源软件系统。它不仅适用于会议室的预订,还能扩展到其他资源的预订,例如电脑...
【标题】"train_ticket_booking_system.zip" 涉及的是一个火车票预订系统的源代码压缩包,这通常是一个用于管理、处理和分配火车票的软件应用程序。从描述中我们可以推测,这个系统可能包含了用于开发、调试和数据...
Ajax-Online-Appointment-Booking-System.zip,为零售连锁诊所提供在线预约系统,用户和管理方均可使用。,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建...
**Windsor Internet Booking System(WIBS)详解** Windsor Internet Booking System(WIBS)是一款专门设计用于管理公共车站需求的开源图书馆预订系统。这个系统旨在提供一个高效、用户友好的平台,使图书馆用户...