链接:https://www.nowcoder.com/acm/contest/82/D

来源:牛客网

比较月亮大小

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 262144K,其他语言524288K

64bit IO Format: %lld

题目描述

 点点是一名出色的狼人。众所周知,狼人只有在满月之夜才会变成狼。

同时,月亮的大小随着时间变化,它的大小变化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 然后又再一次循环。

今年夏天点点很无聊,于是开始看月亮。由于点点很忙,所以他只选择一段连续的时间看月亮,并把月亮的大小记录了下来。

现在,他告诉你他记录下东西,让你告诉他下一天(即点点记录下的最后一天的第二天)的月亮是比前一天(即点点记录下的最后一天)大还是小。

输入描述:

给你一个正整数n表示点点记录下的时间个数。

下一行n个自然数表示点点记录下的月亮大小。

输出描述:

一个字符串。

如果下一天的比前一天的大则输出”UP”

如果下一天的比前一天的小则输出”DOWN”

如果无法判断则输出”-1”

示例1

输入

5

3 4 5 6 7

输出

UP

示例2

输入

8

12 13 14 15 14 13 12 11

输出

DOWN

示例3

输入

1

8

输出

-1

备注:

n≤100 0 ≤ ai ≤ 15

保证输入的数据满足月亮变化的循环规律

思路

考虑完整 分析出集中情况即可

0.n = 1 的情况

输入的一个数 只有是 0 或 15 的时候 分别对应 up 和 down 其他情况都是 -1

  1. n != 1 的时候 我们只需要最后两个数字 就足以判断

我们令 最后两数字 分别为 a b

a > b 的时候

如果 a = 1 那么 b 就为 0 就是 up

其他情况 都是 down

a < b 的时候

如果 a = 14 那么 b 就是 15 然后 就是 down

其他情况都是 up

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 1e3 + 5;
const int MOD = 1e9 + 7; int main()
{
int n, num;
cin >> n;
if (n == 1)
{
cin >> num;
if (num == 0)
printf("UP\n");
else if (num == 15)
printf("DOWN\n");
else
printf("-1\n");
}
else
{
int m = n - 2;
for (int i = 0; i < m; i++)
scanf("%d", &num);
int a, b;
scanf("%d%d", &a, &b);
if (a > b)
{
if (a == 1)
printf("UP\n");
else
printf("DOWN\n");
}
else if (a < b)
{
if (a == 14)
printf("DOWN\n");
else
printf("UP\n");
}
}
}

牛客练习赛14 D 比较月亮大小 【水】的更多相关文章

  1. 牛客练习赛14 D比较月亮大小 (实现)

    链接:https://ac.nowcoder.com/acm/contest/82/D来源:牛客网 题目描述 点点是一名出色的狼人.众所周知,狼人只有在满月之夜才会变成狼. 同时,月亮的大小随着时间变 ...

  2. 牛客练习赛14 B 区间的连续段 (倍增)

    链接:https://ac.nowcoder.com/acm/contest/82/B来源:牛客网 区间的连续段 时间限制:C/C++ 7秒,其他语言14秒 空间限制:C/C++ 262144K,其他 ...

  3. 牛客练习赛14 E - 无向图中的最短距离 (bfs+bitset)

    一个链接:https://ac.nowcoder.com/acm/contest/82/E来源:牛客网 无向图中的最短距离 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144 ...

  4. 牛客练习赛14 A n的约数 (数论)

    链接:https://ac.nowcoder.com/acm/contest/82/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288 ...

  5. 牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 逻辑,博弈 B

    牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 https://ac.nowcoder.com/acm/contest/218/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...

  6. 牛客练习赛11 假的字符串 (Trie树+拓扑找环)

    牛客练习赛11 假的字符串 (Trie树+拓扑找环) 链接:https://ac.nowcoder.com/acm/problem/15049 来源:牛客网 给定n个字符串,互不相等,你可以任意指定字 ...

  7. 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D

    目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...

  8. 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A

    牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...

  9. 最小生成树--牛客练习赛43-C

    牛客练习赛43-C 链接: https://ac.nowcoder.com/acm/contest/548/C 来源:牛客网 题目描述 ​ 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 ...

随机推荐

  1. Hibernate游记——装备篇《一》(基础配置详解)

    Hibernate配置文件可以有两种格式,一种是 hibernate.properties ,另一种是 hibernate.cfg.xml 后者稍微方便一些,当增加hbm映射文件的时候,可以直接在 h ...

  2. react-native 适配问题

    const ScreenWidth = Dimensions.get('window').width; static DimensionsTransform(px) { // 设计图纸以750为基准 ...

  3. java中正则表达式要进行转义的字符。

    /** * 转义正则特殊字符 ($()*+.[]?\^{},|) * * @param keyword * @return */public static String escapeExprSpeci ...

  4. BT原理分析(转)

    BT种子文件结构分析,参考:http://www.cnblogs.com/EasonJim/p/6601047.html BT下载,参考:http://baike.baidu.com/item/BT下 ...

  5. The Process class relies on proc_open, which is not available on your PHP installation

    [Symfony\Component\Process\Exception\RuntimeException] The Process class relies on proc_open, which ...

  6. Android 打开其他程序

    Intent intent = new Intent(); intent.setComponent(new ComponentName("所要打开的程序包名", "所要打 ...

  7. Attempt to invoke virtual method 'void android.app.ActionBar.setTitle的解决方法

    在安卓4.4.2的关于蓝牙开发的一个sample BluetoothChat中,调试时,老是出错:Attempt to invoke virtual method 'void android.app. ...

  8. cocos2d-x step by step(2) 鼠标事件,键盘事件,等等事件

    各种小控件加载进去了,那么问题来了,这些东西如何接受事件呢? good job,let us find the answer 首先我们去看文档,官方尼玛有好多文档,而且大,全,详细,感觉还是不错的 h ...

  9. PhoneGap_百度百科

    PhoneGap编辑 PhoneGap是一个用基于HTML,CSS和JavaScript的,创建移动跨平台移动应用程序的 快速开发平台.它使开发者能够利用iPhone,Android,Palm,Sym ...

  10. ubuntu 卸载干净软件(包括配置文件)

    var/cache/apt/archives occupying huge space I am in the process of cleaning up my system. And I see ...