Odd Gnome

题目描述

According to the legend of Wizardry and Witchcraft, gnomes live in burrows underground, known as gnome holes. There they dig

up and eat the roots of plants, creating little heaps of earth around gardens, causing considerable damage to them.

Mrs. W, very annoyed by the damage, has to regularly de-gnome her garden by throwing the gnomes over the fence. It is a lot of work to throw them one by one because there are so many. Fortunately, the species is so devoted to their kings that each group always follows its king no matter what. In other words, if she were to throw just the king over the fence, all the other gnomes in that group would leave.

So how does Mrs. W identify the king in a group of gnomes? She knows that gnomes travel in a certain order, and the king, being special, is always the only gnome who does not follow that order.

Here are some helpful tips about gnome groups:

• There is exactly one king in a group.

• Except for the king, gnomes arrange themselves in strictly increasing ID order.

• The king is always the only gnome out of that order.

• The king is never the first nor the last in the group, because kings like to hide themselves.

Help Mrs. W by finding all the kings!

输入

The input starts with an integer n, where 1 ≤ n ≤ 100, representing the number of gnome groups. Each of the n following lines contains one group of gnomes, starting with an integer g, where 3 ≤ g ≤ 1 000,representing the number of gnomes in that group. Following on the same line are g space-separated integers, representing the gnome ordering. Within each group all the integers (including the king) are unique and in the range [0, 10 000]. Excluding the king, each integer is exactly one more than the integer preceding it.

输出

For each group, output the king’s position in the group (where the first gnome in line is number one).

样例输入

3
7 1 2 3 4 8 5 6
5 3 4 5 2 6
4 10 20 11 12

样例输出

5
4
2

题解

给出一个序列,序列中有一个King,除了King其他都是递增的,找出King的位置

King不会在第一个和最后一个的位置

那很明显就是枚举2--n-1的位置,找出满足以下两个条件的位置

1.a[i-1] < a[i+1]

2.a[i] > a[i + 1] && a[i] > a[i - 1] 或者 a[i - 1] < a[i + 1]&& a[i] < a[i + 1]

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
const int maxn = 1000005;
int a[maxn];
int n;
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 2; i < n; i++)
if ((a[i] > a[i + 1] && a[i] > a[i - 1] && a[i - 1] < a[i + 1] )
||( a[i - 1] < a[i + 1]&& a[i] < a[i + 1] && a[i] < a[i - 1])) {
printf("%d\n", i);
break;
}
}
return 0;
}

upc组队赛6 Odd Gnome【枚举】的更多相关文章

  1. upc组队赛6 GlitchBot【枚举】

    GlitchBot 题目描述 One of our delivery robots is malfunctioning! The job of the robot is simple; it shou ...

  2. Odd Gnome【枚举】

    问题 I: Odd Gnome 时间限制: 1 Sec  内存限制: 128 MB 提交: 234  解决: 144 [提交] [状态] [命题人:admin] 题目描述 According to t ...

  3. upc组队赛17 Bits Reverse【暴力枚举】

    Bits Reverse 题目链接 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ...

  4. upc组队赛12 Cardboard Container【枚举】

    Cardboard Container Problem Description fidget spinners are so 2017; this years' rage are fidget cub ...

  5. upc组队赛2 Super-palindrome【暴力枚举】

    Super-palindrome 题目描述 You are given a string that is consisted of lowercase English alphabet. You ar ...

  6. upc组队赛5 Ground Defense【枚举】

    Ground Defense 题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced ...

  7. upc组队赛16 Melody【签到水】

    Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...

  8. upc组队赛15 Lattice's basics in digital electronics【模拟】

    Lattice's basics in digital electronics 题目链接 题目描述 LATTICE is learning Digital Electronic Technology. ...

  9. upc组队赛6 Bumped!【最短路】

    Bumped! 题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his retur ...

随机推荐

  1. Linux下安装xwindow图形界面

    执行命令 yum -y groupinstall Desktop yum -y groupinstall "X Window System" 然后执行"startx&qu ...

  2. js对象传到后台ACTION使用

    需的包 <script type="text/javascript" src="s"></script>gson-1.2.3.jar谷歌 ...

  3. Python中多线程的阻塞问题

    在使用Queue模块+多线程模拟生产者+消费者问题时,遇到了一个小问题,现在记录下来.供可能会遇到类似问题的初学者们参考. 该问题的完整参考代码如下.主要实现了以下的功能:在一个线程中,开启生产者模式 ...

  4. 详解Linux运维工具:运维流程管理、运维发布变更、运维监控告警

     概述 应用上线后,运维工作才刚开始,具体工作可能包括:升级版本上线工作.服务监控.应用状态统计.日常服务状态巡检.突发故障处理.服务日常变更调整.集群管理.服务性能评估优化.数据库管理优化.随着应用 ...

  5. Java +selenium Navigation接口介绍

    Navigation接口主要实现对浏览器的前进.后退.打开网址.刷新当前页面等操作的. void back():就是操作当前页面后退,相当于网页的后退按钮. void forward():就是操作当前 ...

  6. Infinity、-Infinity和NaN

    首先看看这三个代表什么: Infinity:正无穷大 -Infinity:负无穷大 NaN:Not a Number 当float或double类型的数除零时, 当被除数为非零值时,结果为无穷大 当被 ...

  7. 常用缓存淘汰算法(LFU、LRU、ARC、FIFO、MRU)

    缓存算法是指令的一个明细表,用于决定缓存系统中哪些数据应该被删去. 常见类型包括LFU.LRU.ARC.FIFO.MRU. 最不经常使用算法(LFU): 这个缓存算法使用一个计数器来记录条目被访问的频 ...

  8. Hibernate入门教程(二):Hibernate核心API

    1.Configuraction onfiguration configuration = new Configuration(); configuration.configure(); 到src下面 ...

  9. C++中逻辑操作符的重载分析

    1,逻辑运算符的原生语义: 1,操作数只有两种值(true 和 false): 1,C 语言中只有非 0 和 0: 2,逻辑表达式不用完全计算就能确定最终值: 1,短路规则: 3,最终结果只能是 tr ...

  10. 银行贷款(dp)

    链接:https://www.nowcoder.com/acm/contest/79/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536KS ...