UVA307 Sticks】的更多相关文章

题目大意:用n根长度未必相等的木棒匹配出最多数量的等长木棒. 题目分析:枚举所有可能的等长木棒的长度,通过DFS的方式逐根匹配,在此过程中要剪枝.先将木棒长度按从大到小排序,也就是说匹配每一根等长木棒时总是优先挑选长的.剪枝方案如下:1. 若第i-1根木棒在当前方案的匹配中没有用到并且length[i]==length[i-1],则第i根木棒也不可能用到:2.若已匹配成功cnt根等长木棒,而第cnt+1根匹配不成功,则要剪枝:3.若在匹配第cnt+1根木棒时,最长的那根木棒stick会第一个被选…
题意:一组等长的木棒,将它们随机的砍掉,得到若干根小木棍, 每一节小棍的长度都不超过50个单位.然后想把这些木棍拼接起来,恢复到裁剪前的状态, 但忘记了初始时有多少木棒以及木棒的初始长度.计算木棒的可能最小长度,每一节木棍的长度都用大于零的整数表示. 输入包含多组数据 这题很经典(有毒啊) 首先,对所有木棍排序(便于搜索) 然后倒着枚举初始木棒个数, 可以通过求平均算出木棒长度(最短),有解就输出(最优) 若当前个数无法被平均分,false 若当前答案比最长木棍小,false 然后开始搜索 详见…
小木棍Sticks[传送门] 算法的话:dfs+超强剪枝: (另外注意UVA上好像不接受万能头[因为万能头WA了两次,瑟瑟发抖]) 思路: 最直接的思路,枚举木棍长度来dfs,但这样很容易就TLE了. dfs的四项关键字: 1.num:剩多少切割后的木棍没有使用: 2.rest:还需要rest的长度可以凑成一个切割前的木棍: 3.len:切割前的木棍长度: 4.last:当前切割后的木棍起始的下标:(对于初始状态dfs last是1还是0好迷啊,好像初始状态是1或者0都可以ac???) 行吧就当…
题目大意: 乔治有一些碎木棒,是通过将一些相等长度的原始木棒折断得到的,给出碎木棒的总数和各自的长度,求最小的可能的原始木棒的长度:(就是将一些正整数分组,每组加起来和相等,使和尽可能小) 一开始做poj 32ms过,但uva3000 ms 都超时...而且poj discuss里给出了一组bT数据,最后uva 0.2sac的代码也跑了3 .4秒左右.discuss里的大牛据说什么奇偶性剪枝0.01ms过,可惜搜了半天也没找到具体方法.这题就这样过好了..(参考各种空间博客才艰难ac.不过此题实…
题目大意:有一堆小木棍,把它们接成相同长度的小木棍,问结果的小木棍的最小长度是多少,多组数据 题解:$dfs$,各种剪枝. 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #include <cstdlib> #define maxn 55 const int inf = 0x3f3f3f3f; int n, Min, Max, sum; int cnt[maxn]; bool halt; void dfs(i…
题目描述 pdf 题解 注意的问题是,各个原始木棒的长度都是一样的! 说一下本题的总思路即:DFS+超强力剪枝!(详见本人的 AC 程序) 首先,我们要从小到大枚举原始木棒的长度len,也就是枚举答案,最先找到的就是最小长度.那怎么确定枚举的是正确的呢?我们用的是搜索. 如果只搜索是极不理智的,而如果有了剪枝,一切就好说了,本题的剪枝主要有五个,我们会边看程序边了解一下. #include<iostream> #include<cstdio> #include<cstring…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15564    Accepted Submission(s): 6405 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段,这样就错了 因为如果线段8与5,6,7相交了,我们接下来不能直接判断4,我们还要找7,6,5与之前哪些相交 #include<set> #include<map> #include<queue> #include<stack> #include<cmat…
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=243 uva开头描述: 307 - Sticks Time limit: 3.000 seconds hduoj 开头描述: E - Sticks Time Limit:3000MS     Memo…
题意:n根木棍随意摆放在一个平面上,问放在最上面的木棍是哪些. 思路:线段相交,因为题目说最多有1000根在最上面.所以从后往前处理,直到木棍没了或者最上面的木棍的总数大于1000. #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> using namespace std; ; ; int sgn(double x){ ; ) ; ; } struct point…
Wooden Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21902   Accepted: 9353 Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworkin…
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define N 100005 using namespace std; struct Point { double x…
Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output After winning gold and silver in IOI 2014, Akshat and Malvika want to hav…
RMQ+二分....枚举 i  ,找比 i 小的第一个元素,再找之间的第一个最大元素.....                   Sticks Problem Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 9338   Accepted: 2443 Description Xuanxuan has n sticks of different length. One day, she puts all her stick…
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 593    Accepted Submission(s): 193 Problem Description The story happened long long ago. One day, Cao Cao made a special order c…
Pick-up sticksTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2950 Accepted Submission(s): 1108 Problem DescriptionStan has n sticks of various length. He throws them one at a time on the floor in…
点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted: 7403 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks…
Sticks Problem's Link:   http://poj.org/problem?id=1011 Mean: http://poj.org/problem?id=1011&lang=zh-CN&change=true analyse: 爆搜,但是其中蕴含着很多剪枝. Time complexity: O(n^2) Source code:  // Memory Time // 1347K 0MS // by : Snarl_jsb // 2014-11-07-17.14 #i…
题意: 按顺序扔木棒,求出最上层的木棒是哪些. 解法: 由于最上层的木棒不超过1000个,所以用一个队列存储最上层的木棒,每次扔出一个木棒后,都与队列中的木棒一一判断,看此木棒是否在某一最上层的木棒的上面,即判线段是否相交(两次跨立实验),如果相交,则将那个被压的木棒抛出队列,最后再加入扔的这个木棒到队列中. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib…
题 题意 给你六根木棍的长度,熊需要头比身体短,大象需要头和身体一样,四肢要一样长,否则就是外星人.请你判断能组成哪一个. 分析 暴力,循环看一下每根有几根相同的,然后如果有四根都是有四根相同的&&有两根是有两根相同的||有六根是有六根相同的,那就是大象,如果出现有五根相同的,或者不满足上面大象的条件,但是有四根四根相同,那就是熊,其它情况就是外星人.当时是另一种做法.感觉现在的做法思路更简单. 代码 #include<stdio.h> #include<algorith…
Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were original…
Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 28036   Accepted: 7428 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a st…
Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 600    Accepted Submission(s): 169 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situa…
Sticks Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1455 Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to…
题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /************************************************ * Author :Running_Time * Created Time :2015/10/26 星期一 15:37:36 * File Name :POJ_2653.cpp ************************************************/ #inclu…
题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索:5 若新的搜索连第一条都没组合出来,直接break: 详细解释:http://blog.csdn.net/lyy289065406/article/details/6647960 http://www.cnblogs.com/devil-91/archive/2012/08/03/2621787.…
http://poj.org/problem?id=2653 我很好奇为什么这样$O(n^2)$的暴力能过.... 虽然说这是加了链表优化的,但是最坏不也是$O(n^2)$吗...(只能说数据太弱...) 然后本题裸的判线段相交和点在直线上...(看了网上的标程,不判端点的情况都能过我也是醉了...) #include <cstdio> #include <cstring> #include <cmath> #include <string> #includ…
这题是暴力加贪心,算是一道水题吧!只要把l和w从小到大排个序就行了... #include"iostream" #include"stdio.h" #include"string.h" #include"cmath" #include"algorithm" #include"queue" #define mx 10005 using namespace std; struct node…
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 32423 Accepted: 8556 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straig…
Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126238   Accepted: 29477 Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the or…