codeforces 982A Row】的更多相关文章

题意: 一个01串是否合法满足以下两个要求: 1.没有两个相邻的1: 2.在满足第一个条件的情况下,不能再放下更多的1. 判断一个给定的串是否合法. 思路: 最近cf的A怎么都这么坑啊... 首先是判断长度为1的情况,为0是No,1就是Yes: 然后判断长度大于1的,有2种一般情况,11,000 2种特殊情况,开头两个0,结尾两个0. 代码: #include <stdio.h> #include <string.h> #include <algorithm> usin…
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能出现一次. 策略: 延伸:这里指的延伸如当发现1-1如果以最后出现重叠的数为右边界则就表示左延伸,若以1.0.1..0第二个0前一个位置作为右边界就为右延伸: 开始时想是右延伸,考虑到可能只出现一组两个数相同,认为向左延伸会出错,但是直接WA了之后,发现这并不是题目的坑点(其实只需将最后一组改成左右…
link:http://codeforces.com/contest/347/problem/A 开始看起来很复杂的样子,但是刚写下样例,就发现因为中间的都消去了,其实起作用的就是最大值和最小值=_= #include <cstdio> #include <algorithm> using namespace std; ]; int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt", "r"…
题目链接:http://codeforces.com/problemset/problem/347/A 题目意思:给出一个序列 a1, a2, ..., an , 通过重排序列,假设变成 x1, x2, ..., xn ,使得 (x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn)   的和最大.输出这个重排后的序列,不过这个序列在满足得到这个最大和的基础上字典序的排序是最小的.字典序排列即: Sequence x1, x2, ... , xp is lexico…
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number…
题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意 给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对儿相等的数字,每个数字都属于某个部分,输出划分的部分数量以及对应区间.  思路 很简单一道题,输入的数据都不用存的,输入一个检测一个就好了,用map打标记,用容器存一下要输出的区间端点值,最后挨个儿输出就好了 代码如下: #include<iostream> #include<map>…
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it cont…
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number …
题目链接:http://codeforces.com/problemset/problem/402/B 题目意思:给出n个数和公差k,问如何调整使得ai + 1 - ai = k.(1 ≤ i < n),即等差数列,求出最少的调整次数.(调整的操作包括向一个数添加或者减少某个数,使得后一个数-前一个数 = 公差). 方法一: 对于每一个数ai,求出以ai为基准,在ai之前和在ai之后不满足等差数列的个数.直到扫描整个序列结束,选出个数最少的,,即调整的次数最少,然后再一次扫描整个序列,算出每一个…
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it cont…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let'…
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); ; i < n; ++ i ) cin >>a[i]; sort(a.begin(),a.end()); swap(a[],a[n-]); ; i < n; ++i) co…
水题,每当出现重复就分割开来,最后留下的尾巴给最后一段 #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include<vector> #include<map> #include<string> #include<iostream> #include<algorithm> using namespace std…
题意:给定 n 个数,让你找出一个排列满足每个数相邻作差之和最大,并且要求字典序最小. 析:这个表达式很简单,就是把重新组合一下,就成了x1-xn,那么很简单,x1是最大的,xn是最小的,中间排序就好. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <cstring> using namespace std;…
给你一个序列,让你求(x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).值最大的一个序列,我们化简一下公式就会发现(x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn). = x1 - xn, 也就是说只有第一个和最后一个是确定的,其他的随便了!  也不是了, 还要让你按字典序最小的排列,也就是说其他的是按飞递减序排列的,简单的一次排序就OK了. //2013-09-21-09.07 #include <stdio.h> #i…
题意:给定n个数,要求修改其中最少的数,使得这n个数满足ai + 1 - ai = k. 分析: 暴力,1000*1000. 1.这n个数,就是一个首项为a1,公差为k的等差数列.k已知,如果确定了a1,就能确定整个数列. 2.1 ≤ ai ≤ 1000,因此,可以从1~1000中枚举a1,将形成的数列与给定的数列比较,统计两数列对应下标中不同数字的个数. 3.不同数字的个数最少的那个数列就是最终要修改成的数列,然后输出对应下标的那个数的变化值即可. #include<cstdio> #inc…
题意:给你两个数组\(a\)和\(b\),对于\(j=1,...,m\),找出\(a_1+b_j,...,a_n+b_j\)的\(gcd\). 题解:我们很容易的得出\(gcd\)的一个性质:\(gcd(a,b)=gcd(a,b-a),gcd(a,b,c)=gcd(a,b-a,c-b)\)以此往后类推, 那么对于此题,我们要求\(gcd((a_1+b_j),(a_2+b_j),...,(a_n+b_j))=gcd(a_1+b_j,a_2-a_1,...,a_{n}-a_{n-1})\).所以我们…
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his info…
E - Qwerty78 Trip Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100947E Description standard input/output Announcement   Statements Qwerty78 is a well known programmer (He is a member of the I…
题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要填的那个数填进去,然后循环比较每行每列以及对角线的和是否相等,题目提交上去卡了几次要注意几点 注意:1.答案数据范围$1\leq x \leq 1e18$,要用 long long 2.特殊情况,$n \equiv 1$时,由于一定有要填的数,所以一定有解 3.反正就是要注意看清楚题目和数据边界情况…
D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: standard input output :standard output The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is loca…
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132014-acmicpc-northwestern-european-regional-contest-nwerc-13-en.pdf D - Diagrams & TableauxA Young diagram is an arrangement of boxes in rows and colum…
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as foll…
B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|. Limak is a police officer…
B. Vanya and Food Processor 题目链接:http://codeforces.com/contest/677/problem/B Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters…
A. Vanya and Fence 题目连接:http://codeforces.com/contest/677/problem/A Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exc…
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of sizen × m and consists of blocks of size 1 × 1. Each block o…
E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n),…
题目链接:http://codeforces.com/problemset/problem/446/B #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e3+3; int matrix[N][N]; ll row[N],col[N]; ll dpr[N*N],dpc[N*N]; priority_queue <ll> q; int main() { ll n,m,k,p;…
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standard input output: standard output Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty mul…