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 0, 1, 2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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.
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.
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.
5 3 4 5 6 7
UP
7 12 13 14 15 14 13 12
DOWN
1 8
-1
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天月亮大小表:0, 1, 2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
题解:如果最后一个数是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;
}
}
}
题意:给你一个串,仅有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;
}