Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题
2015-06-28 00:49
471 查看
C. String Manipulation 1.0
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/555/problem/ADescription
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5.
In one second, you can perform one of the two following operations:
Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
[b]Input[/b]
The first line contains an integer k (1 ≤ k ≤ 2000). The second line
contains a non-empty string s, consisting of lowercase Latin letters, at
most 100 characters long. The third line contains an integer n
(0 ≤ n ≤ 20000) — the number of username changes. Each of the next n
lines contains the actual changes, one per line. The changes are written
as "pi ci" (without the quotes), where pi (1 ≤ pi ≤ 200000) is the
number of occurrences of letter ci, ci is a lowercase Latin letter. It
is guaranteed that the operations are correct, that is, the letter to be
deleted always exists, and after all operations not all letters are
deleted from the name. The letters' occurrences are numbered starting
from 1.
[b]Output[/b]
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
[b]Sample Input[/b]
3 2
2 1 2
1 3
[b]Sample Output[/b]
1
HINT
[b]题意[/b]
俄罗斯套娃,每秒钟可以把一个娃娃扔进一个大娃娃里面
或者把一个娃娃从大娃娃中拿出来
注意脑补俄罗斯套娃的样子,这个不能从中间断的……
[b]题解:[/b]
只留下从1开始连续的链,其他全拆掉就好了= =
[b]代码[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 2000001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; const int inf=0x3f3f3f3f; inline ll read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** vector<ll> a[maxn]; int main() { int n=read(),k=read(); int tmp=0; for(int i=0;i<k;i++) { int t=read(); for(int j=0;j<t;j++) { int kiss=read(); a[i].push_back(kiss); } } ll ans=0; for(int i=0;i<k;i++) { if(a[i][0]==1) { for(int j=1;j<a[i].size();j++) { if(a[i][j]==a[i][j-1]+1) ans++; else break; } } } cout<<(n-1-ans)*2-(k-1)<<endl; }
相关文章推荐
- spring学习笔记(1)——spring介绍
- [Codeforces Round #310 (Div. 2)] #ABC题解
- Codeforces Round #310 (Div. 2)
- 博客订阅Feed地址托管到GAE
- LeetCode——Search for a Range
- DP项目开发随记5-攀爬初步完成
- 有了装逼大全,谁也阻止不了我装逼了
- 定义一个Block
- PHP本地实现虚拟域名访问:Apache虚拟主机配置
- leetcode解题报告228——Summary Ranges
- Zxing在CameraManager.get().closeDriver()报错
- Python 3.5 终于将 Type Hint(类型提示)官方化
- php页面静态化—优化页面响应时间
- Android横向滑动选项卡
- [综] Sparse Representation 稀疏表示
- SDWebImage
- 解决安装laravel/homestead vagrant环境报"A VirtualBox machine with the name 'homestead' already exists."的错误
- struts2 json includeProperties返回list为空
- 苹果Mac OS系统终端命令大全介绍
- Codeforces Round #310 (Div. 1) A B C