![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心
morejarphone
这个作者很懒,什么都没留下…
展开
-
HDU3697(贪心)
Bi的范围比1000大,改成5000就过了。 #include #include #include using namespace std; #define maxn 3111 struct node { double l, r; }p[maxn]; int n; bool vis[maxn]; int main () { while (cin >> n && n)原创 2015-10-23 11:08:01 · 341 阅读 · 0 评论 -
codeforces 732D (二分 贪心)
题目链接:点击这里题意:给出n天,以及每天能考的科目,给出每个科目需要备考的天数。每一天可以选择备考某一门科目或者考试通过某一门科目(备考天数足够)。求通过所有科目的最少天数。二分天数mid,然后对于前mid天贪心check。具体就是从mid往前扫,如果有没有考试过的科目就选择在这一天考,否则用来备考。 最后从前往后依次判断备考是否足够即可。#include <cstdio> #include <原创 2016-10-18 20:41:51 · 534 阅读 · 0 评论 -
HDU 4912 (贪心)
题目链接:点击这里题意:在一棵树上给出m个链<u,v><u,v>, 求出最多能够选择多少个链使得所有的链都没有交点。根据lca自底向上贪心即可。#include <cstring> #include <iostream> #include <cstdio> #include <cmath> #include <algorithm>using namespace std; #define maxn 1原创 2016-07-07 22:54:03 · 371 阅读 · 0 评论 -
HDU 4915 (贪心)
题目链接:点击这里题意:给出一个序列, 其中含有左右括号或者问号, 问号既可以是左括号也可以是右括号。 求合法序列是唯一存在还是不存在还是存在多种。定义一个数组aa和它的前缀序列sumsum, 左括号对应下标的ai=1a_i=1, 右括号对应下标的ai=−1a_i=-1, 一个括号序列合法当且仅当:f(x)={sumi≥0sumn=0(1≤i≤n) f(x)=\left\{ \begin{align原创 2016-07-07 23:08:12 · 489 阅读 · 0 评论 -
HDU 4968 (贪心)
题目链接:点击这里题意:给出n门课的平均分,计算可能的最大和最小的GPA。最大的GPA可以这么构造,先使得每一门都是60分,然后每次多余的分数给一门课加到85 。最小的GPA也类似,先使得每一门是69,然后多余的分数每次给一门加到100 。#include <bits/stdc++.h> using namespace std; #define maxn 111int ave, n; double原创 2016-06-27 09:29:20 · 357 阅读 · 0 评论 -
HDU 5360 (贪心 优先队列)
题意:每个人都有一个答应的区间,如果邀请他的时候答应的人数在区间内, 他就会答应.求使得答应人数最多的邀请顺序. 考虑这样的贪心:对于所有左区间满足的人中选择右区间最小的.这样就可以用 一个优先队列维护可行的人了.最后把剩下的人放最后一起输出. #include using namespace std; #define maxn 111111 struct node { int原创 2016-05-31 22:18:08 · 371 阅读 · 0 评论 -
codeforces 659C (贪心 水~)
C. Tanya and Toys time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland recently a new collection of to原创 2016-04-01 16:19:04 · 412 阅读 · 0 评论 -
codeforces 604B (贪心)
B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin Sun wants to move his precious collec原创 2015-12-02 15:54:02 · 551 阅读 · 0 评论 -
HDU1009(贪心)
水题~ 按照性价比排序。 #include using namespace std; #define maxn 1111 int n, m; struct node { double val; int cnt; bool operator < (const node &a) const { return val/cnt > a.val/a.cnt;原创 2015-10-30 01:16:06 · 309 阅读 · 0 评论 -
HDU5236(概率DP,贪心)
题意是敲n个字符,每次敲有p概率崩溃返回上一次的保存状态,保存需要按下x个建。求最小的按键次数的期望。 求出敲n个字母的期望后枚举分成i段,要使得尽量均匀。 #include using namespace std; #define maxn 111111 #define INF 1e20 double dp[maxn], f[maxn]; double p; int x, n; doub原创 2015-10-13 17:49:09 · 458 阅读 · 0 评论 -
codeforces 732E (贪心)
题目链接:点击这里题意:给出n个电脑,m个电源,电脑有一个值aia_i,电源有一个值bib_i,电脑和电源能够配对当且仅当ai=bia_i=b_i。有无穷多个适配器,每对电源用一个适配器bib_i就减少一半(向上取整)。一个电源可以用很多次适配器。求最多配对多少电脑和电源,以及在最多配对下用的最少的适配器。还要输出方案。将电源按照从小到大依次尝试和电脑配对,如果能够配对成功就配对。可以反证,假设按照原创 2016-10-18 20:55:53 · 608 阅读 · 0 评论