Content

有一头小象住在 \(\texttt{Rozdil}\) 小镇里,它想去其他的小镇旅行。

这个国家一共有 \(n\) 个小镇,第 \(i\) 个小镇距离 \(\texttt{Rozdil}\) 小镇的距离为 \(a_i\)。小象想去往离 \(\texttt{Rozdil}\) 最近的小镇,但是,如果这样的小镇不止一个的话,那么小象就会继续待在 \(\texttt{Rozdil}\)。

现在,它想问你这个距离 \(\texttt{Rozdil}\) 最近的小镇的编号,或者,如果这样的小镇不止一个的话,请输出 \(\texttt{Still Rozdil}\)。


一句话题意:给出 \(n\) 个数 \(a_1,a_2,...,a_n\),请找到最小的数的编号,如果最小数有多个,输出 \(\texttt{Still Rozdil}\)。

数据范围:\(1\leqslant n\leqslant 10^5,1\leqslant a_i\leqslant 10^9\)。

Solution

这道题目看上去比较麻烦,实则非常简单,就是让我们找到最小数的编号罢了。

介于 \(n\leqslant 10^5\),我想到了一个很容易实现的算法:先求出这个最小数,然后再在数列中扫一遍,扫出这个最小数出现的次数并标记它的位置,最后判断并输出。复杂度 \(\mathcal{O}(n)\),足以通过本题。

Code

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; int n, a[100007], minx = 0x3f3f3f3f, minans, cnt; int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
minx = min(minx, a[i]);
}
for(int i = 1; i <= n; ++i)
if(a[i] == minx) minans = i, cnt++;
if(cnt > 1) printf("Still Rozdil");
else printf("%d", minans);
}

CF205A Little Elephant and Rozdil 题解的更多相关文章

  1. codechef Little Elephant and Permutations题解

    The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numb ...

  2. codechef Little Elephant and Bombs题解

    The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy bui ...

  3. CF221A Little Elephant and Function 题解

    Content 小象有一个序列 \(a_1,a_2,a_3,...,a_n\) (其中 \(a_i=i\))和一个递归函数 \(f(x)\).\(f(x)\) 的操作如下: 初始时,\(x=n\). ...

  4. Codeforces Round #129 (Div. 2)

    A. Little Elephant and Rozdil 求\(n\)个数中最小值的个数及下标. B. Little Elephant and Sorting \[\sum_{i=1}^{n-1}{ ...

  5. CodeChef-LECOINS Little Elephant and Colored Coins 题解

    CodeChef-LECOINS Little Elephant and Colored Coins Little Elephant and Colored Coins The Little Elep ...

  6. Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp

    Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...

  7. 『题解』Codeforces220B Little Elephant and Array

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description The Little Elephant loves playing with ...

  8. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  9. Codeforces Round #136 (Div. 1)C. Little Elephant and Shifts multiset

    C. Little Elephant and Shifts Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/pro ...

随机推荐

  1. [loj3048]异或粽子

    先对其求出前缀异或和,然后$o(k)$次枚举,每次选择最大值,考虑如何维护可以全局开一个堆,维护出每一个点的最大值的最大值,那么相当于要在一个点中删去一个点再找到最大值将这些删去的点重新建成一颗tri ...

  2. nginx安装与配置3-反向代理两台

    1.nginx 反向代理 两台tomcat 2.8080.8081 启动tomcat 记住每个tomcat都有两个端口不要出现tomcat端口占用情况 3.启动项目访问,不报错可以访问 4.在每个to ...

  3. es插件安装

    首先安装找到一样版本的地址: Release v7.6.1 · medcl/elasticsearch-analysis-ik (github.com) 下载最上面的编译版 将文件解压到plugins ...

  4. linux 同时执行多个命令及几个基础命令

    先后不同的命令用分号:隔开即可 基础命令: 1.cd 进入目录 /代表根目录,.代表当前目录,..代表上一级目录 2.ls 显示当前目录下的所有文件和文件夹 -F区分目录和文件,文件后边是*代表可执行 ...

  5. 使用 CSS 轻松实现一些高频出现的奇形怪状按钮

    背景 在群里会有同学问相关的问题,怎么样使用 CSS 实现一个内切角按钮呢.怎么样实现一个带箭头的按钮呢? 本文基于一些高频出现在设计稿中的,使用 CSS 实现稍微有点难度和技巧性的按钮,讲解使用 C ...

  6. 常见 js 数组方法使用详解

    数组常用方法总结 concat filter map some every reduce sort includes join some every 语法:array.every(function(c ...

  7. 总结HashSet以及分析部分底层源码

    总结HashSet以及分析部分底层源码 1. HashSet继承的抽象类和实现的接口 继承的抽象类:AbstractSet 实现了Set接口 实现了Cloneable接口 实现了Serializabl ...

  8. JAVA中数组的基本概念与用法

    JAVA中数组的基本概念与用法 1. 数组的定义与特点 数组的一种引用数据类型 数组中可以同时存放多个数据,但是数据的类型必须统一 数组的长度在开始时就需要确定,在程序运行期间是不可改变的 虽然可以使 ...

  9. 【leetcode】337. House Robber III

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  10. window ntp服务

    一.确定服务端和客户端处于同一网段,能相互 Ping 通. 二.服务器端(Server)配置 1.选择一台服务器(Windows 系统)作为时间同步服务器: 2.Win + R (运行 cmd 命令行 ...