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. 第三方登录(1)OAuth(开放授权)简介及授权过程

    3个角色:服务方,开发者,用户 a.用户在第在服务注册填写个人信息, b.服务方开放OAuth, c.开发者在服务方申请第3方登录,在程序中得到令牌后,经用户同意,可得到用户的个人信息. OAuth ...

  2. [CF189A]Cut Ribbon(完全背包,DP)

    题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...

  3. 转载 近期微博吐槽言论存档,涉及“性能优化”、C++陋习等

    http://blog.csdn.net/solstice/article/details/9923615 近期微吐槽博言论存档,涉及“性能优化”.C++陋习等 写C++程序的几个陋习:class 名 ...

  4. 成功的GIT开发分支模型和策略

    详细图文并茂以及git flow工具解释参考: http://danielkummer.github.io/git-flow-cheatsheet/index.zh_CN.html 原文地址:http ...

  5. Debian 如何更改hdmi接口输出的分辨率

    1. 先删除无用的文件: a) Boot/boot.src b) Boot/script.bin 2. 打开boot/script.fex,找到disp_init节点 a) 将screenX_outp ...

  6. Qt之等待提示框(QTimer)

    简述 上节讲述了关于QPropertyAnimation实现等待提示框的显示,本节我们使用另外一种方案来实现-使用定时器QTimer,通过设置超时时间定时更新图标达到旋转效果. 简述 效果 资源 源码 ...

  7. office编程必不可少 [转]

    1. 微软官方实例: 段落.表格.图表 HOW TO:利用 Visual C# .NET 使 Word 自动新建文档 2. 学习资源 (1)Word in the Office 基础知识,必读,下面的 ...

  8. 51nod1364 最大字典序排列

    不断的在cur的后面找最大的符合条件的数扔到cur的前面. 用线段树维护操作就可以了. #include<cstdio> #include<cstring> #include& ...

  9. bzoj2396: 神奇的矩阵

    与51nod1140一样.不过这题是多组数据的...坑.... #include<cstdio> #include<cstring> #include<cctype> ...

  10. Codeforces 424 B Megacity【贪心】

    题意:给出城市(0,0),给出n个坐标,起始人数s,每个坐标k个人, 每个坐标可以覆盖到半径为r的区域,r=sqrt(x*x+y*y)的区域,问最小的半径是多少,使得城市的总人数大于等于1000000 ...