题目链接 http://codeforces.com/contest/798/problem/D 题解 前几天的模拟赛,居然出这种智商题..被打爆了QAQ 这个的话,考虑只有一个序列怎么做,把所有的排序取最大的当然可以,但是还有一种做法,就是两两分组之后每两个相邻的取大的!! 于是按照\(a\)排序,先取第一个,后面每两个相邻的取b较大的.做完了! 哇这怎么想出来的啊.... 代码 #include<cstdio> #include<cstdlib> #include<ios…
题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2}$,$p_{3}$,...,$p_{m}$满足 $a_{p1}+a_{p2}+a_{p3}+...+a_{p_{m}}>a_{1}+a_{2}+a_{3}+...+a_{n}$ $b_{p1}+b_{p2}+b_{p3}+...+b_{p_{m}}>b_{1}+b_{2}+b_{3}+...+b_…
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, …
题意:给你两个数列a,b,你要输出k个下标,使得这些下标对应的a的和大于整个a数列的和的1/2.同时这些下标对应的b //题解:首先将条件换一种说法,就是要取floor(n/2)+1个数使得这些数大于剩下的数.然后想到两种取法,一种是排好序选前半段.令一种取法是两个两个分组,每组取大的那个.//然后就可以(很困难地)想到一种巧妙的取法,先用一个结构体保存a,b,idx,按照a从大到小排序,先取第一个,再对剩下的每两个一组取其中b更大的.这样保证了被选出//的b一定大于剩下的b,也就满足了条件.然…
题目链接:http://codeforces.com/problemset/problem/798/D 题目大意:从长度为n的序列A和序列B中分别选出k个下表相同的数要求,设这两个序列中k个数和分别为ta,tb,两个序列总和分别为asum,bsum.要求ta*2>asum&&tb*2>bsum,k<=n/2+1. 解题思路:首先,肯定要选n/2+1的吧.我们把序列A当成第一层,序列B当成第二层.第一层:按从大到小严格排好.在第二层上:每两个取大的那一个,那最后的和肯定&g…
题目链接 题目大意 给定两个序列a,b,要求找到不多于个下标,使得对于a,b这些下标所对应数的2倍大于所有数之和. N<=100000,所有输入大于0,保证有解. 因为明确的暗示,所以一定找个. 考虑去掉取整符号,分奇偶讨论. 1 n为奇数 将a从大到小排序,首先取最大的,接着每两个数取其中b较大的. 2 n为偶数 将a从大到小排序,首先取最大的和另一个(都可以),接着每两个数取其中b较大的. #include<algorithm> #include<iostream> #i…
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二维的贪心我们可以先让它变成其中一维有序,这样只需要重点考虑另一维,就会简单很多. 首先,对于题目要求的选择元素之和两倍大与所有元素之和,我们可以转化为选择元素之和大于剩下的.然后我们可以将下标按照a从大到小排序.然后选择第一个,之后每两个一组,选择b大的一个,如果n是偶数再选择最后一个. 至于这样写…
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it…
http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking about the harshness of social inequality.…
/* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选出n/2+1个数对,使得其和的二倍大于各自的数列 思路:对数列a进行排序,因为可以选一半加1个,所以最大的那个我们选出来 然后在剩下的数列中,每隔两个选则b中较大的, 这样可以保证选出的在b中满足条件,并且在a中也满足条件 然而....我他喵的居然忘了读入b数列!!!! */ #include <c…
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int fac[N], cnt; void factor(int n) { cnt = ; int limit = sqrt(n); ; i <= limit; ++i) { ) fa…
codeforces 547E Mike and Friends 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define rep(i, a, b) for(int i=(a); i<(b); i++) #define per(i, a, b) for(int i=(b)…
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it…
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路,时间复杂度是O(mlogm) #include <cstdio> #include <iostream> #include <cstring> #include <queue> #include <vector> using namespace s…
CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive in…
[题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a[pk])>∑ai 同时2*(b[p1]+b[p2]+..+b[pk])>∑bi [题解] 两个式子都可以转化为 a[p1]+a[p2]+..+a[pk]>剩余的元素 (移项就能得到) 接着用构造的方法搞; 首先把A数组降序排; (排的时候要记录每个元素它原来的下标) 即a[i].val和a…
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1~n的不重复数字, 要求这k个数字为下标的对应a和b中的数的和乘以2的值  分别大于a和b 的数组总和. 思路:首先对a进行降序排序,然后输出最大值的下标,随后进行幅度为2的枚举,对排序后的a2~an进行选择性输出下标,(注意,排序的时候用一个新数组开两个变量,一个index,一个v进行排序,可以用…
C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful…
题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和乘以2 大于a数组全部数的总和,b也是同理. 题解:一看到这题一般会想到贪心,由于是二维的贪心,所以一定要想让一维有序,所以可以按照a先排一下序. 得到排序后的数组a',先加上a'然后在依次两两选择b大的加上. #include <iostream> #include <cstring>…
B. Mike and Shortcuts time limit per test: 3 seconds memory limit per test: 256 megabytes input: standard input output: standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some si…
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m g…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! As…
B. z-sort 题目连接: http://www.codeforces.com/contest/652/problem/B Description A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: ai ≥ ai - 1 for all even i, ai ≤ ai - 1 for all…
题目链接:http://codeforces.com/contest/707/problem/C 题目大意:给你一条边,问你能否构造一个包含这条边的直角三角形且该直角三角形三条边都为整数,能则输出另外两条边,否则输出-1“”. 解题思路:下面是我从作业帮上找的- -, 利用平方差公式令斜边为c,直角边为a.b,且b为最短边c²-a²=(c+a)(c-a)因此(c+a)(c-a)是完全平方数,且(c-a)是(c+a)的一个因数1.如果(c-a)=1,则(c+a)是完全平方数(最短边是任意大于2的奇…
题目链接 https://codeforces.com/contest/1246/problem/D 题解 首先考虑答案的下界是\(n-1-dep\) (\(dep\)为树的深度,即任何点到根的最大边数),因为每一次操作只会使一个子树内的点深度\(-1\), 也就最多使得最大深度\(-1\). 那么这个下界能否达到呢?答案是肯定的,因为考虑将过程倒过来,每次选择一个子树将它沿某条边向下移动,对于任何一棵非链的树,最深点到根的路径上一定存在分叉,因此就一定可以通过移动使得最大深度\(+1\). 考…
https://codeforces.com/contest/1202/problem/D 当时想的构造是中间两个3,然后前后的1和7组合出n,问题就是n假如是有一个比较大的质数因子或者它本身就是质数就会超长度.事实上程序会正确执行并分解成两个超大质数,不断putchar导致TLE. 正确的做法是通过3来主要组成答案,考虑133..337,中间有x个3,则有C(x,2)个组合,很明显可以发现在x=45000附近超过1e9的上限,而剩下的余数不会超过x=45000(或者在这个附近?). 考虑怎么添…
Codeforces Round #384 (Div. 2) 题目链接:Vladik and fractions Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer \(n\) he can represent fraction \(\frac{2}{n}\) as a sum of three distinct posi…
Codeforces 题面传送门 & 洛谷题面传送门 神仙构造题(不过可能我构造太烂了?) 首先考虑这个奇奇怪怪的 \(\dfrac{4}{7}\),以及这个每个点出度最多为 \(2\) 的条件有何用意.容易发现 \(4=2^2,7=1+2+4\),这启发我们通过某种方式将原图的点集分成三部分.我们考虑构造三个点集 \(A,B,C\) 满足: 对于 \(A\) 中的点 \(x\),要么其入度为 \(0\),要么所有连向它的边的另一个端点都属于 \(C\) 对于 \(B\)​ 中的点 \(x\),…
Codeforces 题目传送门 & 洛谷题目传送门 显然,直接暴力枚举是不可能的. 考虑将点按横纵坐标奇偶性分组,记 \(S_{i,j}=\{t|x_t\equiv i\pmod{2},y_t\equiv j\pmod{2}\}(i,j\in[0,1])\),说白了就是横坐标为偶数.纵坐标为偶数:横坐标为偶数.纵坐标为奇数:横坐标为奇数.纵坐标为偶数:横坐标为奇数.纵坐标为奇数的点集. 然后考虑以下算法: 若 \(S_{0,0},S_{1,1}\) 以及 \(S_{0,1},S_{1,0}\)…