头一次接触POJ,然后写了自己比较擅长的贪心。

解题思路大概就是从小排(这个很重要,然后用cmp随便长度或者重量的排序,选择最小的开始)

直到所有比他weight大的,没有符合条件的了。就代表要再加一分钟了。

然后再次访问,用used标记有没有用过。

和活动顺序排序有点类似。

/**测试样例:
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 2
1
3
**/ #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define MAX_N 5000+10
int used[MAX_N];
struct node
{
int len;
int wei;
}a[MAX_N];
int cmp(node a,node b)
{
if(a.len==b.len)
return a.wei<b.wei;
return a.len<b.len;
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
int ans = 0;
memset(used,0,sizeof(used));
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].len,&a[i].wei);
sort(a,a+n,cmp);
for(int j=0;j<n;j++)
{
if(used[j]) continue;
int weimax = a[j].wei;
ans++;
for(int i=j+1;i<n;i++)
{
if(!used[i]&&a[i].wei>=weimax)
{
used[i]=1;
weimax = a[i].wei;
}
}
}
printf("%d\n",ans);
}
return 0;
}

【贪心】POJ 1065的更多相关文章

  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 (贪心or dp)

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

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

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

  5. poj 1065 Wooden Sticks_贪心

    题意:将木棍放在机器里处理,第一根需要一分钟,剩余的如果大于等于前边放入的长度和重量,就不用费时间,否则需要一分钟,计算给出一组数的最少时间. 思路:先按长度排序,相同在比较重量,然后按顺序比较得出结 ...

  6. poj 1065 简单的贪心算法

    题意大概是:有一组木头需要处理,每块木头有长度,重量两个属性,处理的前一块木头长len,重wei,当下一块木头的len1,与wei1满足:len1>len&&wei1>we ...

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

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

  8. POJ 1065 Wooden Sticks【贪心】

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

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

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

随机推荐

  1. LoadRunner 函数之 web_custom_request

    Allows you to create a custom HTTP request with any method supported by HTTP. List of Attributes URL ...

  2. IIS错误处理集合

    1.编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ya ...

  3. 调整Virtual Box硬盘大小

    我在Mac下使用Virtual Box安装Win7的虚拟机.因为之前装过Win7的32位版.现在因为机器内存升到8G,就可以划出4G来支持Win7虚拟机.所以就重新安装了Win7的64位版.在创建虚拟 ...

  4. SQL Server遍历表的几种方法

    在数据库开发过程中,我们经常会碰到要遍历数据表的情形,一提到遍历表,我们第一印象可能就想到使用游标,使用游标虽然直观易懂,但是它不符合面向集合操作的原则,而且性能也比面向集合低.当然,从面向集合操作的 ...

  5. [nosql之redis]yum安装redis

    1.首先对于这种nosql来说目前我用到的功能很少,所以感觉没有必要去优化他跟不需要去编译安装.今天来介绍下一个yum安装redis 步骤1:安装扩展yum库 [root@localhost ~]# ...

  6. mysql [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist (转载)

    mysql报错Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist 2013-11-2 ...

  7. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  8. PHP中的错误处理、异常处理机制详解

    在编写PHP程序时,错误处理是一个重要的部分.如果程序中缺少错误检测代码,那么看上去很不专业,也为安全风险敞开了大门 例: <?php $a = fopen('test.txt','r'); / ...

  9. java基础 集合 ArrayList 增删改除

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  10. javascript基础04

    javascript基础04 1.循环语句 1.While 语句: while (exp) { //statements; } var i = 1; while(i < 3){ alert(i) ...