HDU 1051

题意:给你n个木块的长和宽,现在要把它送去加工,这里怎么说呢,就是放一个木块花费一分钟,如果后面木块的长和宽大于等于前面木块的长和宽就不需要花费时间,否则时间+1,问把这个木块送去加工的最短时间。

思路:还是结构体排序,长相等就以宽来排序,如果一个木块被送去加工了标记它不存在就可以了;

 1 #include<iostream>
 2 #include<cmath>
 3 #include<algorithm>
 4 using namespace std;
 5 struct wood{
 6     int l,r;
 7     int vi;
 8 }p[5050];
 9 int cmp(wood a,wood b)
10 {
11     if(a.l==b.l)
12         return a.r<b.r;
13     return  a.l < b.l;
14 }
15 int main()
16 {
17     int t; cin >> t;
18     while(t--){
19         int n;cin >> n;
20         for(int i=0;i<n;++i){
21             cin >> p[i].l >> p[i].r;
22             p[i].vi=1;
23         }
24         sort(p,p+n,cmp);        //如果满足 l<=l‘ and w<=w‘,则必然满足 l<=l‘,所以先以它的大小排个序
25         int sum,count;
26         sum=count=0;
27         while(count<n){    //    然后反复找
28             int kl=-1,kr=-1;
29             for(int i=0;i<n;++i){
30                 if(p[i].vi&&p[i].l>=kl&&p[i].r>=kr){
31                     p[i].vi=0;kl=p[i].l;kr=p[i].r;
32                     ++count;
33                 }
34             }
35             ++sum;
36         }
37         cout << sum << endl;
38     }
39     return 0;
40 }
时间: 2024-10-09 04:01:59

HDU 1051的相关文章

HDU 1051:Wooden Sticks

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11605    Accepted Submission(s): 4792 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a

HDU 1051 并查集+贪心

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11694    Accepted Submission(s): 4837 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar

HDU 1051(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1051 Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13534    Accepted Submission(s): 5590 Problem Description There is a pile of n w

HDU 1051 - Wooden Sticks

贪心吧 保证一维非递减的情况下,计算另一维上最少有几个非递减序列,就是答案 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 using namespace std; 5 int t,n; 6 struct P{ 7 int l,w; 8 }s[5005]; 9 bool cmp(P a,P b) 10 { 11 return a.l==b.l?a.w<b.w : a.l<b

贪心/hdu 1051 Wooden Sticks

#include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct node { int l,w; bool v; }; int n; node a[5010]; bool cmp(node x,node y) { if (x.l==y.l) return x.w<y.w; return x.l<y.l; } int main() { int T; scanf(

HDU 1051 - Rightmost Digit

找循环 1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 int t,m,p,q; 5 long long n; 6 int c[15],ans; 7 int main() 8 { 9 scanf("%d",&t); 10 while(t--) 11 { 12 scanf("%lld",&n); 13 m=n%10; 14 int cnt=0,i

HDU 1051 Wooden Sticks 贪心||DP

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22000    Accepted Submission(s): 8851 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar

HDU 1051 Wooden Sticks (贪心)

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11249    Accepted Submission(s): 4629 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a

HDU 1051: Wooden Sticks(贪心)

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11244    Accepted Submission(s): 4627 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a

HDU 1051 Wooden Sticks 贪心题解

本题一看就知道是最长不减序列了,一想就以为是使用dp解决了.不过那是个错误的思路. 我就动了半天没动出来.然后看了看别人是可以使用dp的,不过那个比较难证明其正确性,而其速度也不快.故此并不是很好的解决方法. 所以我就直接硬算,硬模拟选择出非减子序列,选完就出答案了. 思路: 1 按照长度排序 2 按照不减原则选择重量,选一个,消灭一个. 最后消灭完了,就处理完毕,答案就自然出来了. 原来是一道披着dp的外套的模拟题啊!一道伪装成难题的简单题. 代码也可以写的非常简洁: #include <st