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. C#动态创建接口的实现实例对象

    本文简单介绍如何动态创建接口interface的实现实例对象,包含两个知识点: 1.如何获取接口interface的所有实现实例对象? 2.如何判断实例对象的构造函数是否有参数? 准备工作 首先新建一 ...

  2. Python迭代器生成器与生成式

    Python迭代器生成器与生成式 什么是迭代 迭代是重复反馈过程的活动,其目的通常是为了逼近所需目标或结果.每一次对过程的重复称为一次"迭代",而每一次迭代得到的结果会作为下一次迭 ...

  3. C#中的异步

    什么是异步? 作为一名Web端的码农,第一次接触异步是Ajax. 异步请求后端获取数据源,js操作html的dom节点,而无需要渲染整个网页的操作. 页面上点击按钮,加载进度动画,同时发起Ajax请求 ...

  4. vcstool是什么?

    为什么会去了解vcstool,在想要手动编译并且获取ROS源码的时候,有一个Get ROS 2 code的章节中使用到了这个工具. mkdir -p ~/ros2_foxy/src cd ~/ros2 ...

  5. nodejs中的fs模块中的方法

    nodejs中的fs模块 引入模块 const fs =require("fs") 检测文件是否存在fs.stat(path,callback) fs.stat("./n ...

  6. “微信小程序从分享卡片进入,第一次获取不到用户uid、第二次能获取到用户uid”解决方法

    用uniapp开发微信小程序时,有一个需求是分享罐表详情页面给其它用户,其它用户(在已经登录的状态下)点击分享卡片可以直接跳转到该罐表详情页,且能显示自己是否已经收藏该罐表(收藏状态由用户uid和罐表 ...

  7. Redis键空间通知(keyspace notification),事件订阅

      Redis键空间通知(keyspace notification),事件订阅   应用场景:有效期优惠券.24小时内支付.下单有效事件等等. 功能概览 键空间通知使得客户端可以通过订阅频道或模式, ...

  8. Metabolomics Workfolw

    推荐R语言界的国内大佬于淼写的代谢组学workflow,包含了大部分代谢组学(以及暴露组)的数据分析方法. Meta-Workflow 主要内容包括: Sample collection Pretre ...

  9. shell 基本系统维护指令

    笔记 [1]man.passwd.su.echo命令的用法 (1)获取联机帮助 1)使用man命令可以找到特定的联机帮助页,并提供简短的命令说明.一般语法格式为: man commandname 2) ...

  10. 12-Add Digits

    寻找一个数的数根,用了暴力破解的方式,时间复杂度比较高 暂未想到O(1)的方式 Given a non-negative integer num, repeatedly add all its dig ...