## 题目描述

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.

```2
1
3
```

## AC代码

````#include<iostream>`
`#include<algorithm>`
`#include<stdio.h>`
`using namespace std;`
`struct woods`
`{`
`    int l;`
`    int w;`
`}a[5000];`
`bool cmp(woods a, woods b)`
`{`
`    if (a.l < b.l)`
`        return 1;`
`    else if (a.l == b.l)`
`    {`
`        if (a.w < b.w)`
`        return 1;`
`    }`
`    return 0;`
`}`
`int main()`
`{`
`    //freopen("date.in", "r", stdin);`
`    //freopen("date.out", "w", stdout);`
`    int N,m,sum,flag,count;`
`    cin >> N;`
`    woods tem;`
`    for (int i = 0; i < N; i++)`
`    {`
`        sum = 0;`
`        flag = 1;`
`        cin >> m;`
`        for (int j = 0; j < m; j++)`
`        { `
`            cin >> a[j].l >>a[j].w;`
`        }`
`        sort(a, a+m, cmp);`
`        /*for (int l = 0; l < m; l++)`
`        {`
`            cout << a[l].l << " " << a[l].w << endl;`
`        }*/`

`        for (int k = 0; k < m ; k++)`
`        {`
`            //count = 0;`
`            tem.l = a[k].l;`
`            tem.w = a[k].w;`
`            if (a[k].l != -1)`
`            {`
`                sum++;`
`                for (int l = k; l < m; l++)`
`                {`
`                    if (a[l].l >= tem.l&&a[l].w >= tem.w)`
`                    {`
`                        tem.l = a[l].l;`
`                        tem.w = a[l].w;`
`                        a[l].l = -1;`
`                        a[l].w = -1;`
`                        //count++;`
`                    }`
`                }`

`            }`
`        }`
`        cout << sum<<endl;`

`    }`
`}`
```

## SDAU课程练习--problemB(1001)的更多相关文章

1. SDAU课程练习--problemQ(1016)

题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...

2. SDAU课程练习--problemG(1006)

题目描述 Problem Description The highest building in our city has only one elevator. A request list is m ...

3. SDAU课程练习--problemO(1014)

题目描述 Before bridges were common, ferries were used to transport cars across rivers. River ferries, u ...

4. SDAU课程练习--problemA(1000)

题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...

5. SDAU课程练习--problemC

题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...

6. SDAU课程练习--problemE

problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...

7. 4、json-server的使用

json-server 详解 转载于https://www.cnblogs.com/fly_dragon/p/9150732.html JSON-Server 是一个 Node 模块,运行 Expre ...

8. 一分钟内搭建全web的API接口神器json-server详解

JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为 api 的数据源. 安装json-server npm install -g json ...

9. json-server 详解

JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为 api 的数据源. 安装json-server npm install -g json ...

## 随机推荐

1. jq 修改input 标签的值

<input type="number" id="output" placeholder="0" /> jq使用方法 \$('#o ...

2. iOS 关于Layer的疑问

很久很久以前,就对ios的Layer十分的不解,学习了android后,打算通过android中的相关实现,分析一下ios中layer的作用,结果没有找到android中的对应的内容!十分让人郁闷.于 ...

3. 使用 HTML5 Shiv 让 IE 支持 HTML5

HTML5 Shiv 使用 html5.js 必须在页面head元素内调用(因为 IE 必须在元素解析前知道这个元素,所以这个 JS 文件不能在页面底部调用.) 作者已经把js文件放在Google c ...

4. FreeBSD下查看各软件版本命令

查看FreeBSD版本: uname -a root# uname -a FreeBSD power 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02 ...

5. PHP基于变量的引用实现的树状结构

直接上代码: function aryTree(\$ary, \$tagId = 'id', \$tagPid = 'pid', \$tagSub = '_sub') { if(is_array(\$ary)) ...

6. JavaScript———从setTimeout与setInterval到AJAX异步

setTimeout与setInterval执行 首先我们看一下以下代码打印结果 console.log(1); setTimeout(function() { console.log(2); },1 ...

7. CSS规范--春风十里不如写好CSS

先吟几句: 最近看了看春风十里不如你,本来很少看剧的,暑假有点闲就看了,感觉不错,挺喜欢这部剧,就套了个名字,嘿嘿嘿.剧里面印象深刻的是<致橡树>这首诗,念几句: 我如果爱你,绝不像攀援的 ...

8. 移动App开发基本技术面

1.UI布局 1.1.熟悉系统布局基本机制和使用方法 2.界面效果 2.1.熟悉系统提供的所有界面组件 2.2.熟悉各种功能界面效果的实现途径 2,3.动画等特殊UI效果的实现机制 3.网络请求 3. ...

9. anki server 错误与解决

anki 客户端 转载请注明出处 :http://www.cnblogs.com/qq-757617012/ 1.无法同步 是否突然停电,导致程序损坏(提示被防火墙或杀毒软件阻止)     anki客 ...

10. 三、u-boot 的配置-mkconfig 脚本

3.1 mkconfig 脚本 100ask24x0_config : unconfig @\$(MKCONFIG) \$(@:_config=) arm arm920t 100ask24x0 NULL ...