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 ...
随机推荐
- [Leetcode] LRU 算法实现
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- 任何用户密码都能以sysdba角色登入
这是因为在安装Oracle的时候默认是使用了操作系统验证: 数据库用sysdba登录的验证有两种方式,一种是通过os认证,一种是通过密码文件验证:登录方式有两种,一种是在数据库主机直接登录(用os认证 ...
- 【算法日记】2.算法中的大O符号
大O符号是一种算法复杂度的相对表示方式. 1.大O表示算法的操作数,表示出算法运行的快慢 2.大O表示法指出了最糟糕情况下的运行时间,例如 简单查找的运行时间O(n),意味着在最糟糕的情况下,必须运行 ...
- [洛谷P3444] [POI2006]ORK-Ploughing
洛谷题目链接[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He ca ...
- luaj luaoc 回调函数传递的一些小总结
问题场景:我们的游戏在支付时,由于第三方支付比较费时,可能在支付的过程中,我们lua写的cocos2dx项目会断网,我们的游戏有自动重连的机制.我就想,如果断线好了以后,支付完成了,那在断网之前传入的 ...
- Java 中的成员内部类
内部类中最常见的就是成员内部类,也称为普通内部类.我们来看如下代码: 运行结果为: 从上面的代码中我们可以看到,成员内部类的使用方法: 1. Inner 类定义在 Outer 类的内部,相当于 Out ...
- 第一章: 文件句柄转化为 typeglob/glob 与文件句柄检测
#为了使在子例程中传递文件句柄不出问题 #我们要把文件句柄转为glob或typeglob #转为glob $fd = *MY_FILE; #转为typeblog $fd = \*MY_FILE; #两 ...
- webview loadRequest
// 所构建的NSURLRequest具有一个依赖于缓存响应的特定策略,cachePolicy取得策略,timeoutInterval取得超时值 [self.yourSite loadRequest: ...
- android studio 64位手机+Fresco引起的在arm64位机器上找不到对应的so库
我们的程序在32位机器上没有问题,有一天公司采购了一台魅族MX5 MTK的64位处理器上我们的应用报错了 "nativeLibraryDirectories=[/data/app/com.l ...
- IE中部分版本的浏览器对Select标签设置innerHTML无效的问题
这样写的代码:document.getElementById('data_list').innerHTML = data;//data是ajax返回的数据 结果发现在ie10的兼容模式下面下拉框没有内 ...