Codeforces Round #423 A Restaurant Tables(模拟)
1 second
256 megabytes
standard input
standard output
In a small restaurant there are a tables for one person and b tables for two persons.
It it known that n groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.
If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.
You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.
Print the total number of people the restaurant denies service to.
4 1 2
1 2 1 1
0
4 1 1
1 1 2 1
2
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.
In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
有一家店里面有两种桌子,a个一个坐的桌子和b个两人坐的桌子,他们的店会进来n个团体,n个团体里面都只有1人或2人。安排座位的顺序是这样的,从团体来的时间从前往后依次安排,比如第二组样例,有1个一个人坐的桌子和2个两个坐的桌子,那么先进来第一个人,安排到那一个桌子上,又进来1个人,安排在两个人的桌子上,又进来两个人,那么坐不下了,就请出去,又来一个人,坐在两个人桌子上剩余的那个位置。
#include <bits/stdc++.h> int n, a, b, k; int main(){
scanf("%d%d%d", &n, &a, &b);
int restb = b*;
int deny = ;
for(int i = ; i < n; i++){
scanf("%d", &k);
if(k == ){
if(a > ) a--;
else if((a == ) && b){
b--;
restb--;
}
else if(restb){
restb--;
}
else deny++;
}
else{
if(b){
b--;
restb-=;
}
else deny+=;
}
}
printf("%d\n", deny);
}
//使用额外变量half记录双人座的单个位子
#include <iostream>
using namespace std; int main() { int n,a,b,half=,value=;
cin>>n>>a>>b; for(int x=;x<n;x++)
{
int m;
cin>>m; if(m==)
{
if(a>)
{
a--;
}
else if(b>)
{
b--;
half++;
}
else if(half>)
{
half--;
}
else
value++;
}
else if(m==)
{
if(b>)
b--;
else
value+=;
}
}
cout<<value<<endl;
return ;
}
Codeforces Round #423 A Restaurant Tables(模拟)的更多相关文章
- Codeforces Round #423 (Div. 2)
codeforces 423 A. Restaurant Tables [水题] //注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌.读清题意. #inclu ...
- Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)
Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)
题目链接:http://codeforces.com/contest/828 A. Restaurant Tables time limit per test 1 second memory limi ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...
- Codeforces Round #304 C(Div. 2)(模拟)
题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C
A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...
- Educational Codeforces Round 11B. Seating On Bus 模拟
地址:http://codeforces.com/contest/660/problem/B 题目: B. Seating On Bus time limit per test 1 second me ...
随机推荐
- Hadoop 介绍
1.Hadoop简介 Hadoop[hædu:p]实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS.HDFS有高容错性的特点,并且设计用来部署在低 ...
- 基于Mysql数据库亿级数据下的分库分表方案
移动互联网时代,海量的用户数据每天都在产生,基于用户使用数据的用户行为分析等这样的分析,都需要依靠数据都统计和分析,当数据量小时,问题没有暴露出来,数据库方面的优化显得不太重要,一旦数据量越来越大时, ...
- Linux中 设置apache,mysql 开机启动
linux开启启动的程序一般放在/etc/rc.d/init.d/里面,/etc/init.d/是其软连接 mysql设为linux服务 cp /usr/local/mysql5/share/mysq ...
- Jmeter-12-如何使用Plugin Manager
1. 搜索 Jmeter plugin 并找到plugin manager 下载jar文件 2. 放到jmeter/lib/ext下面, 重启jmeter 3. 找到选项-> Plugin ma ...
- Tomcat启动报错:org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalin
Error starting ApplicationContext. To display the auto-configuration report re-run your application ...
- 【BZOJ】1718: [Usaco2006 Jan] Redundant Paths 分离的路径
[题意]给定无向连通图,要求添加最少的边使全图变成边双连通分量. [算法]Tarjan缩点 [题解]首先边双缩点,得到一棵树(无向无环图). 入度为1的点就是叶子,两个LCA为根的叶子间合并最高效,直 ...
- bzoj 1202 并查集
首先我们知道若干区间和信息,判断给出信息是否合法,可以用并查集维护,我们用dis[x]表示x到father[x]的距离为多少,即区间father[x]到x的长度,这样我们可以在路径压缩的时候维护dis ...
- ribbon设置url级别的超时时间
序 ribbon的超时设置,只能按转发的serviceId来分的,无法像nginx那样直接在每个转发的链接里头设置超时时间.这里hack一下,实现url基本的ribbon超时时间设置.具体的思路就是重 ...
- nodewebkitV0.21.6版本的学习
1.下载 https://nwjs.io/ 建议下载sdk版本,有调试功能,正式发布时,使用normal版本 下载以后解压,得到的文件目录如下 点击nw.exe,显示如下 2.hello world ...
- esp8266 IOT Demo 固件刷写记录
将编译好的固件按照下面地址刷写到esp8266 出现下面错误是因为刷写的设置不对,按照图上设置: load 0x40100000, len 26828, room 16 tail 12chksum 0 ...