A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There were n groups of students which came to write a training contest. A group is either one person who can write the…
Codeforces Round #452 (Div. 2) A Splitting in Teams 题目链接: http://codeforces.com/contest/899/problem/A 思路: 统计1和2出现的次数,尽量使2能够与1匹配尽可能多用.假设1再匹配完2之后还有剩余,则求出3个1可组成的方案 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn =…
题 OvO http://codeforces.com/contest/899/problem/E Codeforces Round #452 (Div. 2) - e 899E 解 用两个并查集(记为fa和ma), fa用于更新可以合并在一起的段,维护每个段的左端点,右端点,中间有多少个相同的值,和这个段的值得是什么, ma用于跳跃, 具体来说 例如 这组数据 标上序号(第三行是序号) 1.那么首先合并4个5(10-13),显然9所在的段和14所在的段不能合并 那么把13指向9( ma[13]…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bits/stdc++.h> using namespace std; const int N = 2e5; int n; int a[3]; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", "r", st…
C. Dividing the numbers Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the inte…
第一次打..(太弱(+99积分是几个意思 A 题意:一堆数,只有1和2,问最多凑出多少个3. 分情况即可 #include<cstdio> int main(){ int a=0,b=0,k,n; scanf("%d",&n); while(n--)scanf("%d",&k),k==1?++a:++b; if(a<=b)printf("%d\n",a); else printf("%d\n"…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 闰,平,平 平,闰,平 平,平,闰 平,平,平 4种情况都考虑到就好. 可能有重复的情况. 但是没关系啦. [代码] #include <bits/stdc++.h> using namespace std; const int N = 24; int p[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; int r[12] = {31,29,31,30,31,30,31,31,30,3…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两组的和,如果一样的话,分散在两组 差为1否则差为0 n为奇数 l = 2,r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两组的和,如果一样的话,分散在两组 差为0(把1放在那个较少的组) 否则,差为1 1随意放在哪一组都可以 [代码] #in…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让N乘2->a 然后看一下位数是多少. 假设有x位(x>=2) 则(0..(a%10-1) ) + (99..9)[x-1个]都是合法的 转化为1..N里面有多少对,它们的和为x x总是为奇数 若x-1<=n 先减去1 1 ... x-1 x-1为偶数 1..4 答案为4/2 若x-1>n 则让temp = x-n; 如果temp<n 则temp + n是等于x的 同时temp+1 + n-1也是等于x的 .…
题意:有\(n\)个人,每个人的能力值是\(a_i\),现在你想将这些人分成\(k\)组(没必要全选),但是每组中最高水平和最低水平的人的能力差值必须\(\le 5\),问最多能选多少人. 题解:想了一会发现纯贪心写不了,必须要用dp来求解,先排序,我们记\(dp[i,j]\),表示前\(i\)个人分成\(j\)组选的最多的人数,当便遍历到某个人的时候,他可以不加任何组\(dp[i][j]=dp[i-1][j]\),否则如果他要加入,那么我们往前找到第一个与其能力差值\(>5\)的位置\(pos…