题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; i…
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再看自己的代码发现有清晰的思维是多重要 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include…
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; ; con…
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; in…
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(vo…
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <iostream> using namespace std; ; const int INF = 0x3f3f3f3f; int p[MAXN…
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN]; int main(void) //Codeforce…
题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再最多的b,然而并不能保证是最多的:( */ #include <cstdio> #include <cstring> #include <string> #include <iostream> #include <algorithm> #includ…
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2个+1个,然后k个rgb...r = x + k; g = 2 * (x + z) + k; b = z + k; ans = (x + z) + k = (a[1] + a[2] + a[3]) / 3; 隔了一段时间有做到这题又不会了,看别人的解题报告水平果然没有提升,以后做题要独立思考,看别人的也要…
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; struct Card { int a, b; }card[MAXN]; bool cmp(Card x, Car…