POJ 2181 贪心】的更多相关文章

思路: 贪心 对于每个波浪 ans+=最大值-最小值 注意最后一定是选最大值 //By SiriusRen #include <cstdio> using namespace std; int n,a[150500],flag,ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++) if(fla…
Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59725   Accepted: 20273 Description A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are alway…
题意:FJ希望它的牛做一些清洁工作.有N只牛和T个时间段,每只牛可以承担一段时间内的工作.FJ希望让最小数量的牛覆盖整个T,求出其数量.若无法覆盖整个T,则输出-1. 分析:首先要注意T表示T个时间段,也就是说1就是一个时间段,而[1, 2]是两个时间段.在这个问题上,我们要做到的是用最小的牛覆盖整个区间.比较容易想到的是先将牛按开始时间排序,因为如果一开始就覆盖不了那么后续就没有意义可以直接输出-1.贪心选取在满足当前开始时间的前提下,其结束时间的大的牛,因为在满足开始前提下,当然是覆盖得越多…
/* 贪心.... 处理处每个点按照最大距离在x轴上的映射 然后我们就有了一些线段 目的是选取尽量少的点 使得每个线段内都有点出现 我们按照左端点排序 然后逐一处理 假设第一个雷达安在第一个线段的右端点 若下一条与之无交点 则再按一个雷达 若完全覆盖 贪心的 我们把雷达移动到下一条的右端点 这样这个雷达就又多覆盖了一个岛 */ #include<iostream> #include<cstdio> #include<cstring> #include<algori…
Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8205   Accepted: 4197 Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15143   Accepted: 3875 Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one co…
做法一:直接贪心,按照利润排序,然后直接尽量给每个活动安排到最晚的时间即可.时间复杂度O(n * d)当d都为10000时,很容易超时.由于这题数据比较水,所有贪心未超时. AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <cstring> #include <utility> #include <st…
http://poj.org/problem?id=1456 #include<cstring> #include<iostream> #include<algorithm> using namespace std; struct nod { int a; int d; }; bool cmp(nod x,nod y) { return x.a>y.a; } int main() { nod aa[]; int n; while(cin>>n) { ]…
题意:有n个商品,每个商品如果能在截止日期之前售出就会获得相应利益,求能获得的最大利益 一开始对每个时间进行贪心,后来发现后面的商品可以放到之前来卖,然后就wa了 这里就直接对价格排序,把物品尽量放到最后卖,如果在这个时间有物品卖了,就往前卖,直到前面所有的时间都满了 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath>…
Pass-Muraille Time Limit: 2 Seconds      Memory Limit: 65536 KB In modern day magic shows, passing through walls is very popular in which a magician performer passes through several walls in a predesigned stage show. The wall-passer (Pass-Muraille) h…
题意:给定n个商品的deadline和profit,求每天卖一件的情况下的最大获利 显然是一道贪心 按deadline从小到大排序好,动态维护小根(profit)堆的大小<=当前deadline的天数,往里面符合条件的尽可能塞更优解 注意有n为0的情况 还有脑抽导致判断条件缺斤少两,下次不要这样了 /*H E A D*/ struct Node{ ll p,d,id; }a[maxn]; bool cmp(Node a,Node b){ if(a.d!=b.d)return a.d<b.d;…
题意: 思路: 1. 贪心 我们考虑肯定是走最近的最合适 想象自己是一个黑一日游的司机: 1.如果有乘客要上车,那么就让他上,收钱! 2.如果超载了,把距目的地最远的几个乘客踢下去,退钱. 3.行驶到下一站 (摘自http://blog.sina.com.cn/s/blog_9d987af5010158ih.html) 多么生动形象-. 用multiset乱搞就可以了(我代码写得很丑 慎看) 2 乱想的.. 我觉得可以用最大费用流+消圈来搞 (然而并不会 (也不能证明正确性) 也很可能会T )…
贪心好题 ---. 思路: 从大到小凑C 如果不够 再从小到大补满(超过)C //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,c,ans,flag,vis[21]; struct Money{int amount,value;}money[100]; bool cmp(Money a,Money b){return a.…
题意: 思路: 贪心 能不覆盖的就不盖 写得很乱 左闭右开的 temp //By SiriusRen #include <queue> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,l,temp,ans; struct Node{int from,to;}node[10050]; priority_queue<Node>pq…
Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3056 Description Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To keep track of his forces, Saruman distributes se…
有一家生产酸奶的公司,连续n周,每周需要出货numi的单位,已经知道每一周生产单位酸奶的价格ci,并且,酸奶可以提前生产,但是存储费用是一周一单位s费用,问最少的花费. 对于要出货的酸奶,要不这一周生产,要不提前生产. 什么时候采用什么生产方式呢? 若第i周的货提前生产的话,假设在j周生产,则费用为(i-j)*s+c[j] 若c[i]>(i-j)*s+c[j],则更新c[i]=(i-j)*s+c[j] 更新要O(n^2)? 可以证明,最优的生产方式是,要不在这一周生产,要不在上一周生产(这里的上…
#include <iostream> #include <cstdio> #include <cmath> #define MAXN 150005 #include <algorithm> using namespace std; struct node { int num; int sum; bool boo; }; node _m[MAXN]; int n; void init(); int main() { //freopen("acm.a…
有n件商品,每件商品有它的利润和售出的最后期限,问能够得到的最大利润是多少 这道题和 HDU 1789 Doing Homework again 几乎一模一样,只不过这个是求最的扣分,本题是求最大利润 朴素的做法是: 按照每件商品的利润从大到小排序,有一个busy数组记录那天是否有东西卖出.对于每件商品,从它的截止日期开始遍历,如果那天有东西卖就看看前一天是否有卖东西,直到有一天没有东西卖或者前面的天数都有卖的. //#define LOCAL #include <iostream> #inc…
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, s…
Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14151   Accepted: 6628 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, bu…
Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4434   Accepted: 1588   Special Judge Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time in…
经典面替换算法,每次选择最远的那个碟片请求进行替换. AC代码 #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <utility> #include <string> #include <iostream> #include <map> #include <set> #includ…
Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long b…
很好的解题报告: http://blog.csdn.net/new_c_yuer/article/details/6365689 注意两点: 1.预处理环中权值最大的边···· 2.可以把去掉度限制后的点看成是连通的,权值为无穷远的点也看做是连通的,反正后面肯定会替换出来的···· 我的代码没有预处理出权值最大的边,但是第2点事做到了的,这样便于代码的实现····· 贴代码: #include <cstdio> #include <iostream> #include <ma…
题意:一辆卡车距离重点L,现有油量P,卡车每前行1米耗费油量1,途中有一些加油站,问最少在几个加油站加油可使卡车到达终点或到达不了终点.   思路:运用优先队列,将能走到的加油站的油量加入优先队列中,油不够时加入优先队列中数值最大的油,如果油不够时队列里为空则到达不了.     #include<cstdio> #include<queue> #include<algorithm> using namespace std; priority_queue<int&g…
Evil Straw Warts Live Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1144   Accepted: 330 Description A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, comput…
Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15626   Accepted: 7843 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc…
Jumping Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6398   Accepted: 3828 Description Farmer John's cows would like to jump over the moon, just like the cows in their favorite nursery rhyme. Unfortunately, cows can not jump. The…
题意: 思路: 从前到后扫一遍 如果k个数都出现过了 ans++ 从当前接着判断 最后答案就是ans+1 //By SiriusRen #include <cstdio> using namespace std; int n,k,vis[10050],cnt,ans=1,jy; int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++){ scanf("%d",&jy); i…
题意: 思路: 贪 贪 贪 如果当前的c>之前的c+s 那么之前的合适 一直贪下去就好了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define int long long int n,s,rec=1,c[10500],y[10500],ans; signed main(){ scanf("%lld%lld&…