Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题
C. String Manipulation 1.0
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/555/problem/A
Description
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.
Input
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.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Sample Input
3 2
2 1 2
1 3
Sample Output
1
HINT
题意
俄罗斯套娃,每秒钟可以把一个娃娃扔进一个大娃娃里面
或者把一个娃娃从大娃娃中拿出来
注意脑补俄罗斯套娃的样子,这个不能从中间断的……
题解:
只留下从1开始连续的链,其他全拆掉就好了= =
代码
//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[];
const int inf=0x3f3f3f3f;
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} //************************************************************************************** vector<ll> a[maxn];
int main()
{
int n=read(),k=read();
int tmp=;
for(int i=;i<k;i++)
{
int t=read();
for(int j=;j<t;j++)
{
int kiss=read();
a[i].push_back(kiss);
}
}
ll ans=;
for(int i=;i<k;i++)
{
if(a[i][]==)
{
for(int j=;j<a[i].size();j++)
{
if(a[i][j]==a[i][j-]+)
ans++;
else
break;
}
}
}
cout<<(n--ans)*-(k-)<<endl;
}
Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题的更多相关文章
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
随机推荐
- Delphi 异或,英文为exclusive OR,或缩写成xor
异或,英文为exclusive OR,或缩写成xor 异或(xor)是一个数学运算符.它应用于逻辑运算.异或的数学符号为“⊕”,计算机符号为“xor”.其运算法则为: a⊕b = (¬a ∧ b) ∨ ...
- 容器的范围 .xml
pre{ line-height:1; color:#f0caa6; background-color:#2d161d; font-size:16px;}.sysFunc{color:#e54ae9; ...
- oracle 定时任务(DBMS_JOB)
示例如下: -- 每隔一分钟执行存储过程p1 create or replace procedure p2 as job_num number; begin dbms_job.submit(job_n ...
- cocos2d-x CCEditBox 字符不能显示完全的bug
cocos2d-x CCEditBox 字符不能显示完全的bug (cocos2dx版本 2.2.0)用CCEditBox制作帐号输入框,当输入的内容超过框的宽度时,框里面不会显示当前输入的字符,显示 ...
- 一.JSP开发的工具下载与环境搭建
JSP技术的强势: (1)一次编写,到处运行.在这一点上Java比PHP更出色,除了系统之外,代码不用做任何更改. (2)系统的多平台支持.基本上可以在所有平台上的任意环境中开发,在任意环境中进行系统 ...
- 面试java简答题
1. sleep() 和 wait() 有什么区别? 答:1.这两个方法来自不同的类分别是Thread和Object 2.最主要是sleep方法没有释放锁,而wait方法释放了锁,使得其他 ...
- POJ 3164 Command Network (最小树形图)
[题目链接]http://poj.org/problem?id=3164 [解题思路]百度百科:最小树形图 ]里面有详细的解释,而Notonlysucess有精简的模板,下文有对其模板的一点解释,前提 ...
- js运动 摩擦运动
<!DOCTYPE HTML> <HTML> <meta http-equiv="Content-Type" content="text/h ...
- hdu 5491 The Next (位运算)
http://acm.hdu.edu.cn/showproblem.php?pid=5491 题目大意:给定一个数D,它的二进制数中1的个数为L,求比D大的数的最小值x且x的二进制数中1的个数num满 ...
- servlet-3_0-final-spec
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="http://w ...