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 ...
随机推荐
- 8.3 k8s部署jenkins,通过pv/pvc结合NFS服务器持久化
1.制作jenkins docker镜像 1.1 下载jenkins wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.30 ...
- Codeforces 710F - String Set Queries(AC 自动机)
题面传送门 题意:强制在线的 AC 自动机. \(n,\sum|s|\leq 3\times 10^5\) 如果不是强制在线那此题就是道 sb 题,加了强制在线就不那么 sb 了. 这里介绍两种做法: ...
- Codeforces 306D - Polygon(随机化+乱搞)
Codeforces 题目传送门 & 洛谷题目传送门 中考终于结束了--简单写道题恢复下状态罢. 首先这一类题目肯定没法用一般的方法解决,因此考虑用一些奇淫的乱搞做法解决这道题,不难发现,如果 ...
- Excel-满足指定条件并且包含数字的单元格数目,DCOUNT()
DCOUNT函数 函数名称:DCOUNT 主要功能:返回数据库或列表的列中满足指定条件并且包含数字的单元格数目. 使用格式:DCOUNT(database,field,criteria) 参数说明:D ...
- 8 — springboot中静态资源处理方式 - 前后端分离 这没屁用
7中说了thymeleaf,哪还有一个目录是static 那么就来研究一下静态资源 静态资源,springboot底层是怎么去装配的,都在WebMvcAutoConfiguration有答案,去看一下 ...
- 日常Java 2021/10/19
Java集合框架 Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射. Collection接口又有3种子类型,Li ...
- Flink(四)【IDEA执行查看Web UI】
1.导入依赖 <!-- flink Web UI --> <dependency> <groupId>org.apache.flink</groupId> ...
- ComponentScan注解的使用
在项目初始化时,会将加@component,@service...相关注解的类添加到spring容器中. 但是项目需要,项目初始化时自动过滤某包下面的类,不将其添加到容器中. 有两种实现方案, 1.如 ...
- UIButton总结
UIButton 1. 功能 既能显示文字,又能显示图片(能显示2张图片,背景图片.内容图片) 长按高亮的时候可以切换图片\文字 直接通过addTarget...方法监听点击 2. 状态 normal ...
- 微服务中心Eureka
一.简介 Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS(AWS 是业务流程管理开发平台AWS Enterprise BPM Platform ...