Codeforces Round #414


A. Bank Robbery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.

Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the i-th safe from the left is called safe i. There are n banknotes left in all the safes in total. The i-th banknote is in safe xi. Oleg is now at safe a. There are two security guards, one of which guards the safe b such that b < a, i.e. the first guard is to the left of Oleg. The other guard guards the safe c so that c > a, i.e. he is to the right of Oleg.

The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather.

Input

The first line of input contains three space-separated integers, ab and c (1 ≤ b < a < c ≤ 109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.

The next line of input contains a single integer n (1 ≤ n ≤ 105), denoting the number of banknotes.

The next line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109), denoting that the i-th banknote is located in the xi-th safe. Note that xi are not guaranteed to be distinct.

Output

Output a single integer: the maximum number of banknotes Oleg can take.

Examples
input
5 3 7
8
4 7 5 5 3 6 2 8
output
4
input
6 5 7
5
1 5 7 92 3
output
0
Note

In the first example Oleg can take the banknotes in positions 456 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.

For the second sample, Oleg can't take any banknotes without bumping into any of the security guards.


题意:Oleg打算去偷银行,Oleg当前在第a个保险箱的位置,第b个保险箱和第c个保险箱的位置有保安。然后是输入n表示有n张钞票,接下来n个数据表示第i张钞票在哪个保险箱内。

解题思路:由于b<a<c,也即是说Oleg在两个保安之间,所以Oleg能够偷取b到c之间的所有钞票,然后只需要在输入的时候判断一下就可以了。


代码如下:

#include <bits/stdc++.h>

using namespace std;

int a,b,c,n,m,cnt;
int main()
{
    while(~scanf("%d %d %d",&a,&b,&c))
    {
        scanf("%d",&n);
        cnt = 0;
        while(n--)
        {
            scanf("%d",&m);
            if(m>b&&m<c) cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}


B. Cutting Carrot
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into npieces of equal area.

Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to h. Igor wants to make n - 1 cuts parallel to the base to cut the carrot into n pieces. He wants to make sure that all n pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area?

Illustration to the first example.
Input

The first and only line of input contains two space-separated integers, n and h (2 ≤ n ≤ 10001 ≤ h ≤ 105).

Output

The output should contain n - 1 real numbers x1, x2, ..., xn - 1. The number xi denotes that the i-th cut must be madexi units away from the apex of the carrot. In addition, 0 < x1 < x2 < ... < xn - 1 < h must hold.

Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10 - 6.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .

Examples
input
3 2
output
1.154700538379 1.632993161855
input
2 100000
output
70710.678118654752
Note

Definition of isosceles triangle: https://en.wikipedia.org/wiki/Isosceles_triangle.


题意:输入n和h,给你一个底边为1,高度为h的等腰三角形,让你用n-1条平行于底边的直线把这个等腰三角形平分成n个面积相等的区域,输入这n-1条直线的高度。

解题思路:根据相似三角形面积比为边长比的平方来解决。如果把一个三角形分成两个部分,那么上面那个部分比上整个部分就是1:2,也就是说上面那个三角形和整个部分的高度比为sqrt(1):sqrt(2)。

代码如下:

#include <bits/stdc++.h>

using namespace std;

int n,h;
double ans;
int main()
{
    while(~scanf("%d %d",&n,&h))
    {
        for(int i=1; i<n; i++)
        {
            ans = h*sqrt(i)/sqrt(n);
            printf("%.12f%c",ans,i==n-1?'\n':' ');
        }
    }
    return 0;
}



C. Naming Company
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.

To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.

For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :

Initially, the company name is ???.

Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.

Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is{i, m}.

Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.

In the end, the company name is oio.

Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?

A string s = s1s2...sm is called lexicographically smaller than a string t = t1t2...tm (where s ≠ t) if si < ti where i is the smallest index such that si ≠ ti. (so sj = tj for all j < i)

Input

The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.

The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.

Output

The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.

Examples
input
tinkoff
zscoder
output
fzfsirk
input
xxxxxx
xxxxxx
output
xxxxxx
input
ioi
imo
output
ioi
Note

One way to play optimally in the first sample is as follows :

  • Initially, the company name is ???????.
  • Oleg replaces the first question mark with 'f'. The company name becomes f??????.
  • Igor replaces the second question mark with 'z'. The company name becomes fz?????.
  • Oleg replaces the third question mark with 'f'. The company name becomes fzf????.
  • Igor replaces the fourth question mark with 's'. The company name becomes fzfs???.
  • Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??.
  • Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?.
  • Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.

For the second sample, no matter how they play, the company name will always be xxxxxx.


题意:Oleg和lgor新建立了一家公司,他们都想给公司命名,于是他们想了一个游戏,开始时公司的名称为???..一共n个问号,他们各有一个长度为n的字符串,他们轮流取自己的一个字符放在公司名称的任意一个位置,其中Oleg想让公司的名称的字典序尽量小,而lgor想让公司名称的字典序尽量大。Oleg先取。

解题思路:典型的贪心题,首先要确定Oleg和lgor要取的字符的区间,因为Oleg想让字典序小,而lgor想让字典序大,所以Oleg得到字符串要从小到大取,而lgor的字符串从大到小取,即先对两个字符串排序。当n为奇数的时候可以想到,Oleg要取n/2+1个字符,而lgor只能取n/2个字符。即可以求出Oleg取字符的区间和lgor取字符的区间。当然,这道题还需要注意一下其他情况。当我们取Oleg的字符时,先取最小的,但是如果这个最小的都比lgor取字符区间中最大的字符还大,那么为了字典序尽量小,我们就不应该去这个字符,而是将Oleg取字符区间中最大的字符放在最后面。当我们取lgor的字符时,先取最大的字符,但是如果这个最大的字符都比Oleg最小的字符小,那么我们就不能取这个字符放在前面,而是将lgor取字符区间中的最小的字符放在最后面。

代码如下:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e5+20;
char s[maxn],st[maxn],ans[maxn];
int n,l[3],r[3],flag,x,y;	//l[0]和r[0]表示Oleg的取字符的区间,l[1]和r[1]表示lgor的取字符的区间。
int main()
{
    while(~scanf("%s",s))
    {
        scanf("%s",st);
        n = strlen(s);
        sort(s,s+n);
        sort(st,st+n);		//排序
        y = r[1] = n-1;		
        x = flag = l[0] = 0;	
        r[0] = (n+1)/2-1;	
        l[1] = n - r[0];
        if(n%2==0) l[1]--;	//当n为偶数的时候调整lgor的左区间
        while(x<=y)
        {
            if(flag==0)
            {
                if(s[l[0]]<st[r[1]]) ans[x++] = s[l[0]++];	//判断Oleg最小的字符和lgor最大的字符,小于就将这个字符放在前面
                else ans[y--] = s[r[0]--];			//否则就将Oleg取字符区间的最大的字符放在后面。
                flag = 1;
            }
            else
            {
                if(st[r[1]]>s[l[0]]) ans[x++] = st[r[1]--];	//判断lgor最大的字符和Oleg最小的字符,大于就将这个字符放在前面
                else ans[y--] = st[l[1]++];			//否则就将lgor取字符区间的最小的字符放在后面。
                flag = 0;
            }
        }
        ans[n] = '\0';
        puts(ans);
    }
    return 0;
}




  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值