CodeForces 222A Shooshuns and Sequence
来源:互联网 发布:电瓶车速度测试软件 编辑:程序博客网 时间:2024/05/02 04:44
题意:给出若干个数字形成一个序列,每次进行两项操作,(1).在序列末尾添加一个和第k个数字相同的数字。(2).删除第一个数字,求至少要多少次操作之后才能使得这个序列中所有数字一致。
链接:http://codeforces.com/problemset/problem/222/A
思路:规律题,考虑到第k个数字开始会进行复制,并且同时删除第一个数字(复制位置向后移动),所以,只有当第k个数字以后的所有数字相同时,才能使得这个序列中数字保持一致,并且前k-1个元素中,找到最后一个与第k个数字不同的位置n,就是需要的最少的操作次数。
注意点:
以下为AC代码:
luminous11222A -32GNU C++11Accepted154 ms388 KB2015-02-04 08:54:232015-02-04 08:54:23
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <vector>#include <deque>#include <list>#include <cctype>#include <algorithm>#include <climits>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>#include <iomanip>#include <cstdlib>#include <ctime>#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define clr(a, v) memset( a , v , sizeof(a) )#define pb push_back#define mp make_pair#define read(f) freopen(f, "r", stdin)#define write(f) freopen(f, "w", stdout)using namespace std;const double pi = acos(-1);//Problem Cint main(){ ios::sync_with_stdio( false ); int num[100005]; int n; int k; while ( cin >> n >> k ){ for ( int i = 1; i <= n; i ++ ){ cin >> num[i]; } bool flag = 0; for ( int i = k + 1; i <= n; i ++ ){ if ( num[i] != num[i-1] ){ flag = 1; break; } } if ( flag ){ cout << -1 << endl; continue; } for ( int i = k - 1; i > 0; i -- ){ if ( num[i] != num[k] ){ cout << i << endl; flag = 1; break; } } if ( ! flag ) cout << 0 << endl; }}
0 0
- CodeForces 222A Shooshuns and Sequence
- 【CodeForces】222A - Shooshuns and Sequence(思维)
- A. Shooshuns and Sequence
- Codeforces Round #137 (Div. 2) / 222A Shooshuns and Sequence (模拟)
- 【Codeforces】-#222A-KShooshuns and Sequence(思维)
- Codeforces 283A Cows and Sequence
- codeforces 301 A Yaroslav and Sequence
- 【CF】CodeForces 301A Yaroslav and Sequence
- Yaroslav and Sequence - CodeForces 301A 水题
- codeforces 301a Yaroslav and Sequence
- Codeforces 301A Yaroslav and Sequence 【思维】
- codeforces 283A. Cows and Sequence [线段树-区间更新]
- codeforces 283A - Cows and Sequence 简单数据结构模拟
- CodeForces 283A Cows and Sequence 树状数组
- Dima and Sequence CodeForces
- A. Yaroslav and Sequence
- Chloe and the sequence CodeForces
- Chloe and the sequence CodeForces
- hdu1010 Tempter of the Bone(dfs)
- DNS 协议
- Accelerated C++ Exercises Ch10
- C++学习笔记
- 观察者模式
- CodeForces 222A Shooshuns and Sequence
- 例题10-6 无关的元素 UVa1635
- C++备忘-QT(2)
- ui到底是什么?
- 0005 嘿嘿
- pat1017 Queueing at Bank
- POJ 2503 Babelfish (Trie树 或 map)
- 接口的使用和规则
- JS行间样式与非行间样式操作(及兼容性解决方法)