【POJ - 1862】Stripies (贪心)】的更多相关文章

http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成一个的最小重量 思路: m1+m2 >=  2*sqrt(m1*m2) 所以每次取大的去合并,能变小. 直接优先队列就可以啦. #include<cstdio> #include<cmath> #include<queue> using namespace std;…
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int main() { int n; ]; while(~scanf("%d",&n)) { ;i<n;i++) { int m; scanf("%d",&m); w[i]=m*1.0; } s…
Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18198   Accepted: 8175 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…
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> class Solution{ public: ; int sz; double heap[Max_N]; inline void…
Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10263   Accepted: 4971 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…
Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English name to apply for an international patent). The str…
每次合并最大的两个,优先级队列维护一下. 输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC. #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> using namespace std; int n,s; priority_queue<double>Q; int main() { while…
题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2).要求出最终的重量的最小值. 思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得到最小的质量.所有只要维护一个优先队列就可以了 #include <iostream> #include <cstdio> #include <queue> #include <math.h> #include <cstring> #include…
POJ 1862 Stripies https://vjudge.net/problem/POJ-1862 题目:     Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English n…
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=543 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian -…
Stripies 直接上中文了 Descriptions 我们的化学生物学家发明了一种新的叫stripies非常神奇的生命.该stripies是透明的无定形变形虫似的生物,生活在果冻状的营养培养基平板菌落.大部分的时间stripies在移动.当他们两个碰撞,会有新stripie生成,而旧的不见了.经过长期研究,他们发现新stripies的体重不等于消失的stripies的体重,而是:如果一个质量为m1和m2的stripies相撞,生成的stripies体重是2*sqrt(m1*m2) 现在,科学…
题目描述:http://poj.org/problem?id=1862 题目大意:你有n个数要合并,每两个数x,y合并后得到2*sqrt(x*y).求最后留下的一个数的最小值. 每合并一次,就会有数被开方,那么你越早合并的数被开放的次数越多,于是每次把最大的两个数合并即可.用到优先队列. 代码: #include<cstdio> #include<queue> #include<cmath> using namespace std; priority_queue<…
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…
题意: 有n个数,要把其中2个数进行2*根号(n1*n2)操作,求剩下最小的那个数是多少? 哭诉:看题目根本没看出来要让我做这个操作. 思路: 每次把最大的,次大的拿出来进行操作 用"优先队列"巧解,优先队列中剩下的那个就是题目要求求的答案. 解题代码: #include <iostream> #include <math.h> #include <algorithm> #include <queue> #include <cstd…
#include <string.h> #include <iostream> #include <queue> #include <stdio.h> using namespace std; struct product{ int deadline; int val; friend bool operator<(product n1,product n2) { return n1.val<n2.val; } }q; ]; int main()…
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固定阳光强度在某一个值,每种的数量是cover[i] ,每头奶牛只能用一瓶防晒霜,问最多有多少头奶牛能在沙滩上晒太阳. 理解题意之后还是挺好做的. 首先确定的贪心策略是,在满足min_spf的条件下,尽量用spf小的用在max_spf大的奶牛身上,用一个最小堆维护max_spf的最小值即可. 先对奶牛…
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid unsightly burns while tanning, each of the c (1 ≤ c ≤ 2500) cows must cover her hide with sunscreen when they're at the beach. cow i has a minimum and…
题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of tim…
Bridge over a rough river Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4143   Accepted: 1703 Description A group of N travelers (1 ≤ N ≤ 50) has approached an old and shabby bridge and wishes to cross the river as soon as possible. Ho…
Tian Ji -- The Horse Racing Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12490   Accepted: 3858 Description Here is a famous story in Chinese history. That was about 2300 years ago. General Tian Ji was a high official in the country Q…
地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪枝 然而 还是TLE了 TLE代码 #include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; vector<pair&l…
简单的说说思路,如果一开始能够去到目的地那么当然不需要加油,否则肯定选择能够够着的油量最大的加油站加油,,不断重复这个贪心的策略即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int maxn=1e4+9; int dist,p,n; struc…
//poj 3154 //sep9 #include <iostream> #include <cmath> using namespace std; double a[2048]; double b[2048]; int main() { int n,m; while(scanf("%d%d",&n,&m)==2){ for(int i=0;i<n;++i) a[i]=i*(10000.0/n); for(int i=0;i<(n+…
这题目的贪心思路还是有一点细节问题的. 还没有证明,据说是因为题目给的条件是每个价格是比它小的价格的倍数才能这么贪心的. 思路如下: 假设要给奶牛的钱为C 1)从大面值到小面值一次拿钱,能拿多少拿多少. 但是注意不能拿到的钱的总和大于C 2)如果第一步拿到的钱不够C,那么就从小面值到大面值拿钱,能拿多少拿多少. 直到拿到的钱总和大于等于C 我刚开始第一步实现的比较好,但是第二步想错了. 后来才意识到大拿到的钱尽量不要超过C很多才是最优的,所以第二步要从小到大拿 #include <iostrea…
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #inc…
(- ̄▽ ̄)-* 找规律 //初始化为B[i]=A[i] //然后由V=|A[1]-B[1]|+|A[2]-B[2|+|A[3]-B[3]| // +|B[1]-B[2]|+|B[2]-B[3]| //可以知道,如果要V尽可能小,那么对于B[2]的取值, //则要求B[2]到A[2] B[1] B[3]的距离尽可能小, //在数轴上可以看出,只要B[2]=中位数(A[2],B[1],B[3])即可 //即贪心规则如下:B[i]=Mid(A[i],B[i-1],B[i+1])(i=1--n-1)…
题意:给定一个序列表示一群山,要你保留最多 K 个山峰,最少要削去多少体积和土.一个山峰是指一段连续的相等的区间,并且左边和右边只能比这个区间低,或者是边界. 析:贪心,每次都寻找体积最小的山峰,然后把它削去,每次削的是最小的,所以是满足贪心的,最后剩下的小于 K 个就可以了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string…
Cow Sorting Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6993   Accepted: 2754 Description Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the evening. Each cow has a unique "grumpiness" level in the range 1...…
//poj 4014 //sep9 #include <iostream> #include <algorithm> using namespace std; int n; struct DICE { int ids; int num; int a[128]; }d[1024]; int cmp1(DICE x,DICE y) { return x.num<y.num; } int cmp2(DICE x,DICE y) { return x.ids<y.ids; }…
田忌赛马,大致题意是田忌和国王赛马,赢一局得200元,输一局输掉200元,平局则财产不动. 先输入一个整数N,接下来一行是田忌的N匹马,下一行是国王的N匹马.当N为0时结束. 此题为贪心算法解答,有两种思路. 思路二: 1.开始也是先排序,可以使用sort快排: 2.然后将田忌最大的马与国王进行比较: 3.如果田忌最大的马大于国王,那么就胜场++: 4.如果田忌最大的马小于国王,那么就一定会输,所以用田忌最小的马输给国王最大的马: 5.如果田忌最大的马等于国王,那么就比较最小的马: 5.1.如果…