Problem Description
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows: 
(a) The setup time for the first wooden stick is 1 minute.  (b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup. 
You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).
 
Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.
 
Output
The output should contain the minimum setup time in minutes, one per line.
 
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
 
Sample Output
2 1 3
 
//嗯,加油~
 
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; int mark[]; struct node
{
int a;
int b;
} data[]; bool cmp(const node &a,const node &b)
{
if(a.a>b.a)
return true;
if(a.a==b.a)
{
if(a.b>b.b)
return true;
else return false;
}
if(a.a<b.a)
return false;
} int main()
{
int t,n,ans,m;
cin>>t;
while(t--)
{
cin>>n;
memset(mark,,sizeof(mark));
ans=;
for(int i=;i<n;i++)
cin>>data[i].a>>data[i].b;
sort(data,data+n,cmp);
//for(int i=0;i<n;i++)
//cout<<data[i].a<<" "<<data[i].b<<endl;
for(int i=;i<n;i++)
{
if(mark[i]==)
{
ans++;
m=i;
for(int j=i+;j<n;j++)
{
if(data[m].b>=data[j].b&&mark[j]!=)
{
mark[j]=;
m=j;
}
}
} }
cout<<ans<<endl; }
return ;
}

HDU1051:Wooden Sticks的更多相关文章

  1. HDU 1051:Wooden Sticks

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

  2. HDU 1051: Wooden Sticks(贪心)

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

  3. HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)

    嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...

  4. HDU1051 Wooden Sticks 【贪婪】

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

  5. Hdu1051 Wooden Sticks 2017-03-11 23:30 62人阅读 评论(0) 收藏

    Wooden Sticks Problem Description There is a pile of n wooden sticks. The length and weight of each ...

  6. hdu1051 Wooden Sticks(贪心+排序,逻辑)

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

  7. Wooden Sticks(hdu1051)

    Wooden Sticks Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  8. HDOJ 1051. Wooden Sticks 贪心 结构体排序

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

  9. Wooden Sticks

    Wooden Sticks Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. python 基础学习-总结1

    1.Python 简介 易学易懂,语法简单 不需编译,即可运行 比其他语言更简洁 不需要管理内存 1.1 什么是Python? python 是由Guido.van.Rossum于1989年始创,其根 ...

  2. sublime text 设置

    https://packagecontrol.io/installation#Simple 下载 php 自动补全 点击菜单栏的:Preferences: 选择:Setting-User项: 然后在大 ...

  3. C语言函数参数的传递详解

    一.三道考题 开讲之前,我先请你做三道题目.(嘿嘿,得先把你的头脑搞昏才行--唉呀,谁扔我鸡蛋?)考题一,程序代码如下:void Exchg1(int x, int y){   int tmp;    ...

  4. 【第七篇】Volley之处理Gzip数据

    一般对于API请求需带上GZip压缩,因为API返回数据大都是Json串之类字符串,GZip压缩后内容大小大幅降低. public class GZipRequest extends StringRe ...

  5. 关于 HSSF 和 XSSF 功能的开发者入门指南 (Apache POI 操作 Excel)

    关于 HSSF 和 XSSF 功能的开发者入门指南 笔者深夜无眠,特此对本文翻译一部分,未完成部分待后续更新 本文源文地址 意欲使用 HSSF 和 XSSF 功能快熟读写电子表格?那本文就是为你而写的 ...

  6. CentOS6.2编译gcc失败,kernel-headers错误

    准备转移到阿里云服务器,用的CentOS6.2 x64,虚拟机上用的 6.3版本,测试重装了好几次都没问题了,结果在云服务器上刚开始就出问题了... yum 安装的时候居然出错了,靠...网上 goo ...

  7. App提交Appstore审核流程【转】

    这是一个app提交到iTunces Connect被拒了4次摸索出来的经验,说多了都是泪,先让我擦擦...好了,话不多说,为了让中国的app不再那么容易被拒,或者被拒了不知道该咋办,我把我的小经验在这 ...

  8. 复习i++和++j

    一,新建一个Default.aspx页面 在Default.aspx.cs

  9. Llinux环境下编译并使用OpenCV

    http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html http://stacko ...

  10. IIS7部署MVC站点后,打开无法正常跳转到首页

    产品拿到安装包后想在本地安装测试一下,但是管理工具里没有IIS. 后来在windows功能里添加iis服务. 添加后成功安装. 但是第一次打开时,页面提示要“启用目录浏览”. 启用后,打开的却是站点目 ...