CF205A Little Elephant and Rozdil 题解
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 题解的更多相关文章
- codechef Little Elephant and Permutations题解
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numb ...
- codechef Little Elephant and Bombs题解
The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy bui ...
- CF221A Little Elephant and Function 题解
Content 小象有一个序列 \(a_1,a_2,a_3,...,a_n\) (其中 \(a_i=i\))和一个递归函数 \(f(x)\).\(f(x)\) 的操作如下: 初始时,\(x=n\). ...
- Codeforces Round #129 (Div. 2)
A. Little Elephant and Rozdil 求\(n\)个数中最小值的个数及下标. B. Little Elephant and Sorting \[\sum_{i=1}^{n-1}{ ...
- CodeChef-LECOINS Little Elephant and Colored Coins 题解
CodeChef-LECOINS Little Elephant and Colored Coins Little Elephant and Colored Coins The Little Elep ...
- Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp
Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...
- 『题解』Codeforces220B Little Elephant and Array
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description The Little Elephant loves playing with ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- 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 ...
随机推荐
- Chrome 插件特性及实战场景案例分析
一.前言 提起Chrome扩展插件(Chrome Extension),每个人的浏览器中或多或少都安装了几个插件,像一键翻译.广告屏蔽.录屏等等,通过使用这些插件,可以有效的提高我们的工作效率:但有时 ...
- 【Mysql】三大日志 redo log、bin log、undo log
@ 目录 redo log(物理日志\重做日志) binlog(逻辑日志/归档日志) update语句执行流程 Uodolog(回滚日志/重做日志) undo log+redo log保证持久性 re ...
- github文件下载加速器
https://d.serctl.com/?dl_start
- Roslyn+T4+EnvDTE项目完全自动化 (一)
前言 以前做一个金融软件项目,软件要英文.繁体版本,开始甲方弄了好几个月,手动一条一条替换,发现很容易出错,因为有金融专业术语,字符串在不同语义要特殊处理,第三方工具没法使用.最后我用Roslyn写了 ...
- 计算机网络 | 从 ChanelOption 到 Netty 底层
概述 ChannelOption 是 Netty 中在构建引导类时可以填写的构建 Channel 的选项 其可以分为两部分,一部分为控制 Netty 自身底层运行的选项:另一部分则是操作系统创建 so ...
- php-fpm一个PHPFastCGI进程管理器
PHP-FPM(FastCGI Process Manager:FastCGI进程管理器)是一个PHPFastCGI管理器,对于PHP 5.3.3之前的php来说,是一个补丁包 [1] ,旨在将Fa ...
- 准确率,召回率,F值,ROC,AUC
度量表 1.准确率 (presion) p=TPTP+FP 理解为你预测对的正例数占你预测正例总量的比率,假设实际有90个正例,10个负例,你预测80(75+,5-)个正例,20(15+,5-)个负例 ...
- 关于Stream的使用
引言 Stream 是 Java8 中处理集合的关键抽象概念,它可以指定你希望对集合进行的操作,可以执行非常复杂的查找.过滤和映射数据等操作.使用Stream API 对集合数据进行操作,就类似于使用 ...
- C#时间选择
<script type="text/javascript" src="http://www.shicishu.com/down/WdatePicker.js&qu ...
- day18定时任务
day18定时任务 什么是定时任务 类似日常生活之中的闹钟:主要用于定时执行某些命令,达到定时处理数据的作用. 作用: 1.类似生活中使用的闹钟 2.可以自动完成操作命令 3.定时备份系统数据信息 定 ...