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
(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).
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
1
3
#include "cstdio"
#include "iostream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
#define mj
#define db double
#define ll long long
using namespace std;
;
;
;
bool u[N];
typedef struct stu{
int l,w;
}M;
M s[];
int cmp(M a,M b)
{
if(a.l==b.l) return a.w>=b.w;
return a.l>=b.l;
}
int main()
{
int t,n,i,j,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
;i<n;i++)
scanf(;
sort(s,s+n,cmp);
int mi;
ans=;
;i<n;i++)
{
if(u[i]) continue;
mi=s[i].w;
;j<n;j++)
{
if(!u[j]&&s[j].w<=mi){
mi=s[j].w;
u[j]=;
}
}
ans++;
}
printf("%d\n",ans);
}
;
}
HDU 1051 Wooden Sticks 贪心||DP的更多相关文章
- HDU 1051 Wooden Sticks (贪心)
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) ...
- HDU 1051 Wooden Sticks 贪心题解
本题一看就知道是最长不减序列了,一想就以为是使用dp攻克了. 只是那是个错误的思路. 我就动了半天没动出来.然后看了看别人是能够使用dp的,只是那个比較难证明其正确性,而其速度也不快.故此并非非常好的 ...
- hdu 1051 wooden sticks (贪心+巧妙转化)
#include <iostream>#include<stdio.h>#include<cmath>#include<algorithm>using ...
- hdu 1051:Wooden Sticks(水题,贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ.1051 Wooden Sticks (贪心)
Wooden Sticks 点我挑战题目 题意分析 给出T组数据,每组数据有n对数,分别代表每个木棍的长度l和重量w.第一个木棍加工需要1min的准备准备时间,对于刚刚经加工过的木棍,如果接下来的木棍 ...
- HDU 1051 Wooden Sticks 造木棍【贪心】
题目链接>>> 转载于:https://www.cnblogs.com/Action-/archive/2012/07/03/2574800.html 题目大意: 给n根木棍的长度 ...
- HDU 1051 Wooden Sticks
题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1 ...
随机推荐
- 开关调色新世界BP2888电源解决方案
LED智能方案经过几年的拼杀,已经风靡照明界.但人们渐渐发现,对照明来说,一味追求花哨的功能并不被市场所认同,而其中开关调色,以其简单易操作的特点,已逐步融入广大消费者的生活习惯中.对吸顶灯,面板灯等 ...
- Fisher Vector Encoding and Gaussian Mixture Model
一.背景知识 1. Discriminant Learning Algorithms(判别式方法) and Generative Learning Algorithms(生成式方法) 现在常见的模式 ...
- 不知道Linux的mysql的root密码
用了好几次了这个方法.记一下: 1.停止Mysql /etc/init.d/mysql stop 或者(根据安装配置的位置不同,而不同) /etc/init.d/mysqld stop 2.进入Mys ...
- Zepto源码分析-动画(fx fx_method)模块
源码注释 // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT l ...
- 将 FFmpeg 移植到 Android平台 (完整版)
首先需要去FFmpeg的官网http://www.ffmpeg.org/去下载FFmpeg的源码,目前的版本号为FFmpeg3.3(Hilbert). 下载的文件为压缩包,解压后得到ffmpeg-3. ...
- 【小练习06】HTML+CSS--电影公告
要求实现如下效果图: 代码演示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- wpf XAML xaml 进行 数据绑定,Resource DataContext ElementName
先做个声明:这里绑定都在前台实现,至于后台怎么写,那比前台简单多了,但更常用的是xaml中绑定.我们分析下最简单的字符串绑定来弄清楚原理,其他的类推就是. 数据绑定主要是要弄清楚两个东西,一个是源So ...
- 关于AD9516芯片的硬件设计和FPGA程序编写心得
最近在做一个项目,其中有涉及时钟芯片AD9516的硬件设计和软件编程,有些使用心得,供大家参考讨论. AD9516,这是一个由ADI公司设计的14路输出时钟发生器,具有亚皮秒级抖动性能,还配有片内集成 ...
- form表单在前台转json对象
会发生序列化乱码问题,待解决. //根据表单id将其内空间,名称,值转为json var fireTraceEquipment =queryParamByFormId('form1'); functi ...
- Spring学习(22)--- AOP之Advice应用(下)
(六)Advice parameters(advice带参数的情况) 例子: 修改MyAspect(添加around_init方法): package com.aop.schema; import o ...