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 012,34567891011121314151413121110987654321, 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 or9, thus the answer is -1.

题意: 给出你天数和每一天月亮的大小,问明天的月亮会变大还是变小,如果不确定 输出-1.

30天月亮大小表:012,34567891011121314151413121110987654321

题解:如果最后一个数是0,是up,15,是DOWN,否则 如果只是一个数,输出-1,否则 看最后一个数和前一个数的大小关系。

没想到这题初测没有考虑一个数为0为15的情况,我cha了3个,我房间有一个cha了10个,然而我cha了他。。。。

代码:

#include <bits/stdc++.h>//代码略渣,懒不想改
#define ll long long
using namespace std;
const int mx=1e5;
int a[mx];
int n,m,k;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
        cin>>a[i];
    if(t==1)
    {
        if(a[t]==15)
            cout<<"DOWN"<<endl;
        else if(a[t]==0)
            cout<<"UP"<<endl;
        else
        cout<<-1<<endl;
    }
    else
    {
        if(a[t]>a[t-1])
        {
            if(a[t]==15)
            {
                cout<<"DOWN"<<endl;
            }
            else
                cout<<"UP"<<endl;
        }
        else
        {
            if(a[t]==0)
                cout<<"UP"<<endl;
            else
            cout<<"DOWN"<<endl;
    }
}
}
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.


题意:给你一个串,仅有r和b组成,问经过多少次操作后能形成rbrbrb或brbrbr(两种操作,1:交换任意位置的一对r,b 2:将一个r变成b,或b变成r);

题解:刚开始以为只能交换相邻的,发现完全不会做,后来发现可以交换任意位置的,就枚举即可,我们假设最后形成是rbrb型的,记录不满足的r和b的个数,两者取较大。再枚举brbrb。情况之间取小的。

代码:

#include <bits/stdc++.h>
using namespace std;

char a[1010101];
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
        cin>>a[i];
	int a0=0,a1=0,mini;
	for(int i=0;i<t;i++)
	{
		if(a[i]!='r'&&i%2==1)
			a1++;
		if(a[i]!='b'&&i%2==0)
			a0++;
	}
	//cout<<a0<<" "<<a1<<endl;
	mini=max(a1,a0);
	a1=a0=0;
	for(int i=0;i<t;i++)
	{
		if(a[i]!='r'&&i%2==0)
			a1++;
		if(a[i]!='b'&&i%2==1)
			a0++;
	}

	//cout<<a0<<" "<<a1<<endl;
	mini=min(mini,max(a1,a0));
	cout<<mini<<endl;
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值