Codeforces Round #373 (Div. 2)

A. Vitya in the Countryside
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.

Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0123456789101112,1314151413121110987654321, and then cycle repeats, thus after the second 1 again goes 0.

As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.

The second line contains n integers ai (0 ≤ ai ≤ 15) — Vitya's records.

It's guaranteed that the input data is consistent.

Output

If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.

Examples
input
5
3 4 5 6 7
output
UP
input
7
12 13 14 15 14 13 12
output
DOWN
input
1
8
output
-1
Note

In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".

In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".

In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.


注意一下特殊情况,以免sad被hack,但还是被hack了一次。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[105];
int main()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    if(n == 1)
    {
        if(a[n] == 15)
            printf("DOWN\n");
        else if(a[n] == 0)
            printf("UP\n");
        else
             printf("-1\n");
    }
    else
    {
        if(a[n] == 15)
            printf("DOWN\n");
        else if(a[n] == 0)
            printf("UP\n");
        else
        {
            if(a[n] > a[n-1])
                printf("UP\n");
            else
                printf("DOWN\n");
        }
    }
}

B. Anatoly and Cockroaches
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.

Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line toalternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.

Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.

The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.

Output

Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.

Examples
input
5
rbbrr
output
1
input
5
bbbbb
output
2
input
3
rbr
output
0
Note

In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.

In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.

In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.

A题做的快了,然后就激动了,以为B是规律题,wa了N次才知道是贪心啊。


对rb循环br循环两种情况,分别看看原串与其错位多少,错位的r和b优先互换,其次单个替换,取最小值。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char str[100005];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        scanf("%s",str);
        int len = strlen(str);
        int ans = 0,a = 0,b = 0;
        for(int i = 0;i < len;i++)
        {
            if(i%2 == 0 && str[i] != 'b')
                ans++,a++;
            if(i%2 == 1 && str[i] != 'r')
                ans++,b++;
        }
        int minn = min(a,b);
        int c = abs(a-b);

        a = 0,b = 0;
        for(int i = 0;i < len;i++)
        {
            if(i%2 == 0 && str[i] != 'r')
                ans++,a++;
            if(i%2 == 1 && str[i] != 'b')
                ans++,b++;
        }

        int mm = min(a,b);
        int d = abs(a-b);
        int ss = min(minn+c,mm+d);
        printf("%d\n",ss);
    }
}

C. Efim and Strange Grade
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).

There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.

In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.

For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.

Input

The first line of the input contains two integers n and t (1 ≤ n ≤ 200 0001 ≤ t ≤ 109) — the length of Efim's grade and the number of seconds till the end of the break respectively.

The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.

Output

Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.

Examples
input
6 1
10.245
output
10.25
input
6 2
10.245
output
10.3
input
3 100
9.2
output
9.2
Note

In the first two samples Efim initially has grade 10.245.

During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.

In the third sample the optimal strategy is to not perform any rounding at all.

  模拟没时间看和想了,只要是模拟不能耽搁啊,不然就不想想了。
  考虑进位的次数,如果理解发现很简单的,

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

char str[200005];

void add(int pos)
{
    int add = 1;
    for(int i = pos;i >= 0;i--)
    {
        if(str[i] == '.')
            continue;

        int val = str[i] - '0';
        val += add;
        str[i] = val % 10 + '0';
        add = val / 10;
    }
}
int main()
{
    int n,t;
    cin >> n >> t;
    scanf("%s",str+1);
    str[0] = '0';//判断是否进位
    int pos = 1;//找到小数点的位置
    while(str[pos] != '.')
        pos++;

    for(int i = pos+1;i <= n;i++)
    {
        if(str[i] >= '5')//如果可以直接进位
        {
            str[i] = 0;//当前及以后pass掉
            add(i-1);
            break;
        }
        else if(str[i] == '4')//前面为4,后面进位
        {
            int cnt = 1;
            while(i <= n && str[i] == '4')
                i++,cnt++;
            if(str[i] >= '5')
            {
                cnt = min(cnt,t);//这里是能进位的最靠前的位数
                str[i-cnt+1] = 0;//pass
                add(i-cnt);
                break;
            }
        }
    }

    int len = strlen(str);
    if(str[len-1] == '.')//最后是小数点
        len--;

    if(str[0] != '0')
        printf("%c",str[0]);
    for(int i = 1;i < len;i++)
        printf("%c",str[i]);
    return 0;
}

//貌似是参考cf上的一个代码,够简化

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值