codeforces C. Booking System

题意:有n组客人,分别告诉每一组的个数和花费,然后给你餐厅内k个桌子,每个桌子的最大容纳人数,如何安排使得餐厅最大收益并且容纳人数尽可能大;

思路:贪心,对花费排序,然后对每一组客人找桌子就可以。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 2000
 5 using namespace std;
 6 struct node
 7 {
 8     int c,p,id;
 9     bool operator <(const node &a)const
10     {
11         return (p>a.p)||(p==a.p&&c>a.c);
12     }
13 }q[maxn];
14 struct node1
15 {
16    int x,id;
17    bool operator <(const node1 &a)const
18    {
19        return x<a.x;
20    }
21 }p[maxn],pp[maxn];
22 bool vis[maxn];
23 int num[maxn];
24
25 int main()
26 {
27     int n,k;
28     scanf("%d",&n);
29     for(int i=0; i<n; i++)
30     {
31         scanf("%d%d",&q[i].c,&q[i].p);
32         q[i].id=i+1;
33     }
34     sort(q,q+n);
35     scanf("%d",&k);
36     for(int i=1; i<=k; i++)
37     {
38         scanf("%d",&p[i].x);
39         p[i].id=i;
40     }
41     sort(p+1,p+k+1);
42     memset(vis,false,sizeof(vis));
43     int ans=0,cnt=0;
44     for(int i=0; i<n; i++)
45     {
46         for(int j=1; j<=k; j++)
47         {
48             if(p[j].x>=q[i].c&&!vis[p[j].id])
49             {
50                 pp[cnt].x=q[i].id;
51                 pp[cnt++].id=p[j].id;
52                 ans+=q[i].p;
53                 vis[p[j].id]=true;
54                 break;
55             }
56         }
57     }
58     printf("%d %d\n",cnt,ans);
59     for(int i=0; i<cnt; i++)
60     {
61         printf("%d %d\n",pp[i].x,pp[i].id);
62     }
63     return 0;
64 }

时间: 2024-10-05 04:56:58

codeforces C. Booking System的相关文章

CodeForces 4C Registration system

Registration system Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on CodeForces. Original ID: 4C64-bit integer IO format: %I64d      Java class name: (Any) A new e-mail service "Berlandesk" is going to be opened in Berland

Codeforces 458A Golden System

经过计算两个字符串的大小对比 主要q^2=q+1 明明是斐波那契数 100000位肯定超LL 我在每一位仅仅取到两个以内 竟然ac了 #include<bits/stdc++.h> using namespace std; int a[100020]; char s1[100020],s2[100020]; int main() { scanf("%s%s",s1,s2); int len1=strlen(s1),len2=strlen(s2); for(int i=len

Codeforces 1321D Navigation System

题意 有个人要从\(s\)走到\(t\),经过的路径给定.导航系统每次会显示当前节点到\(t\)的最短路,有多条就显示其中之一.这个人如果按照导航走,那么啥都没变.如果没有按导航走导航就会重新导航.问重新导航的最小和最大次数. 解题思路 建反图,在反图上以\(t\)为源跑dijkstra最短路. 在原图上dfs 若下一个节点到\(t\)的距离是所有邻接节点中最短的 如果到\(t\)最短的节点只有一个,那么什么都不变. 如果不止一个,那么最大次数加1. 若下一个节点到\(t\)的距离是所有邻接节点

26款 网络会议/视频会议开源软件

转自:http://www.oschina.net/project/tag/227/video-conferencing?lang=0&os=0&sort=view&p=1 视频会议系统 OpenMeetings OpenMeetings是一个多语言可定制的视频会议和协作系统.它支持音频.视频,能让你查看每个与会者的桌面.OpenMeetings还包含一个白板,通过白板可以导入各种格式的图片和涂鸦. 在线演示:http://www.openmeetings.de/...更多Open

CodeForces 22C System Administrator 小水怡情 图论+构造

题目链接:点击打开链接 构造一个星形图+一个完全图就好了.. #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf

Codeforces Beta Round #4 (Div. 2 Only) C. Registration system hash

C. Registration system Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/4/C Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to

【打CF,学算法——一星级】Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/A 题面: A. Currency System in Geraldion time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A magic island Geraldion, where Gerald lives,

CodeForces 527B Error Correct System

Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 527B Description Ford Prefect got a job as a web developer for a small company that makes towels. His current work ta

CodeForces 22C System Administrator

把v和2结点交换, 1和v连,其他点和v之间可以互相连. #include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; int n,m,v,flag,i,cnt,j; int mai