HDUOJ------------1051Wooden Sticks
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9937 Accepted Submission(s): 4081
(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).
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct
{
int we;
int le;
int tag;
}go;
int cmp(go const a, go const b)
{
/*升序*/
if(a.le==b.le)
{
if(a.we<b.we) return ;
else return ;
}
if(a.le<b.le) return ;
else return ;
}
int main()
{
int t,n,cnt;
vector<go>st;
go tem;
scanf("%d",&t);
while(t--)
{
st.clear();
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&tem.le,&tem.we);
tem.tag=true;
st.push_back(tem);
}
sort(st.begin(),st.end(),cmp);
vector<go>::iterator it,tem;
cnt=;
bool falg;
while(!st.empty())
{
falg=true;
for(it=st.begin(); it!=st.end();it++)
{
if(it->tag&&falg) tem=it;
if(it->tag&&tem->we<=it->we)
{
tem=it;
it->tag=false;
falg=false;
}
}
if(!falg) cnt++;
else break;
}
printf("%d\n",cnt);
}
return ;
}
HDUOJ------------1051Wooden Sticks的更多相关文章
- hdu 1051Wooden Sticks
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000 using na ...
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 2653 Pick-up sticks (线段相交)
题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...
- POJ 2653 Pick-up sticks【线段相交】
题意:n根木棍随意摆放在一个平面上,问放在最上面的木棍是哪些. 思路:线段相交,因为题目说最多有1000根在最上面.所以从后往前处理,直到木棍没了或者最上面的木棍的总数大于1000. #include ...
- POJ1065Wooden Sticks[DP LIS]
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21902 Accepted: 9353 De ...
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- CF451A Game With Sticks 水题
Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second mem ...
- POJ 2452 Sticks Problem
RMQ+二分....枚举 i ,找比 i 小的第一个元素,再找之间的第一个最大元素..... Sticks Problem Time Limit: 6000MS ...
- The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
随机推荐
- 物联网(IoT)的11大云平台:AWS、Azure、谷歌云、Oracle、
物联网(IoT)的11大云平台:AWS.Azure.谷歌云.Oracle. 2018-11-06 14:02 云技术 关键词:物联网AzureGoogleSalesforce云计算 导读:现在,我们将 ...
- javascript和python取dict字典对象的不同
dict1={"a":1,"b":2,"22a":44} JS: dict1.a 和 dict1["a"]都可以 pyt ...
- Windows 7系统垃圾清理自写程序
系统清理.bat @echo off color 0a title windows7系统垃圾清理--- echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★☆ ★☆ ★☆★ echo ★☆ ★☆ ...
- 遇到Elements in iteration expect to have 'v-bind:key' directives.' 这个错误
解决方式一:更改VS Code编辑器的vetur配置 错误提示: [vue-language-server] Elements in iteration expect to have 'v-bind: ...
- WebSettings 文档 API 翻译 常用设置
. setDefaultFontSize(int size) Sets the default font size. The default is 16. setDefaultTextEncodin ...
- [转]VirtualBox 修改UUID实现虚拟硬盘复制
-------------------------------------------------------------------- 原文:https://www.cnblogs.com/find ...
- 使用Zxing开发Air版二维码扫描工具
简介实现的核心要点和几个须要注意的问题: 使用开源类库:Zxing,微信也是用的这个.下载地址:http://code.google.com/p/zxing/ as版:https://github.c ...
- CoCreateInstance(转)
CoCreateInstance 创建组件的最简单的方法是使用CoCreateInstance函数. 在COM库中包含一个用于创建组件的名为CoCreateInstance的函数.此函数需要一个 ...
- bash參考手冊之六(Bash特性)
6 Bash 特性 这部分描写叙述Bash独有的特性. * 调用Bash : Bash能够接受的命令行选项. * Bash启动文件 : Bash何时及怎样运行脚本. * 交互Shell : 什么 ...
- 【C#】C#委托学习
虽然做.NET这行也快2年了,但基础不太好啊,今天看了下委托方面的知识,记录下. 1.委托 总的来说,委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋 ...