CodeForces 222A
来源:互联网 发布:软件安全评估方法 编辑:程序博客网 时间:2024/06/08 07:46
One day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
- Find the number that goes k-th in the current sequence and add the same number to the end of the sequence;
- Delete the first number of the current sequence.
The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 105).
The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
3 23 1 1
1
3 13 1 1
-1
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
水题,不解释。。。
#include <stdio.h>#include <iostream>#include <string.h>using namespace std;int a[100005];int main(){ int n,k; while(~scanf("%d%d",&n,&k)) { int flag=0,i; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=k;i<n;i++) if(a[i]!=a[k-1]) { flag=1; break; } if(flag) printf("-1\n"); else { for(i=k-2;i>=0;i--) if(a[i]!=a[k-1]) { printf("%d\n",i+1); break; } if(i==-1) printf("0\n"); } } return 0;}
- CodeForces 222A
- CodeForces 222A
- CodeForces-a
- Codeforces 903A A
- CodeForces 222A Shooshuns and Sequence
- Codeforces Round #222 (Div. 1) A. Maze
- [思路题] Codeforces 377A #222 (Div. 1) A. Maze
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- 蓝桥杯2014年C\C++A组-切面条
- UML之用例图
- LINUX学习总结第6篇:搭建FTP服务器
- warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead
- short int,int,unsigned int,long,long int,float,double等32位,64位各占几个字节的问题
- CodeForces 222A
- linux下装mysql
- android中目录和文件讲解
- 负数取余运算
- IT发展方向
- 第三周作业
- 编写函数查找字符串中子字符串出现的次数
- LeetCode题解:Single Number
- 从今天起,每天都要有收获,UP-14-3-23