CodeForces 719A Vitya in the Countryside 思维题

题目大意:月亮从0到15,15下面是0、循环往复。给出n个数字,如果下一个数字大于第n个数字输出UP,小于输出DOWN,无法确定输出-1.

题目思路:给出0则一定是UP,给出15一定是DOWN,给出其他的一个数字(n==1)无法确定,其他的情况比较后两位。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<vector>
 5 #include<stdio.h>
 6 #include<stdlib.h>
 7 #include<queue>
 8 #include<math.h>
 9 #include<map>
10 #define INF 0x3f3f3f3f
11 #define MAX 1000005
12 #define Temp 1000000000
13 
14 using namespace std;
15 
16 int a[MAX];
17 int main()
18 {
19     int n,op;
20     while(scanf("%d",&n)!=EOF)
21     {
22         for(int i=1;i<=n;i++)
23             scanf("%d",&a[i]);
24         if(n==1)
25         {
26             if(a[n]==15)
27                 op=-1;
28             else if(a[n]==0)
29                 op=1;
30             else
31                 op=0;
32         }
33         else
34         {
35             if(a[n]==15)
36                 op=-1;
37             else if(a[n]==0)
38                 op=1;
39             else if(a[n] > a[n-1])
40                 op=1;
41             else if(a[n] < a[n-1])
42                 op=-1;
43         }
44         if(op==0)
45             printf("-1
");
46         else if(op==1)
47             printf("UP
");
48         else
49             printf("DOWN
");
50     }
51     return 0;
52 }
View Code
原文地址:https://www.cnblogs.com/alan-W/p/5932225.html