杨二哥扛把子

Problem A: 杨二哥扛把子

Time Limit: 1 Sec  Memory Limit: 128 MB

Description

在孙悟空出世之前,杨二哥一直是三界的扛把子,身为扛把子,没件像样的武器怎么行。于是二哥去东海龙王那给自己和小弟找武器。都说土豪靠装备,屌丝靠变异,杨二哥手里有这么一个运输武器的装备,将武器放在机器里处理,每件武器的重量(w)和长度(l)已给出,如果运输当前的武器比运输的前一件武器长度长且重量比前一件重,就不用费时间,否则需要一分钟,杨二哥的时间很宝贵,需要你安排放置的顺序,使得用时最少,计算运走n件武器的最少时间!

Input

多组输入数据。

输入n,木棍的个数。n<5000。

输入w(重量),l(长度)。1<w,l<1000000。

Output

输出所需要的时间。

Sample Input

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

HINT

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 struct node
 6 {
 7     int a,b;
 8 } a[100001];
 9 int cmp(struct node a,struct node b)
10 {
11     if(a.a==b.a)
12         return a.b<b.b;
13     return a.a<b.a;
14 
15 }
16 int main()
17 {
18     int n;
19     while(scanf("%d",&n)!=EOF)
20     {
21         int ans=0,flag[100001]= {0};
22         for(int i=0; i<n; i++)
23             scanf("%d%d",&a[i].a,&a[i].b);
24         sort(a,a+n,cmp);
25         for(int i=0; i<n; i++)
26         {
27             if(flag[i]==1)
28             {
29                 continue;
30             }
31          
32    for(int i1=i,j=i+1; j<n; j++)
33             {
34                 if(a[j].b>=a[i1].b&&flag[j]==0)
35                 {
36                     i1=j;
37                     flag[j]=1;
38                 }
39             }
40             ans++;
41         }
42         printf("%d
",ans);
43     }
44 }
原文地址:https://www.cnblogs.com/tianmin123/p/4742823.html