雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  贪心专辑

摘要:思想是按草的新鲜程度作为第一关键词,前作为第二关键词排序(因为要取钱较少的,所以草鲜嫩排第一)multiset 储存符合第二关键词的 所有第一关键词,取合理且最小的第一关键词累积View Code #include<stdio.h>#include<algorithm>#include<iostream>#include<vector>#include<set>using namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EO 阅读全文

posted @ 2011-09-13 22:13 huhuuu 阅读(447) 评论(0) 推荐(0) 编辑

摘要:在家没事干就要多做做比赛才是。。。 C题是搜索题 N个数字之间放N-1个"+","-","*" ,"/" 使每位不存在为k的数字。。。 注意点,超int,注意除数不为0,当结果为0是特判 //long long 注意0#include<stdio.h>#include<iostream>#inclu 阅读全文

posted @ 2011-08-01 22:37 huhuuu 阅读(439) 评论(0) 推荐(0) 编辑

摘要:感觉这种从左向右统计的题目都可以用到栈来优化单调栈,从左向右扫ps:STL里的栈是比较快的,自己是、手写的栈效率跟它差不多啊。。。View Code #include<stdio.h>#include<iostream>#include<stack>using namespace std;int a[80009]; int main(){ int n; while(scanf("%d",&n)!=EOF) { int i; for(i=0;i<n;i++) scanf("%d",&a[i]); s 阅读全文

posted @ 2011-07-28 13:52 huhuuu 阅读(301) 评论(0) 推荐(0) 编辑

摘要:暴力亦可过,同没意思。。。有个O(n)的算法从左向右扫{while{if(栈顶元素.h>当前元素.h) 入队,更新栈顶元素对应的牛的V ,结束while循环else 出队}直到队列为空}再从右向左View Code #include<stdio.h>#include<iostream>#include<stack>using namespace std;struct data{ int h,v,no;}node[50009];int all[50009];int main(){ int n; while(scanf("%d",&am 阅读全文

posted @ 2011-07-27 21:31 huhuuu 阅读(361) 评论(0) 推荐(0) 编辑

摘要:比较好的贪心题也学会了优先队列吧思路:现对开始时间升序排序(再一次领教到了排序降维的意义!!!)优先队列里放add(第几次stall),rr(结束时间)在把第一个放到优先队列,第二个数与优先队列顶部进行比较若第二个数结束时间>优先队列顶部结束时间,则更新该顶部时间否则第二个数加到该优先队列里View Code #include<iostream>#include<cstdio>#include<algorithm>#include<queue>#include<string.h>using namespace std;int r 阅读全文

posted @ 2011-07-27 15:43 huhuuu 阅读(291) 评论(0) 推荐(0) 编辑

摘要:输入n然后n个数字输出需要换几次View Code #include<cstdio>#include<iostream>#include<algorithm>using namespace std;struct data{ int val; int no; int N;}a[500009];int hash[500009];int cmp(data a,data b){ return a.val<b.val;}int cmp1(data a,data b){ return a.no<b.no;}int main(){ int n; while(s 阅读全文

posted @ 2011-07-15 13:59 huhuuu 阅读(238) 评论(0) 推荐(0) 编辑

摘要:求最小排序交换次数贪心做View Code #include<stdio.h>#include<algorithm>#include<iostream>using namespace std;int b[1009],a[1009];int min(int a,int b){ if(a>b)return b; else return a;}int max(int a,int b){ if(a>b)return a; else return b;}int main(){ int n; int add[6]; while(scanf("%d& 阅读全文

posted @ 2011-07-15 11:17 huhuuu 阅读(340) 评论(0) 推荐(0) 编辑

摘要:如何安排相片,使相片尽量能放入几个给定的箱子里(体积不同),但是条件是,每个箱子里的照片不能相邻:如第一张,第二张不能同时放到一个箱子里,而且第一张与最后一张也不能在一起!!!错了N久,解决方法就是尽量把不能最后放的箱子在前面用掉1.按每个箱子剩余容积排序放入第一张到一个箱子里2.每放入一张照片前,先拿第一张所放入的箱子号去放(为了使第一张与最后一张不能相邻),如不行则再按每个箱子剩余容积排序,选择符合的箱子去放http://codeforces.com/problemset/problem/81/DView Code #include<iostream>#include<c 阅读全文

posted @ 2011-05-05 15:47 huhuuu 阅读(296) 评论(0) 推荐(0) 编辑

摘要:a==ba>b时按: if(a.shu==b.shu) return a.no<b.no; return a.shu<b.shu; a<b时按: if(a.shu==b.shu) return a.no>b.no; return a.shu<b.shu; View Code #include<iostream>#include<cstdio>#include<algorithm>using namespace std;struct data{ int no; int shu;}qun[100009];bool hash[1 阅读全文

posted @ 2011-05-04 21:29 huhuuu 阅读(208) 评论(0) 推荐(0) 编辑

摘要:直接枚举整数算余数 明显会超时枚举(小数+整数) 求方后四舍五入,后求根号后比较小数,看是否一致即可注意:费解的精度问题如:对219048452111求根号,然后对求得的数进行*10运算,到后来开始的第九位小数会变化,由4到3的变化?解决方法,直接乘1000,000,000后求第9位数View Code #include<stdio.h>#include<math.h>int main(){ __int64 l,s,j; __int64 i,n,t1; while(scanf("%I64d%I64d",&l,&s)!=EOF) { d 阅读全文

posted @ 2011-03-27 21:31 huhuuu 阅读(555) 评论(0) 推荐(0) 编辑

摘要:用贪心做初始i=j=1当i/j>=n/m时:j++反之i++随时记录最接近的值即可View Code #include<stdio.h>double jue(double a){ if(a>0)return a; return -a;}int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF) { int ri,rj,i,j; double e=n*1.0/m,t,cha=99999999; i=1; j=1; while(i<=32767&&j<=32767 阅读全文

posted @ 2011-03-16 20:11 huhuuu 阅读(156) 评论(0) 推荐(0) 编辑