Wooden Sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8899    Accepted Submission(s): 3630

【解题思路】初学贪心仅知道一些理论的知识,这题说是贪心自己也没啥感觉,做题的思路是在抛开贪心的概念然后按照自己的想法实现出来,实现之后想在思路中找到贪心的影子,只能看到每次都是找尽可能多的stick仅此而已,Pursuiting...

Wa的原因是当时没考虑到stick的选择可以是不连续的,直接将排序后的次元素的比较上将后面一个跟前面一个进行比较。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define SIZE 5002 using namespace std; typedef struct sticks{
int L, w;
}sticks;
sticks stick[SIZE];
bool visit[SIZE];
int n; bool cmp(const sticks& a, const sticks& b)
{
if(a.w == b.w)
return a.L < b.L;
else return a.w < b.w;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int T, sum;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=; i<n; ++i)
scanf("%d%d", &stick[i].L, &stick[i].w);
sort(stick, stick+n, cmp);
sum = ;
memset(visit, false, sizeof(visit));
int curmax = ;
for(int i=; i<n; ++i)
{
if(visit[i]) continue;
curmax = stick[i].L;
sum++;
for(int j=i+; j<n; ++j)
{
if(!visit[j] && stick[j].L >= curmax)
{
visit[j] = true;
curmax = stick[j].L;
}
}
}
/* for(int i=0; i<n; ++i)
if(!i || stick[i].L<stick[i-1].L) sum++;
*/
printf("%d\n", sum);
}
return ;
}

HDU ACM 1051/ POJ 1065 Wooden Sticks的更多相关文章

  1. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

  2. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  3. POJ 1065 Wooden Sticks (贪心)

    There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...

  4. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  5. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  6. poj 1065 Wooden Sticks 【贪心 新思维】

    题目地址:http://poj.org/problem?id=1065 Sample Input 3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1 ...

  7. POJ 1065 Wooden Sticks【贪心】

    题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...

  8. POJ 1065 Wooden Sticks Greed,DP

    排序后贪心或根据第二关键字找最长下降子序列 #pragma comment(linker, "/STACK:1024000000,1024000000") #include< ...

  9. POJ 1065 Wooden Sticks#贪心+qsort用法

    (- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.h ...

随机推荐

  1. 关于c#字典key不存在的测试

    之前一直隐约记得没有创建key会报异常,测试了下. 测试结果: 写入值,如果不存在key,会自动创建. 取值,如果不存在key,会报异常. 一般用c#提供了尝试取值方法,不过有out参数,考虑写扩展 ...

  2. MVC用户登陆验证及权限检查(Form认证)

    1.配置Web.conf,使用Form认证方式   <system.web>     <authentication mode="None" />      ...

  3. 了解thinkphp(二)

    ThinkPHP的核心文件: Library文件夹下的Think文件夹目录 ThinkPHP的入口文件是: ThinkPHP.php , 我们在创建项目时都要引入这个入口文件!!! 一 , 项目的部署 ...

  4. MongoDB 学习笔记(五)索引

    http://www.cnblogs.com/stephen-liu74/archive/2012/08/01/2561557.html

  5. jquery ajax的async属性的理解

    $(function(){ queryTemplateSort(); // fillAddTemplatePage(); function queryTemplateSort() { $.ajax({ ...

  6. apiCloud创建APP项目

    1.注册一个apiCloud账户 2.创建一个应用 3.安装sublime插件 4.用sublime创建应用 5.配置参数,保证一致 6.上传代码,两种方式 一种是压缩成zip 一种是配置svn,通过 ...

  7. eclipse有生成不带参数的构造方法的快捷键吗

    你打上类名的2个字母,然后”alt“ +“/” 基本上选第一个就行了

  8. jQuery_效果(隐藏和显示)

    一.jQuery hide() 显示和 show()隐藏 通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素: <script type=" ...

  9. Unable to locate package update

    碰到这个问题后找到这个帖子就转了过来 当用apt-get更新软件包时常出现错误提示Unable to locate package update, 尤其是在ubuntu server上,解决方法是: ...

  10. 51nod1442 士兵的旅行

    裸网络流拆点就可以了... #include<cstdio> #include<cstring> #include<cctype> #include<algo ...