(~ ̄▽ ̄)~*

这道题用到了cstdlib库的qsort()函数

用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.html

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std; struct stick
{
int l,w;
int flag;
}st[5005]; int cmp(const void *u,const void *v)
{
stick *a=(stick *)u;
stick *b=(stick *)v;
if(a->l == b->l)
return a->w - b->w;
else
return a->l - b->l;
} int main()
{
int cas,n,minT,W;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d %d",&st[i].l,&st[i].w);
st[i].flag=0;
}
qsort(st,n,sizeof(st[0]),cmp); //从小到大排序,如果l相等,则w小的排前 minT=0;
for(int i=0;i<n;i++)
{
if(!st[i].flag)
{
minT++;
W=st[i].w;
for(int j=i+1;j<n;j++)
{
if((!st[j].flag)&&st[j].w>=W)
{
st[j].flag=1;
W=st[j].w;
}
}
}
}
printf("%d\n",minT);
}
return 0;
}

POJ 1065 Wooden Sticks#贪心+qsort用法的更多相关文章

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

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

  3. HDU ACM 1051/ POJ 1065 Wooden Sticks

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

  4. POJ 1065 Wooden Sticks

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

  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(贪心+dp+最长递减子序列+Dilworth定理)

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

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

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

随机推荐

  1. xtrabackup在线备份主库,搭建slave,使用gtid模式

    mysql:5.6.29xtrabackup:2.2.10master:192.168.166.129slave:192.168.166.131mysql数据目录:/data/mysqlmysql备份 ...

  2. linux-命令-top

    top 实时动态显示系统状态.(cpu.内存.swap.task) 1. top  汇总cpu.内存.swap.task信息  和  列表展示进程维度的cpu.内存.swap.task信息 2. to ...

  3. 东秦C#课设002-简单的文本编辑器

    //加入的拖拽属性失败,dropenter声明方法待查. using System; using System.Collections.Generic; using System.ComponentM ...

  4. release management客户端无法连接到release management server的问题解决

    参考:http://myalmblog.com/2014/03/error-installing-release-management-client/ 装了服务器,装客户端.然后客户端连不上服务器. ...

  5. const 那点事儿

    修饰变量时 const char 与 char const 是等价的,例如 const char a = 'a'; char const a = 'a'; 表示变量a不能再被赋予其他值. 到指针时情况 ...

  6. drag

    1.draggable ="true"  元素可以拖拽了 2.拖拽元素事件: dragstart  拖拽前触发 drag 拖拽前.拖拽结束之间,连续触发 dragend 拖拽结束触 ...

  7. 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件

    创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文 ...

  8. css和css3学习

    css和css3学习 css布局理解 css颜色大全 样式的层叠和继承 css ::before和::after伪元素的用法 中文字体font-family常用列表 cursor属性 css选择器 F ...

  9. js实现多行文本超出一定字数显示省略号功能

    最近项目中遇到了一个关于超出一定字数用省略号显示的问题,其实这种形式很常见,公司简介.产品介绍啊里面都可能会用到,一行文字显示省略号很容易,多行就得想点办法了.在经过查阅.整理之后,我也算是实现了这个 ...

  10. Form提交时隐藏Token验证

    前端声称一个Token @Html.AntiForgeryToken() 后台对Token进行验证 AntiForgery.Validate();