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 ...
随机推荐
- C++ 编译错误记录
C++ _ZSt28__throw_bad_array_new_lengthv1 编译错误 出现场景:类似代码 vector<vector<int>> grid = {{1, ...
- 贪心/构造/DP 杂题选做Ⅲ
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...
- 洛谷 P4002 - [清华集训2017]生成树计数(多项式)
题面传送门 神题. 考虑将所有连通块缩成一个点,那么所有连好边的生成树在缩点之后一定是一个 \(n\) 个点的生成树.我们记 \(d_i\) 为第 \(i\) 个连通块缩完点之后的度数 \(-1\), ...
- 洛谷 P3214 - [HNOI2011]卡农(线性 dp)
洛谷题面传送门 又是一道我不会的代码超短的题( 一开始想着用生成函数搞,结果怎么都搞不粗来/ll 首先不妨假设音阶之间存在顺序关系,最终答案除以 \(m!\) 即可. 本题个人认为一个比较亮的地方在于 ...
- BAT的一些题
114.java中实现多态的机制是什么 答:重写,重载.方法的重写Overriding和重载Overloading是Java多态性的不同表现. 重写Overriding是父类与子类之间多态性的一种表 ...
- JAVA写入TXT
用java生成txt文件有两种方式: 1)是通过字符流(或字节流): 2)是直接调用PrintWriter类. 具体实现过程如下: 1)字符流(字节流) 代码如下: import java.io.Fi ...
- Learning Spark中文版--第三章--RDD编程(1)
本章介绍了Spark用于数据处理的核心抽象概念,具有弹性的分布式数据集(RDD).一个RDD仅仅是一个分布式的元素集合.在Spark中,所有工作都表示为创建新的RDDs.转换现有的RDD,或者调 ...
- 4.2 rust 命令行参数
从命令行读取参数 use std::env; fn main() { let args: Vec<String> = env::args().collect(); println!(&q ...
- mysql之对象创建
1 --创建表空间 2 create tablespace tablespace_name 3 innodb and ndb: 4 add datafile 'file_name' 5 innodb ...
- MyBatis(2):CRUD操作
编写接口 import com.shandx.pojo.User; import java.util.List; public interface UserMapper { <span clas ...