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. HEAD请求

    平时用的最多的无外乎POST GET 很少用的HEAD 这次HEAD请求使用场景:判断资源是否存在

  2. 洛谷 P1972 [SDOI2009]HH的项链——树状数组

    先上一波题目 https://www.luogu.org/problem/P1972 这道题是询问区间内不同数的个数 明显不是正常的数据结构能够维护的 首先考虑 因为对于若干个询问的区间[l,r],如 ...

  3. 设置xampp开机自动启动

    l  设置xampp开机自动启动: 1)vi /etc/init.d/xampp.sh 增加:#!/bin/sh     /opt/lampp/lampp start 2)vi /etc/rc.d/r ...

  4. intellij中maven不能导入pom文件中指定的jar包

    pom文件配置依赖的jar包版本,可以有默认的版本,如下 <profiles> <profile> <id>default_version</id> & ...

  5. web编程非常实用的在线工具大全---转载

    代码对比/归并: http://www.matools.com/compare 正则表达式: http://www.matools.com/regex js/css压缩: http://www.mat ...

  6. canvas时间粒子

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 一个简化的插件框架c#

    利用MEF实现插件加载. 定义了一套接口,分别实现插件主界面,插件,业务插件等. 整套加载完全使用MEF2. 所有插件分开,包括主界面也是插件实现. 用一个应用程序,只有Main和插件加载方法.我管它 ...

  8. Codeforces 1179D 树形DP 斜率优化

    题意:给你一颗树,你可以在树上添加一条边,问添加一条边之后的简单路径最多有多少条?简单路径是指路径中的点只没有重复. 思路:添加一条边之后,树变成了基环树.容易发现,以基环上的点为根的子树的点中的简单 ...

  9. 人脸识别课件需要安装的python模块

    Python3.6安装face_recognition人脸识别库 https://www.jianshu.com/p/8296f2aac1aa

  10. eclipse里部署struts2

    Struts2是一个比较出色的基于MVC设计模式的框架,是由Struts1和WebWork发展而来的,性能也比较稳定,现在是Apache软件基金会的一个项目,下面就来配置Struts2进行初始化的开发 ...