题目描述:
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
4 1 1
1 1 2 1
输出:
0
2
题意:
一个餐厅,他有a张一人座位,b张双人座位,有n组人来这个餐厅,每组人都是一个或两个人。一个人的话,如果有单人座就优先分配单人座,如果没有,有双人座就分配双人座,若没有单独的双人座,就和他人共享,如果在没有就拒绝为他们服务,对于双人来说,有双人座就接收,否则拒绝,按输入接纳这n组人,问你一共拒绝了多少人。
题解:
按照题目模拟
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
char s[10000];
int vis[30][30];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i = 0; i <= 26; i ++){
for(int j = 0; j <= 26; j ++){
vis[i][j] = 0;
}
}
scanf("%s",s);
for(int i = 0; i < n - 1; i ++){
int t1 = s[i] - 'A';
int t2 = s[i + 1] - 'A';
vis[t1][t2] ++;
}
int maxx = - 1;
int x = 0,y = 0;
for(int i = 0; i < 26; i ++){
for(int j = 0;j < 26; j ++){
if(vis[i][j] > maxx){
maxx = vis[i][j];
x = i;
y = j;
}
}
}
printf("%c%c\n",(x + 'A'),(y + 'A'));
}
return 0;
}