2012年7月25日

摘要: hdu2100: http://acm.hdu.edu.cn/showproblem.php?pid=2100解法:高精度加法-26进制,A~Z分别代表0~26,求法和10进制一样code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>char a[300],b[300],c[300],d[300];int max(int x,int y){ if(x>y) return x; else return y;}int main(){ int x,y,s; 阅读全文
posted @ 2012-07-25 20:59 acmer-jun 阅读(300) 评论(0) 推荐(0) 编辑
摘要: hdu1856: http://acm.hdu.edu.cn/showproblem.php?pid=1856题意:输入n对朋友,求最多的朋友集合(直接或间接为朋友)解法:并查集:集合的合并及查询。code:#include<iostream>#include<cstdio>#include<cstdlib>const int maxn=10000002;int fa[maxn],ans[maxn];int find(int x) //路径压缩,复杂度为常数{ int fx=fa[x]; if(x!=fx)fa[x]=find(fx); return fa[ 阅读全文
posted @ 2012-07-25 20:54 acmer-jun 阅读(185) 评论(0) 推荐(0) 编辑
摘要: hdu1798: http://acm.hdu.edu.cn/showproblem.php?pid=1798题意:给出两个圆的圆心坐标和半径,求两圆相交面积code:#include<iostream>#include<cstdlib>#include<cstdio>#include<cmath>const double pi=acos(double(-1));double min(double x,double y){ if(x>y) return y; else return x;}int main(){ double x1,y1,r 阅读全文
posted @ 2012-07-25 20:50 acmer-jun 阅读(206) 评论(0) 推荐(0) 编辑
摘要: pku1018: http://poj.org/problem?id=1018题意:给出n种设备,每种设备有m家公司出售,对应宽带b[n][m]和价格p[n][m],现要求每种设备各选一个,要求所选设备bmin的最小值与所选设备总价格p的比值最大解法:贪心+枚举:将所有设备的b值从小到大枚举,再选出符合价格最小的设备。code:#include<iostream>#include<cstdio>#include<cstdlib>int b[150][150],p[150][150],m[150];const int inf=1<<29;int m 阅读全文
posted @ 2012-07-25 20:45 acmer-jun 阅读(178) 评论(0) 推荐(0) 编辑
摘要: pku1083: http://poj.org/problem?id=1083题意:有一条走廊,走廊两边为房间,一边的编号都为奇数(1、3……、399),一边的编号都为偶数(2、4……、400),现要从某个房间搬东西到另一房间,走廊很窄,不能共用,即若要用到同一段走廊,不能同时搬,搬一次需时10,求最小搬家时间解法:贪心:因为如果不冲突的话可以同时进行,所以最小次数为走廊需要用到的次数最多那段的次数,再乘以10即为最小时间。code:#include<iostream>#include<cstdio>#include<cstdlib>int ans[500] 阅读全文
posted @ 2012-07-25 20:35 acmer-jun 阅读(173) 评论(0) 推荐(0) 编辑
摘要: hdu1677: http://acm.hdu.edu.cn/showproblem.php?pid=1677题意:给出m个嵌套娃娃的数据(宽w、高h),求嵌套后最少娃娃数解法:贪心法+dp:类似最少拦截系统,这个问题其实是用dp求最长子序列的长度,先按宽从小到大排序,则小号可能可以嵌套在大号中,再依次判断后面的h是否比前面的大,若是,则取前面中h较大者(由贪心法可知)。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespac 阅读全文
posted @ 2012-07-25 20:29 acmer-jun 阅读(164) 评论(0) 推荐(0) 编辑
摘要: hdu3177: http://acm.hdu.edu.cn/showproblem.php?pid=3177题意:向一个体积为V的洞搬进东西,物品体积为v[i].a,需要的移动体积为v[i].b,问能否全部搬进洞中解法:贪心法:对于两件物品a1,b1;a2,b2,若先放1再放2,则V-a1>b2即V>a1+b2;若先放2再放1,则V-a2>b1即V>a2+b1,用贪心法可知要取a1+b2与a2+b1中较小者,即b-a大者先取code:#include<iostream>#include<cstdio>#include<cstdlib> 阅读全文
posted @ 2012-07-25 19:42 acmer-jun 阅读(112) 评论(0) 推荐(0) 编辑
摘要: hdu2037: http://acm.hdu.edu.cn/showproblem.php?pid=2037题意:求最多不相交区间:给出n个节目开始a[i]和结束b[i]的时间,求最多可看多少个节目方法:贪心法:将b[i]从小到大排序,每次取第一个区间,再剔除与所取区间相交的区间。如样例应取(1,3)、(3,4)、(5,10)、(10,15)、(15,19)code:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std; 阅读全文
posted @ 2012-07-25 18:45 acmer-jun 阅读(138) 评论(0) 推荐(0) 编辑
摘要: hdu1257: http://acm.hdu.edu.cn/showproblem.php?pid=1257题意:导弹拦截系统:第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度,v[i]为依次发来的导弹高度,求最少需要多少套拦截系统解法:贪心法:如对于样例,首先启动第一套,拦截前三个导弹后,限定值为155,再启动第二套,限定值为300,对于后面的导弹,采用贪心法,与前面的限定值作比较,采用限定值最接近该高度且小于该限定值的系统,如果没有这种系统,则另启动新系统。code:#include<iostream>#include<cstdio>#inc 阅读全文
posted @ 2012-07-25 17:53 acmer-jun 阅读(187) 评论(0) 推荐(0) 编辑
摘要: hdu1548: http://acm.hdu.edu.cn/showproblem.php?pid=1548题意:坐电梯,给出层数n,求从a到b最少要按多少次键(每层楼有一个数c[i],表示可以搭到第i-c[i]和第i+c[i]层,但只能到达1至n层,求最少需要按多少次按钮可到达目的地。解法:bfs(也可用dij求最短路)code:#include<iostream>#include<cstdio>#include<cstdlib>int v[250][250],k[250],d[250],q[3000*300];const int inf=2<&l 阅读全文
posted @ 2012-07-25 17:27 acmer-jun 阅读(137) 评论(0) 推荐(0) 编辑

导航