Codeforces 1138B(列方程枚举)】的更多相关文章

构造模拟要分情况讨论感觉不是够本质,然后官解是因为只有四个量所以可以根据限制条件列两个方程,再枚举一下解就可以了. const int maxn = 5000 + 5; int n, c[maxn], a[maxn]; vector<int> zero, two, cl, ac, ans1, ans2; int main() { cin >> n; getchar(); rep(i, 1, n) { char ch = getchar(); c[i] = ch - '0'; } g…
题意: 给你两个01串,要你选n/2个位置,使得选的位置在s1中"1"的数量等于未选的s2中"1"的数量 n<=5000,1s 思路: 设两个串中出现"00""01""10""11"的总数是A,B,C,D,我们选的个数分别是a,b,c,d 数据最多能承受n^2的暴力 根据题意,有a+b+c+d=n/2     ① c+d=B-b+D-d    ② 联立得d=B+D+a-n/2 于是…
codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成01背包,一定多读题 代码: #include <bits/stdc++.h> using namespace std; int a[800]; int main() { int n,minval,sum,tot; cin>>n; tot=0; for(int i=1;i<=n;+…
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多为多少? 题解 一开始用贪心搞,搞到一半发现需要枚举的情况太多 只能用暴力搞,即枚举被去掉的两个区间,那么如何判断去掉哪两个区间比较好? 维护去掉后剩下的点数即答案 代码 #include<bits/stdc++.h> using namespace std; int n,q,i,j,l[5005…
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom…
题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这样枚举的,但是思路超级混乱,按照r2进行贪心但是最后想想想法很荒谬. 顺序和题意一定要搞的很透彻才可以== #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struc…
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was…
一个暴力的枚举,枚举组成正多边形需要对应覆盖原先的几条边,范围为(1,n/3),然后维护最大值就可以了,注意初始化为-inf. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; ]; int main() { int n; while(~scanf("%d",&n)){ ; ;i<n…
The only difference between easy and hard versions is a number of elements in the array. You are given an array aa consisting of nn integers. The value of the ii-th element of the array is aiai. You are also given a set of mm segments. The jj-th segm…
Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and…