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 or 9, thus the answer is -1.
原题链接:http://codeforces.com/contest/719/problem/A
题意:给你一个0-15-1-0的周期序列。问你下一个数字将会是上升的还是下降的。
首先特殊情况,最后一个为0,一定上升,最后一个为15,一定下降,只有一个其他的数字,则无法判断,否则比较最后两个数字。
官方题解:
here are four cases that should be carefully considered:
-
an = 15 — the answer is always DOWN.
-
an = 0 — the answer is always UP.
-
If n = 1 — the answer is -1.
-
If n > 1, then if an–1 > an — answer is DOWN, else UP.
Time Complexity: .
AC代码:
/**
* 行有余力,则来刷题!
* 博客链接:http://blog.csdn.net/hurmishine
*
*/
/**
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
//freopen("data.txt","r",stdin);
int a[100];
int n;
while(cin>>n)
{
for(int i=1; i<=n; i++)
cin>>a[i];
if(a[n]==0)
cout<<"UP"<<endl;
else if(a[n]==15)
cout<<"DOWN"<<endl;
else if(n==1)
cout<<"-1"<<endl;
else if(a[n]>a[n-1])
cout<<"UP"<<endl;
else
cout<<"DOWN"<<endl;
}
return 0;
}
尊重原创,转载请注明出处: http://blog.csdn.net/hurmishine