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 ...
随机推荐
- jquery动画切换引擎插件 Velocity.js 学习01
一.Velocity.js介绍 Velocity是一个jQuery插件,重新实现了$.animate() 来产生更高的性能(速度也比CSS动画库更快),而包括新的功能,以提高动画工作流程. Veloc ...
- mysql的数据库 索引
1.两种主要的引擎:MyISAM和InnoDB 2.如何查看自己的表是什么类型:http://www.cnblogs.com/luosongchao/archive/2013/05/23/309592 ...
- Jmeter 重要测试指标释义
Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...
- 解决配置JAVA_HOME JDK版本不变的问题
解决方案:修改环境变量Path 因为PATH环境变量中默认将system32等系统重要目录添加在最前面,所以运行java -version时当然是调用system32目录下的java.exe了. 所以 ...
- JDK工具学习
javap: 可以对照源代码和字节码,从而了解很多编译器内部的工作. 查看class字节码:JDK有自带的工具包,使用javap命令打开.class文件就行 javap -c JAVAPTest
- CODE FESTIVAL 2017 qual B C - 3 Steps
Score : 500 points Problem Statement Rng has a connected undirected graph with N vertices. Currently ...
- 2017ACM暑期多校联合训练 - Team 1 1001 HDU 6033 Add More Zero (数学)
题目链接 Problem Description There is a youngster known for amateur propositions concerning several math ...
- Spring 路由地址的基本使用
1.下面是spring的使用基本框架连接 https://www.cnblogs.com/HD/p/4103239.html
- foreign key constraint fails错误的原因
建表:CREATE TABLE Course ( Cno Char(4) PRIMARY KEY, Cname Char(40), Cpno Char(4), Ccredit Int, FOREIGN ...
- Linux 入门记录:一、命令行 Bash 的基本操作
为了以后长期的线上测试和服务器的性能考量,要用 Linux 服务器了.昨晚装了个 CentOS 6.9,今天开始学学 Linux 基础,扫扫盲.ok,小本本记 ing... 一.Shell简介 She ...