
HDU
一只会旅行的猫
这个作者很懒,什么都没留下…
展开
-
hdu 2844 Coins
http://acm.hdu.edu.cn/showproblem.php?pid=2844题意:用不同种类的不同数量的硬币可以得到多少种2)用二进制减少重复的计算#include#include#includeusing namespace std;int vau[105],f[100005],num[105],count,m,n;void ZeroOne原创 2013-04-07 19:39:24 · 793 阅读 · 0 评论 -
hdu 3127 WHUgirls
http://acm.hdu.edu.cn/showproblem.php?pid=3127题意:用规定大小的布裁给出的布,获得最大利润,可以不完全用完布,二维完全背包分化方案:#include#includeusing namespace std;int f[1002][1002];struct CLOTH{int x,y,vau;}cloth[1原创 2013-04-07 18:36:13 · 891 阅读 · 0 评论 -
hdu 1171
#include#include#includeusing namespace std;int N[110][110],m1[300000],m2[300000];int main(){ int i,j,num,num1,k,n; while(scanf("%d",&n)&&(n>0)) { memset(m1,0,sizeof(m1));原创 2013-04-11 21:22:12 · 508 阅读 · 0 评论 -
hdu 1272 小希的迷宫
http://acm.hdu.edu.cn/showproblem.php?pid=1272题意要点:任意两个房间有且仅有一条路径可以相通,用并查集法1)#include#include#includeusing namespace std;const int N=100005;bool flag;int father[N],rank[N],MAX;int find原创 2013-04-13 16:45:22 · 593 阅读 · 0 评论 -
poj 1182 食物链
http://poj.org/problem?id=1182分析:rank[x]=(rank[x]+rank[t])%3;rank[t1]=(rank[y]-rank[x]+d-1+3)%3;参考:http://cavenkaka.iteye.com/blog/1489588#include#includeusing namespace std;con原创 2013-04-17 21:32:09 · 649 阅读 · 0 评论 -
hdu 1788 Chinese remainder theorem again
http://acm.hdu.edu.cn/showproblem.php?pid=1788分析:N%Mi=Mi-a即:N%Mi+a=Mi即:(N%Mi)Mi+a%Mi=0即:(N+a)%Mi=0所以,N就为Mi的最小公倍数减去a切记,心细、心细、心细! #include#includeusing namespace std;__int64 gc原创 2013-05-08 20:00:16 · 571 阅读 · 0 评论 -
hdu 1576 A/B
http://acm.hdu.edu.cn/showproblem.php?pid=1576分析:A%9973=n即:A≡n(mod9973)即:Bx≡n(mod9973)即:Bx1+9973*y1=1 #include#includeusing namespace std;const int N=9973;__int64 x,y,r;voi原创 2013-05-08 20:57:10 · 574 阅读 · 0 评论 -
hdu 1051 Wooden Sticks
分析:排序后,从小找到大,注意保存第一个不满足条件的stick,作为第二次查找的开始#include#includeusing namespace std;const int NM=5005;struct Stick{ int x,y;}st[NM];bool comp(struct Stick A,struct Stick B){ if(A.x<B.x) retur原创 2013-07-13 11:14:48 · 520 阅读 · 0 评论 -
hdu 1175 连连看(外一篇)
http://acm.hdu.edu.cn/showproblem.php?pid=1175分析:因为转弯次数的限制,用一直走到底的方法,其他各种方法变换搜索方向顺序均不能通过,是错误的#include#include#includeusing namespace std;const int NM=1005;struct Node{ int x,y,turn;};int原创 2013-07-17 13:08:35 · 548 阅读 · 0 评论 -
hdu 2102 A计划
http://acm.hdu.edu.cn/showproblem.php?pid=2102分析:遇到‘#’就跳到另外一层,本来想到两层相同位置同时为’#‘会发生冲突,没想到还是脑抽了认为已经考虑到这种情况了,还狂找bug,看来还是不够细心和自信,努力之#include#include#includeusing namespace std;const int NM=11;cha原创 2013-07-19 23:32:26 · 587 阅读 · 0 评论 -
hdu 4070 Phage War
http://acm.hdu.edu.cn/showproblem.php?pid=4070题意:一个噬菌体周围有编号1~n个细胞,每一秒钟这个噬菌体就产生一个新的噬菌体,想要感染细胞需要:1)Di个噬菌体 2)Ti秒的到达时间,问最少需要多少时间可以使所有的细胞都被感染?分析:先感染需要到达时间最长的细胞,利用剩下时间繁殖噬菌体,然后更新最长时间#include#include#原创 2013-07-30 16:05:15 · 689 阅读 · 0 评论 -
hdu 3183 A Magic Lamp
http://acm.hdu.edu.cn/showproblem.php?pid=3183题意:从一个数里删除n个数字,使其最小分析:只需判断第i个数是否大于第i+1个数,实则删掉,否则继续寻找;注意0的存在,只要第二位数是0,直接删除第一个数即可,因为数的位数减少了#include#include#include#include#includeusing namespac原创 2013-07-30 20:08:02 · 550 阅读 · 0 评论 -
hdu 4550 卡片游戏
http://acm.hdu.edu.cn/showproblem.php?pid=4550分析:就是前导可恶的0,然后利用字符串,大于序列第一个数的放右边,反之放左边(#include#include#include#includeusing namespace std;int main(){ string str,card; char t; int T,i,j,len原创 2013-07-23 20:03:28 · 662 阅读 · 0 评论 -
hdu 1445 Ride to School
http://acm.hdu.edu.cn/showproblem.php?pid=1445分析:原先把问题想麻烦了,其实只要理清思路就会发现,无论自己的车速会怎么变,最后一定会和一个人同时到达,那么计算这个人的到达时间即可其中,时间为负数的不用考虑,要么你追不上,要么他追不上你#include#include#include#includeusing namespace st原创 2013-07-24 23:14:47 · 712 阅读 · 0 评论 -
hdu 4296 Buildings(外一篇:hdu 4310 Hero)
http://acm.hdu.edu.cn/showproblem.php?pid=42分析:条件:A.w+A.s具体分析:http://blog.youkuaiyun.com/acm_ted/article/details/79849351) a=sum-si;b=sum+wi-sj; 交换两个板的位置2)b'=sum-sj;a'=sum+wj-s原创 2013-07-23 22:01:14 · 570 阅读 · 0 评论 -
hdu 1597 find the nth digit
http://acm.hdu.edu.cn/showproblem.php?pid=1597法一:分析:由题意知,设n在Si序列,则:i*(i-1)解二元一次方程:i^2+i-2*n=0,即:i=(-1+sqrt(1+8*n))/2#include#include#includeusing namespace std;int main(){ __int64 T,原创 2013-07-25 18:29:34 · 618 阅读 · 0 评论 -
hdu1238 Substrings
http://acm.hdu.edu.cn/showproblem.php?pid=1238分析:枚举+STL#include#include#include#include#includeusing namespace std;const int NM=105;string str[NM];bool comp(string A,string B){ if(A.si原创 2013-07-25 21:33:25 · 595 阅读 · 0 评论 -
hdu 1240 Asteroids!
http://acm.hdu.edu.cn/showproblem.php?pid=1240分析:三维数组,同二维相同,同类型:hdu 1253 胜利大逃亡#include#include#includeusing namespace std;const int NM=15;int a[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,原创 2013-07-25 20:20:24 · 564 阅读 · 0 评论 -
hdu 1239 Calling Extraterrestrial Intelligence Again
http://acm.hdu.edu.cn/showproblem.php?pid=1239分析:范围2~50000->10000,居然可以暴力成功,哎#include#include#includeusing namespace std;const int NM=10005;int pi[NM/2],a[NM];int main(){ int i,j,k,ans,m,原创 2013-07-26 22:01:33 · 472 阅读 · 0 评论 -
【最小生成树】hdu 1863 畅通工程
分析:prim算法(添加边)#include#includeusing namespace std;struct Road{ int x,y,vau;}road[5000];bool comp(const struct Road &A,const struct Road &B){ if(A.vau<B.vau) return 1; else return原创 2013-05-03 20:58:16 · 1513 阅读 · 0 评论 -
【最短路径-Dis】hdu 3790 最短路径问题
http://acm.hdu.edu.cn/showproblem.php?pid=3790分析:首先判断路径长短,在路径长短相同时,才判断花费#include#include#includeusing namespace std;const int NM=1005;const int MAX=0x3fffffff;int a[NM][NM],b[NM][NM],n,m;b原创 2013-08-06 12:34:29 · 667 阅读 · 0 评论 -
【最短路径-Dis】hdu 1596 find the safest road
http://acm.hdu.edu.cn/showproblem.php?pid=1596分析:乘积,注意初始化即可#include#includeusing namespace std;const int NM=1005;const int MAX=0;double a[NM][NM],p[NM];int n; bool flag[NM]; void Dis(i原创 2013-08-06 18:09:03 · 449 阅读 · 0 评论 -
【最短路径-Floyd】hdu 2112 HDU Today
http://acm.hdu.edu.cn/showproblem.php?pid=2112注意:起终点相同,map保存出现的地点#include#include#include#includeusing namespace std;const int NM=155;const int MAX=0x3fffffff;int a[NM][NM];mapm1;int ma原创 2013-08-06 14:41:10 · 565 阅读 · 0 评论 -
hdu 2141 Can you find it ?
#include#include#includeusing namespace std;const int NM=505;__int64 a[NM],b[NM],c[NM],num[NM*NM];int main(){ __int64 L,N,M,i,j,flag,t,n,ans,mid,low,high,T; ans=1; whi原创 2013-08-20 19:55:40 · 526 阅读 · 0 评论 -
hdu 1969 Pie
http://acm.hdu.edu.cn/showproblem.php?pid=1969题意:“我”要将我拥有的n个不同大小的pie分给f+1(自己),求每人能得到的最大pie的面积,注意只能由一块饼分得,不能拼接分析:二分查找,判断每次的面积变化是否能满足人数需求#include#include#includeusing namespace std;const doub原创 2013-08-20 21:48:55 · 490 阅读 · 0 评论 -
hdu 4004 The Frog's Games
http://acm.hdu.edu.cn/showproblem.php?pid=4004分析:二分查找+贪心(哎)#include#include#includeusing namespace std;const int NM=500005;int a[NM],n,m;bool Stone(int mid){ int k,t,i,j; i=1;j=k=原创 2013-08-22 20:17:52 · 549 阅读 · 0 评论 -
【最短路径-Floyd+路径】hdu 1385
1.floyd-warshall算法如:hdu 1385for(i=1;i<=N;i++)//字典序神马的,注意-1的时候 for(j=1;j<=N;j++) pass[i][j]=j; //floyd-warshall算法 for(k=1;k<=N;k++)//注意:要先枚举媒介结点,即:k for(i=1;i<=N;i++) for(j=1;j<=N;j原创 2013-08-10 20:17:26 · 324 阅读 · 0 评论 -
hdu 2822 Dogs
http://acm.hdu.edu.cn/showproblem.php?pid=2822分析:遇到'.'(挖隧道)的时候才需要步数加1,'X'是一个整体,利用优先队列选择步数最小的开始广搜不过这样效率比较低,可以用双搜加快效率#include#include#includeusing namespace std;const int NM=1005;int a[4][2]原创 2013-08-11 12:20:55 · 495 阅读 · 0 评论 -
hdu 2298 Toxophily
http://acm.hdu.edu.cn/showproblem.php?pid=2298分析:斜抛运动:http://baike.baidu.com/link?url=JYIT2a6cWniYW7UfTHTYFOxf_B-D2noUxnLIRTRTrydpixDeq8s_mGvdH7N1hfre斜抛运动轨迹方程式:y=xtanθ-gx^2/2(v0cosθ)^2,其中x:某时刻该点水平原创 2013-08-22 22:54:43 · 614 阅读 · 0 评论 -
【BFS+DFS】hdu 1254 推箱子
http://acm.hdu.edu.cn/showproblem.php?pid=1254分析:以箱子的路线为主,判断人是否能到达推箱子的地点,通过箱子只能走不同方向(vis[NM][NM][[4])一次标记#include#include#includeusing namespace std;const int NM=10;int a[4][2]={-1,0,1,0,0,1原创 2013-08-11 16:00:22 · 632 阅读 · 0 评论 -
【DFS】hdu 1426 Sudoku Killer
http://acm.hdu.edu.cn/showproblem.php?pid=1426分析:同hdu 2780相同,注意退细节的处理#include#include#includeusing namespace std;const int NM=20;int a[NM][NM],vis[NM],k,flag;struct Sudu{ int x,y;}s[原创 2013-08-14 18:40:50 · 563 阅读 · 0 评论 -
【DFS】hdu 2780 Su-Su-Sudoku
http://acm.hdu.edu.cn/showproblem.php?pid=2780分析:我去,注意可能输入的矩阵就不符合要求,以及最后一行不用再多输出空格了(各种处理,真的好讨厌)回溯搜索#include#include#includeusing namespace std;const int NM=9;int vis[10],v1[10],v2[10],v3[1原创 2013-08-14 00:25:49 · 609 阅读 · 0 评论 -
hdu 4198 Quick out of the Harbour
http://acm.hdu.edu.cn/showproblem.php?pid=4198分析:计算最小时间时间#include#include#includeusing namespace std;const int NM=505;const int MAX=0x3fffffff;char str[NM][NM];int vis[NM][NM],n,m,d,x1,y1,原创 2013-08-17 19:37:17 · 584 阅读 · 0 评论 -
hdu 1114 Piggy-Bank
http://acm.hdu.edu.cn/showproblem.php?pid=1114题意:用最少的价值装满存钱罐,完全背包#include#include#includeusing namespace std;int f[10005],P[505],W[505];const int MAX=0xfffff;int main(){int T,E,F原创 2013-04-03 21:09:04 · 544 阅读 · 0 评论 -
hdu 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602题意:01背包#include#include#includeusing namespace std;int cost[1005],value[1005],f[1005];int main(){int i,j,T,N,V;scanf("%d",&T);whil原创 2013-04-03 21:09:51 · 466 阅读 · 0 评论 -
hdu 3633
http://acm.hdu.edu.cn/showproblem.php?pid=1000枚举~#include#includeusing namespace std;const int N=100005;char str[N];int main(){ int h,t,i,n,flag,num1,num2,count1,count2; while(scanf("%d",&原创 2013-05-26 23:30:01 · 5306 阅读 · 0 评论 -
hdu 1228 A + B
http://acm.hdu.edu.cn/showproblem.php?pid=1228#include#include#include#include#includeusing namespace std;int main(){ string str1,str4,strp,str2,str5,stre; mapm1; int num1,n原创 2013-09-23 23:21:32 · 544 阅读 · 0 评论 -
hdu 4528 捉迷藏
http://acm.hdu.edu.cn/showproblem.php?pid=4528分析:其中一个人被发现后还会在原来的位置,用vis[x][y][4]数组保存查找状态(可以重复走同一位置):0)未发现任何人;1)只发现大明;2)只发现二明;3)都找到#include#include#include#includeusing namespace std;co原创 2013-09-24 14:19:19 · 487 阅读 · 0 评论 -
hdu 4427 玩转十滴水
http://acm.hdu.edu.cn/showproblem.php?pid=4527#include #include #include #include using namespace std;const int NM=10;struct Node{ int x,y,dir;};int c[4][2]={-1,0,1,0,0,-1,0,1};int a[N原创 2013-09-26 15:27:37 · 690 阅读 · 0 评论 -
hdu 2600 War
http://acm.hdu.edu.cn/showproblem.php?pid=2600题意:要求找出不发生战争的最后一年分析:按照x,y都最大排序,即:从最大的区间开始查找战争年间是否有断层#include #include #include using namespace std;struct War{ int x,y;}war[105];原创 2013-10-19 11:07:40 · 682 阅读 · 0 评论