codeforces模拟专题

来源:互联网 发布:淘宝舒口健牙膏 编辑:程序博客网 时间:2024/06/02 02:16

A. Restaurant Tables
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Input
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.

Output
Print the total number of people the restaurant denies service to.

Examples
input
4 1 2
1 2 1 1
output
0
input
4 1 1
1 1 2 1
output
2
Note
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.
模拟就好,不过题意一定要理解,否则的话就不行了
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.
注意上面这句话

#include<stdio.h>#include<iostream>#include<string.h>using namespace std;long long  t[222222];int main(){    long long  n,a,b;    while(cin>>n>>a>>b)    {        int i,j;        long long sum=0,s=0;        for(i=0; i<n; i++)        {            scanf("%lld",&t[i]);            s+=t[i];        }        int f=0;        for(i=0; i<n; i++)        {            if(t[i]==1)            {                if(a>0)                {                    a--;                    sum+=1;                }                else if (b!=0)                {                    b--;                    sum++;                    f ++;                }                else if(f)                {                    sum++;                    f --;                }            }            else if(t[i]==2&&b!=0)            {                b--;                sum+=2;            }        }        printf("%lld\n",s-sum);    }    return 0;}

A. Unimodal Array
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Array of integers is unimodal, if:

it is strictly increasing in the beginning;
after that it is constant;
after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

Write a program that checks if an array is unimodal.

Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 1 000) — the elements of the array.

Output
Print “YES” if the given array is unimodal. Otherwise, print “NO”.

You can output each letter in any case (upper or lower).

Examples
input
6
1 5 5 5 4 2
output
YES
input
5
10 20 30 20 10
output
YES
input
4
1 2 1 2
output
NO
input
7
3 3 3 3 3 3 3
output
YES
Note
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
单峰阵列:题意不难理解

#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int main(){    int n,a[105],i,minn=0,k=0,flag=0;    scanf("%d",&n);    for(i=0;i<n;i++)    {        scanf("%d",&a[i]);        if(a[i]>minn&&k==1)        {            flag=1;            break;        }        if((a[i]==minn||a[i]>minn)&&k==2)        {            flag=1;            break;        }        if(a[i]==minn)            k=1;        if(a[i]<minn)            k=2;        minn=a[i];    }    if(flag==1)        printf("NO\n");    else        printf("YES\n");    return 0;}

B. Keyboard Layouts
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.

You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order.

You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.

Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

Input
The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.

The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.

The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

Output
Print the text if the same keys were pressed in the second layout.

Examples
input
qwertyuiopasdfghjklzxcvbnm
veamhjsgqocnrbfxdtwkylupzi
TwccpQZAvb2017
output
HelloVKCup2017
input
mnbvcxzlkjhgfdsapoiuytrewq
asdfghjklqwertyuiopzxcvbnm
7abaCABAABAcaba7
output
7uduGUDUUDUgudu7
简单的字符串操作,注意细节就好

#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int main(){    string s1,s2,s;    int flag=0;    cin>>s1>>s2>>s;    for(int i=0;i<s.size();i++)    {        flag=0;        if(s[i]>='A'&&s[i]<='Z')         s[i]+=32,flag=32;        for(int j=0;j<26;j++)        {            if(s[i]==s1[j])            {                s[i]=s2[j]-flag;                break;//不能省略            }        }    }    for(int i=0;i<s.size();i++)        printf("%c",s[i]);    printf("\n");    return 0;}