
ACM(算法)
文章平均质量分 81
在ACM竞赛中会用到各种各样的算法。
该专栏主要记录各AMC竞赛题解,各题解按照算法进行分类。
Must_so
Theirs not to reason why,theirs but to do and die.
展开
-
HDU 5301 Buildings(思维:一道简单的难题)
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectang原创 2016-07-18 21:39:01 · 498 阅读 · 0 评论 -
HDU 1394 Minimum Inversion Number(用规律取代线段树)
Problem DescriptionThe inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i aj.For a given sequence of numbers a1, a2, ..., an, if we mov原创 2016-07-21 21:23:40 · 344 阅读 · 0 评论 -
HDU 4608 I-number(暴力模拟)
I-numberTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3968 Accepted Submission(s): 1415Problem DescriptionThe I-number of原创 2016-07-06 02:53:08 · 633 阅读 · 0 评论 -
STL之unique()去重函数
CF上的代码是开放的,常常就能看到本渣与大神们的差距比如去重。。。这是本鶸代码。。。。。。。#include#include#includeusing namespace std;const int N = 100000;int a[N+5];int b[N+5];int main(){ int n; while (cin>>n) {原创 2016-07-14 12:04:48 · 30836 阅读 · 7 评论 -
STL之resize()函数
size() 目前容器正拥有的元素个数capacity() 容器能储存的元素个数,即容量reserve() 重新指定容器能存储数据的个数resize() 重新指定容器有效的元素个数设元素原本的v.size()是n 当调用v.resize(m)后,有两种情况:1.若 m 2.若m > n ,则容器之前储存的n个元素不变,不足m的部分补0#includeu原创 2016-07-20 17:24:09 · 4440 阅读 · 0 评论 -
POJ 3273 Monthly Expense(二分)
题目链接:点击打开链接题目大意是说给n个数,要求分成m组,必须连续的数才能合并成一个组,求满足ans大于等于每一组的和的最小ans(每个组可以只有1个数)显然二分查找最小的ans//Must so#include#include#include#include#include#include#include#include#include#include#原创 2016-03-15 00:53:44 · 314 阅读 · 0 评论 -
HDU 2333Assemble(简单二分)
AssembleTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 628 Accepted Submission(s): 230Problem DescriptionRecently your team原创 2016-07-06 03:22:02 · 1281 阅读 · 2 评论 -
二叉查找树的简单创建和3种遍历
创建一棵二叉查找树并分别用先序遍历中序遍历后序遍历输出其实根据二叉搜索树的特点,中序遍历的结果就是从小到大的顺序输出,但为了练习树我还是用递归输出的题目:DescriptionBinary Search Tree, abbreviated as BST, is a kind of binary tree maintains the following p原创 2016-04-02 03:23:51 · 471 阅读 · 0 评论 -
线段树之HDU 1754 I hate it
题目:HDU 1754 I hate it!//Must so#include#define mem(a,x) memset(a,x,sizeof(a))#define sqrt(n) sqrt((double)n)#define pow(a,b) pow((double)a,(int)b)#define inf 1<<29#define NN 200006using names原创 2016-03-08 02:17:02 · 472 阅读 · 0 评论 -
HDU 1166 敌兵布阵(线段树&树状数组)
题目:HDU 1166 敌兵布阵线段树模板题同时也是树状数组模板题//Must so#include#define mem(a,x) memset(a,x,sizeof(a))#define sqrt(n) sqrt((double)n)#define pow(a,b) pow((double)a,(int)b)#define inf 1<<29#define NN 50004using name原创 2016-03-08 02:38:58 · 407 阅读 · 0 评论 -
HDU 5289 Assignment(线段树)
AssignmentTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3361 Accepted Submission(s): 1563Problem DescriptionTom owns a comp原创 2016-07-06 00:47:19 · 407 阅读 · 0 评论 -
POJ 2528 Mayor's posters(线段树区间离散化入门)
DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city counci原创 2016-07-08 10:03:07 · 1018 阅读 · 1 评论 -
HDU 4339 Query(线段树)
Problem DescriptionYou are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.Your task is to answer next queries: 1) 1 a i c - you should set i-th character in a-th string to c原创 2016-07-14 01:08:34 · 510 阅读 · 0 评论 -
HDU 5316 Magician(线段树区间合并)
Problem DescriptionFantasy magicians usually gain their ability through one of three usual methods: possessing it as an innate talent, gaining it through study and practice, or receiving it from a原创 2016-07-23 20:39:27 · 751 阅读 · 0 评论 -
HDU 3974 Assign the task(并查集)
Problem DescriptionThere is a company that has N employees(numbered from 1 to N),every employee in the company has a immediate boss (except for the leader of whole company).If you are the immediat原创 2016-07-14 03:34:27 · 804 阅读 · 0 评论 -
HDU 2066 一个人的旅行(Dijkstra模板题)
Problem Description虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景……草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女……眼看寒假就快到了,这么一大原创 2016-02-10 02:15:47 · 1073 阅读 · 1 评论 -
HUD 1874 畅通工程续(Dijkstra/spfa/floyd)
Problem Description某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。 Input本题目包含多组数据,请处理到文件结束。原创 2016-02-13 03:12:35 · 608 阅读 · 0 评论 -
HDU 3765 Celebrity Split(dfs走平分问题--递推)
Problem DescriptionJack and Jill have decided to separate and divide their property equally. Each of their N mansions has a value between 1,000,000 and 40,000,000 dollars. Jack will receive some o原创 2016-02-11 18:30:54 · 1140 阅读 · 0 评论 -
HUD 1003/HDU 1081:动态规划之最大子序列和+最大矩阵和
最大子序列和:HDU 1003 Max Sum用动态规划的思想,求解前i个数能获得的最大和,当sum如果sum > ans则更新ans和起点、终点。//Must so#include#include#include#define mem(a,x) memset(a,x,sizeof(a))#define sqrt(n) sqrt((double)n)#define pow(原创 2016-03-08 00:41:55 · 725 阅读 · 0 评论 -
最长公共子序列的长度和输出/HDU1159
给出两字符串,要求输出两字符串的最长公共子序列;这里有必要解释一下子串和子序列的区别,子串要求连续,子序列不必.也就是说,对于 "abckkkef" 和"abcef"这两字符串而言,他们最长的公共子串是"abc",而最长公共子序列是"abcef"最长公共子序列,最长上升子序列,很显然都是动态规划的思想,不同的是,"公共"的话是要对两个序列进行处理my code:#inc原创 2016-04-07 00:57:44 · 564 阅读 · 0 评论 -
HDU 1058Humble Numbers(dp)
题目被分类为dp,那么这样的解法应该也是dp吧题目:http://acm.hdu.edu.cn/showproblem.php?pid=1058注意一下输出格式就好[cpp] view plain copy//Must so #include #define mem(a,x) memset(a,x,si原创 2016-07-06 01:02:50 · 292 阅读 · 0 评论 -
HDU 1025 最长上升子序列(nlogn)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025第一次写最长上升子序列不是写的这题,所以对于这个最长上升子序列的模板题也没什么好说的,主要坑点在于,如果答案是一road用单数..............[cpp] view plain copy//Must so原创 2016-07-06 01:05:31 · 545 阅读 · 0 评论 -
HDU 3008 Warcraft(DP之状态的保存)
Problem DescriptionHave you ever played the Warcraft?It doesn't matter whether you have played it !We will give you such an experience.There are so many Heroes in it,but you could only choose one原创 2016-07-13 19:53:50 · 595 阅读 · 0 评论 -
HDU 4501 小明系列之买年货(三维背包)
Problem Description 春节将至,小明要去超市购置年货,于是小明去了自己经常去的都尚超市。 刚到超市,小明就发现超市门口聚集一堆人。用白云女士的话说就是:“那家伙,那场面,真是人山人海,锣鼓喧天,鞭炮齐呤,红旗招展。那可真是相当的壮观啊!”。好奇的小明走过去,奋力挤过人群,发现超市门口贴了一张通知,内容如下: 值此新春佳节来临之际,为了回馈广大顾客的支原创 2016-02-10 01:19:37 · 1387 阅读 · 0 评论 -
HDU 4563 御剑术I(背包)
Problem Description在众多武侠类游戏中,都可以看到主角衣袂飘飘地在一旁通过“气”操控剑在空中飞行来杀伤敌人的帅气场景。“十年磨一剑,霜刃未曾试”,在刻苦练习了不知道多少个日夜之后,今天你也掌握了这一项高超的武艺。虽然你可以并行地控制多柄剑同时飞行,但为了照顾普通群众的理解需求,暂时只考虑一把剑的情形。所谓御剑术,实质上就是通过“气”来传递信息给已经通灵的剑原创 2016-02-10 01:24:08 · 1360 阅读 · 0 评论 -
HDU 4508湫湫系列故事――减肥记i-简单的完全背包
Problem Description 对于吃货来说,过年最幸福的事就是吃了,没有之一! 但是对于女生来说,卡路里(热量)是天敌啊! 资深美女湫湫深谙“胖来如山倒,胖去如抽丝”的道理,所以她希望你能帮忙制定一个食谱,能使她吃得开心的同时,不会制造太多的天敌。 当然,为了方便你制作食谱,湫湫给了你每日食物清单,上面描述了当天她想吃的每种食物能带给她的幸福程度,以及会增原创 2016-02-10 01:32:48 · 885 阅读 · 0 评论 -
HDU 3732 Ahui Writes Word(01背包转化为多重背包)
Problem DescriptionWe all know that English is very important, so Ahui strive for this in order to learn more English words. To know that word has its value and complexity of writing (the length o原创 2016-02-12 01:08:10 · 566 阅读 · 0 评论 -
HDU 1372 Knight Moves(BFS)
Problem DescriptionA friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of原创 2016-02-13 01:41:44 · 414 阅读 · 0 评论 -
HDU 1548 A strange lift(最短路问题Dijkstra & bfs两种解法)
Problem DescriptionThere is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When原创 2016-02-13 07:37:36 · 587 阅读 · 0 评论 -
POJ 3253 Fence Repair(优先队列)
DescriptionFarmer 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 len原创 2016-02-26 20:37:43 · 379 阅读 · 0 评论 -
HDU 1026 Ignatius and the Princess I(BFS+优先队列)
Problem DescriptionThe Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrint原创 2016-02-27 05:04:21 · 459 阅读 · 0 评论 -
POJ 3126 Prime Path(BFS)
题目链接:POJ 3126 Prime Path题意:给出两个四位素数,要求从第一个素数变到第二个素数。 变换规则:每次只能改变四位数中的一个数,并且要求变换后的数依旧是素数。 求最少的变换次数。思路:先把1000-10000之间的数判断好是不是素数,之后直接用。 然后BFS搜索,每次变换一个数,变换后的数要求是素数,原创 2016-03-09 01:25:52 · 343 阅读 · 0 评论 -
HDU 1253 胜利大逃亡(空间BFS)
Problem DescriptionIgnatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个原创 2016-03-12 21:53:10 · 405 阅读 · 0 评论 -
HDU 1072 Nightmare (时间重置)BFS
Problem DescriptionIgnatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb原创 2016-07-06 00:58:06 · 974 阅读 · 0 评论 -
HDU 1043 Eight(经典八数码问题)对比POJ 1077(bfs)
题目链接:点击打开链接事情是这样的,我先在TLE无数发之后A了POJ的1077,然后在VJ上看到“原题”,然而,此原题被我TLE5发MLE9发,最后从学长那里学得记录路径的方法之后才过,却原来,这道所谓原题并非原题!!!HDU 的1043和POJ的1077都叫Eight,但是由于HDU上是多组数据POJ上单组,所以POJ上直接正常bfs搜索, HDU上则需要预处理。。。方法是一样的原创 2016-07-06 01:30:18 · 867 阅读 · 0 评论 -
POJ 1324Holedox Moving (状态BFS)
Holedox MovingTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 15264 Accepted: 3686DescriptionDuring winter, the most hungry and severe time, Holedox sle原创 2016-07-07 00:18:57 · 1229 阅读 · 0 评论 -
HDU 4771 Stealing Harry Potter's Precious(bfs+状态压缩)
Problem Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. When Hogwarts school is in holiday, Harry Potter has to go back to uncle Vernon's home.原创 2016-07-15 18:34:47 · 440 阅读 · 0 评论 -
HDU 1226 超级密码(BFS)
Problem DescriptionIgnatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密码是一个C进制的数,并且只能由给定的M个数字构成,同时密码是一个给定十进制整数N(0注意:由于宝藏的历史久远,当时的系统最多只能保存500位密码.因此如果得到的密码长度大于500也不能用来开启房门原创 2016-07-16 19:14:37 · 652 阅读 · 0 评论 -
POJ 2415 Hike on a Graph(bfs)
Description"Hike on a Graph" is a game that is played on a board on which an undirected graph is drawn. The graph is complete and has all loops, i.e. for any two locations there is exactly one arr原创 2016-07-19 23:52:57 · 512 阅读 · 0 评论 -
HDU 1241 Oil Deposits(DFS模板题)
Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates原创 2016-02-12 01:59:24 · 709 阅读 · 0 评论