C - Wooden Sticks
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Description
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
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
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这一题是学姐给的思路。就是先按照长度排序,然后再用flag记录是否访问过。#include<iostream>
#include<algorithm>
using namespace std;
typedef struct dot{
int l,w;
bool flag;
}dot;
bool cmp(dot a,dot b)
{
if(a.l!=a.l)return a.w<a.w;
else return a.l<b.l;
}
int main()
{
int T,n;
cin>>T;
while(T--)
{
cin>>n;
dot a[10000];
for(int i=0;i!=n;i++){
cin>>a[i].l>>a[i].w;
a[i].flag=0;
}
sort(a,a+n,cmp);
int sum=0;
for(int i=0;i!=n;i++){
if(a[i].flag==0){
sum++;
a[i].flag=1;
int k=i;
for(int j=k;j!=n;j++){
if(!a[j].flag&&a[k].w<=a[j].w){k=j;a[j].flag=1;}
}
}
}
cout<<sum<<endl;
}
return 0;
}贪心练得不好。。。。
C - Wooden Sticks的更多相关文章
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- HDU ACM 1051/ POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1051 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Wooden Sticks
Wooden Sticks Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU 1051 Wooden Sticks (贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- uvalive 2322 Wooden Sticks(贪心)
题目连接:2322 Wooden Sticks 题目大意:给出要求切的n个小木棍 , 每个小木棍有长度和重量,因为当要切的长度和重量分别大于前面一个的长度和重量的时候可以不用调整大木棍直接切割, 否则 ...
- Wooden Sticks(杭州电1051)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1051:Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- 最短路(dijskra+SPFA+Bellman)
最短路 Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- javascript高级知识点——内置对象原型
代码信息来自于http://ejohn.org/apps/learn/. 可以修改内置对象的方法. if (!Array.prototype.forEach) { Array.prototype.fo ...
- dp状态压缩-铺砖问题
题目:有一个n行m列的地板,需要用 1*2小砖铺盖,小砖之间互相不能重叠,问有多少种不同的铺法? 示范: 解法:用F[i][j]存放第i行的第j状态(j为十进制,转为二进制即是状态)有多少种方案. 用 ...
- nginx 几个参数
worker_processes : When set to 'auto', which is also the default behavior, Tengine will create the s ...
- op cache config
[opcache] ; dll地址 zend_extension=php_opcache.dll ; 开关打开 opcache.enable=1 ; 开启CLI opcache.enable_cli= ...
- Android RadioGroup/RadioButton
RadioGroup RadioButton的集合,提供多选一的机制 属性: android:orientation="horizontal/vertical&quo ...
- OC中NSArray的使用
不可变数组类容器类,管理一组对象类型的数据. 元素是有序的,索引值从0开始 数组中存储的元素必须是对象,类型任意. 创建数组对象,使⽤用实例初始化或便利构造器.获取元素个数.根据索引值获取对 ...
- GitHub 菜鸟使用
之前有用过一次,但是一直弄不明白怎么用,今天我又试了一下,成功了,现在我就记录下来,为了以后的使用以及帮助那些跟我原先一样不会用的同学 进入正题: Step 1: 注册GitHub账号 https:/ ...
- html中上标、下标、删除字、小号字等
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ArcEngine做栅格数据拉伸
//获得已打开的栅格数据 IRasterLayer rasterLayer = new RasterLayerClass(); rasterLayer = (IRasterLayer)axMapCon ...