C. Hard Process time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a with n elements. Each element of a is either 0 or 1. Let's denote the length of the longest subsegme…
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an array a with n elements. Each element of a is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in a, consisting…
题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[i,i+x-1]里面0的个数是否小于等于k. 代码: #include<iostream> #include<cstdio> #include<vector> #include<cstring> using namespace std; ; int n,k; i…
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can i…
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line…
E. Well played! time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max…
E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected graph consisting of n vertices and  edges. Instead of giving you the edges that exist i…
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array i…
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们可以画几张图,发现每一次我们染色的最佳方法就是每次往里面多填一圈,并把上一圈给填满. 比如上图就很好地说明了这个过程,大家可以用画一下 \(n=4,n=5,n=6,n=7\),就能验证这个命题了,所以一个 \(n\times n\) 的矩阵有 \(\lfloor\frac{n}{2}\rfloor+…
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全,最后只能很蠢的暴力,把所有的AB和BA的位置求出来,能有一对AB和BA不重叠即可. #include <bits/stdc++.h> using namespace std; ]; vector<int> ab; vector<int> ba; int main() { w…
A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输出这个序列. 思路:最优的就是插入1,1与非1的数都互质. #include<bits/stdc++.h> using namespace std; int gcd(int a,int b){ ?a:gcd(b,a%b); } int main(){ ,a[],b[]; scanf("%…
http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能组成多少个位置不同的四边形 我们统计两个点之间的中点坐标  假如有n对点的中点重合 那么我们就知道这里面有(n-1)*n/2个平行四边形 就这样搞喽. PS:说实话typedef pair<double,double> pdd; 这语句让我想到了骚猪PDD 笑死了. #include<cst…
G. Castle Defense time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Thr…
F. SUM and REPLACE time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) …
You are given two integers nn and mm . Calculate the number of pairs of arrays (a,b)(a,b) such that: the length of both arrays is equal to mm ; each element of each array is an integer between 11 and nn (inclusive); ai≤biai≤bi for any index ii from 1…
E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Description For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence)…
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertice…
B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capac…
A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want…
Description Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n. Consider that m (m ≤ 4n) people occupy the seats i…
题目链接:https://codeforces.com/contest/1427/problem/B 题意 给出一个长为 \(n\) 由 W, L 组成的字符串,如果一个 W 左侧为 W,则它提供 2 分,否则为 1 分.最多可以将 \(k\) 个 L 变为 W,问字符串可以得到的最大分值. 题解 本题的关键是字符串中 W 的有无及两两构成的封闭区间长度. 如果全为 L,则字符串的最大分值为 \(max(2k-1,\ 0)\) . 如果存在 W,则每次操作都会至少增加 2 分,如果操作的为两个…
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can i…
E. Army Creation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known a…
司老大当时教了一种姿势枚举连续K个0,说实话当时比赛写这题完全蒙了 纵然后来知道思路还是写了一段时间 真的是.. 题目大意 n长度的序列,由0 1构成 我们可以改变 k个0为1 求可以得到的最长连续1序列的长度 既然求连续1 我们贪心连续k个0 枚举端点 左端点0设置为0 右端点0设置为 n+1 中间统计一下 最长长度和改变的0的位置就OK了 #include<cstdio> #include<map> //#include<bits/stdc++.h> #includ…
传送门 题意 将n个数划分为两块,最多改变一个数的位置, 问能否使两块和相等 分析 因为我们最多只能移动一个数x,那么要么将该数往前移动,要么往后移动,一开始处理不需要移动的情况 那么遍历sum[i] 如果往前移动,sum[k]+(sum[i]-sum[i-1])=sum[n]/2,k∈[1,i-1] 如果往后移动,sum[k]-(sum[i]-sum[i-1])=sum[n]/2,k∈[i+1,n] 一开始我没有考虑往后移动 时间复杂度\(O(nlog(n))\) trick 代码 #incl…
A. Co-prime Array 题意:给你一个数列,要求构造两两相邻之间的数互质的数列,可以插入的数的小于10的9次方 思路:其实可以选择靠近10的9次方的最大的三个素数.然后按我下面的方法做就可以了,我这里选的三个素数不是最大的,数据有点水,就水过了 #include<cstdio> #include<cstring> #include<cmath> ; int num[qq]; ]; int gcd(int x,int y) { ?x:gcd(y,x%y); }…
题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球的最后一个的前面 思路:首先我们想如果是第i种颜色,我们首先必须把这个颜色留下一个,留下的这个球前面的球的个数是前面颜色的总和+这个颜色数-1, 我们想这个颜色的位置数如何安排,即 C(总座位数,要安排的个数),i-1种颜色也是相同的道理,所以我们推出公式 累加球的个数 sum 当前颜色的球的个数n…
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features nn problems of distinct difficulty, the difficulties are numbered from 11 to nn. To hold a round Arkady needs nn new (not used previously) probl…
B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebran…
题目大意 求从l到r的整数中长度为n的等比数列个数,公比可以为分数 首先n=1的时候,直接输出r-l+1即可 n=2的时候,就是C(n, 2)*2 考虑n>2的情况 不妨设公比为p/q(p和q互素->既约分数) 那么等比数列为 k      k*p/q     k*(p/q)^2  .....          k*(p/q)^(n-1) 因为都是整数,所以k一定可以表示为x*q^(n-1),化简数列得 x*q^(n-1)  ........     x*p^(n-1) 也就是说,假如q &l…