http://poj.org/problem?id=1065

题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度

都大于前一根木棍,那么这根木棍不需要生产时间,问你最少的生产时间是多少?

首先可以贪心,先按长度 l排序,如果l相同,按宽度w排序。

从i=0开始,每次把接下来的i+1  -  n-1 的没有标记并且长度和宽度大于等于i这根木棍的长度和宽度标记起来。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ; struct point
{
int l,w;
bool operator < (const point &a) const
{
return l==a.l ? w<a.w : l<a.l;
}
}p[maxn]; int mark[maxn]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].l,&p[i].w);
}
sort(p,p+n);
//for(int i=0;i<n;i++) printf("%d %d\n",p[i].l,p[i].w);
int s=;
memset(mark,,sizeof(mark));
for(int i=;i<n;i++)
{
int temp=p[i].w;
if(!mark[i])
{
for(int j=i+;j<n;j++)
{
if(p[j].w>=temp&&!mark[j])
{
temp=p[j].w;
mark[j]=;
}
}
s++;
}
}
printf("%d\n",s);
}
return ;
}

dp:排序跟上面一样,然后就是找 w 的最长下降子序列。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ; struct point
{
int l,w;
bool operator < (const point &a) const
{
return l==a.l ? w<a.w : l<a.l;
}
}p[maxn]; int dp[maxn]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].l,&p[i].w);
}
sort(p,p+n);
//for(int i=0;i<n;i++) printf("%d %d\n",p[i].l,p[i].w);
int ans=;
for(int i=;i<n;i++) dp[i]=;
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
if(p[j].w>p[i].w) dp[i]=max(dp[i],dp[j]+);
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

poj -1065 Wooden Sticks (贪心or dp)的更多相关文章

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

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

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

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

  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

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

  5. HDU ACM 1051/ POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)

    题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...

  7. 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 ...

  8. POJ 1065 Wooden Sticks Greed,DP

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

  9. POJ 1065 Wooden Sticks【贪心】

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

随机推荐

  1. 01.FastDFS的安装部署

    1.FastDFS简介 (1)FastDFS的功能介绍 FastDFS是一个开源的分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负 ...

  2. js判断手机还是pc并跳转相关页面

    <script type="text/javascript"> function GetRequest() { var url = location.search; / ...

  3. CentOS 有gcc没有g++

    [root@localhost ~]# which gcc/usr/bin/gcc[root@localhost ~]# which g++/usr/bin/which: no g++ in (/us ...

  4. Sqli-labs less 49

    Less-49 本关与47关基本类似,区别在于没有错误回显,所以我们可以通过延时注入和导入文件进行注入. 利用延时注入 http://127.0.0.1/sqli-labs/Less-49/?sort ...

  5. MAC OS下使用Xcode进行GLSL编程的配置过程

    整理自之前使用的163博客原创文章. GLSL项目中需要使用GLEW库,因此先要安装GLEW库和在Xcode中配置GLEW.要使GLEW在Xcode中被正确链接,又需要通过MacPorts来安装GLE ...

  6. 国内Jquery CDN

    新浪CDN: <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js">< ...

  7. win7建wifi 热点,附wifi小工具

    首先申明:1)以下操作均在管理员身份下操作,其他用户下请亲测.                2)具备无线网卡,并且已经安装好了驱动. 1.打开命令行:输入netsh wlan set hostedn ...

  8. NSArray block用法

    28.使用block 块遍历整个数组.这个block 需要三个参数,id obj 表示数组中的元素. NSUInteger idx 标示元素的下标, bool *stop 是一个bool类型的参数. ...

  9. netaddr 0.7.12

    Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses https://pypi.python.org/pyp ...

  10. PHP 字符串函数--替换、正则匹配等

    名称 支持正则 特 点 备注 str_replace X 字符串替换函数,大小写敏感   str_ireplace X 字符串替换函数,大小写不敏感,支持数组式批量替换 感谢网友franci, 提醒添 ...