hdu1051
#include<iostream>
#include<algorithm>
using namespace std;
struct SIZE
{
int l;
int w;
}sticks[5005];
int flag[5005];
bool cmp(const SIZE &a,const SIZE &b)//这里是排序!
{//写排序函数的时候要特别的小心!
//if(a.w!=b.w)//这里写错了,这里表示如果重量不等,按照长度排,如果重量相等,则按照重量排!(没意义!)
if(a.l!=b.l)
return a.l>b.l;//长度不等时按照长度排,从大到小排
else
return a.w>b.w;//长度相等时,再按照重量从大到小排列
}
int main()
{
int n,min,cases;
int i,j,s;
cin>>cases;
for(j=0;j<cases;j++)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>sticks[i].l>>sticks[i].w;
flag[i]=0;
}
sort(sticks,sticks+n,cmp);
s=0;
for(i=0;i<n;i++)
{
if(flag[i]) continue;
min=sticks[i].w;
for(int j=i+1;j<n;j++)
{
if(min>=sticks[j].w && !flag[j])
{
min=sticks[j].w;
flag[j]=1;
}
}
s++;
}
cout<<s<<endl;
}
//system("pause");
return 0;
}
- #include<iostream>
- #include<algorithm>
- using namespace std;
- struct SIZE
- {
- int l;
- int w;
- }sticks[5005];
- int flag[5005];
- bool cmp(const SIZE &a,const SIZE &b)//这里是排序!
- {//写排序函数的时候要特别的小心!
- //if(a.w!=b.w)//这里写错了,这里表示如果重量不等,按照长度排,如果重量相等,则按照重量排!(没意义!)
- if(a.l!=b.l)
- return a.l>b.l;//长度不等时按照长度排,从大到小排
- else
- return a.w>b.w;//长度相等时,再按照重量从大到小排列
- }
- int main()
- {
- int n,min,cases;
- int i,j,s;
- cin>>cases;
- for(j=0;j<cases;j++)
- {
- cin>>n;
- for(i=0;i<n;i++)
- {
- cin>>sticks[i].l>>sticks[i].w;
- flag[i]=0;
- }
- sort(sticks,sticks+n,cmp);
- s=0;
- for(i=0;i<n;i++)
- {
- if(flag[i]) continue;
- min=sticks[i].w;
- for(int j=i+1;j<n;j++)
- {
- if(min>=sticks[j].w && !flag[j])
- {
- min=sticks[j].w;
- flag[j]=1;
- }
- }
- s++;
- }
- cout<<s<<endl;
- }
- //system("pause");
- return 0;
- }
hdu1051的更多相关文章
- hdu1051(LIS | Dilworth定理)
这题根据的Dilworth定理,链的最小个数=反链的最大长度 , 然后就是排序LIS了 链-反链-Dilworth定理 hdu1051 #include <iostream> #inclu ...
- HDU1051 贪心
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu1051 Wooden Sticks
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051 大意:求最少升序序列的个数. #include <cstdio> #include &l ...
- HDU1051 Wooden Sticks 【贪婪】
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU1051:Wooden Sticks
Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...
- hdu1051 Wooden Sticks---贪心
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1051 题目大意:给你n根木棍的长度和重量.根据要求求出制作该木棍的最短时间.建立第一个木棍需要1分钟 ...
- Hdu1051 Wooden Sticks 2017-03-11 23:30 62人阅读 评论(0) 收藏
Wooden Sticks Problem Description There is a pile of n wooden sticks. The length and weight of each ...
- hdu1051 Wooden Sticks(贪心+排序,逻辑)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Wooden Sticks(hdu1051)
Wooden Sticks Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
随机推荐
- dede调用二级下拉菜单方法
<div id="menu"> <ul> {dede:channelartlist typeid='top' row='6' orderby='s ...
- EntityFramework 学习 一 Change Tracking in Entity Framework
EntityFramework自动跟踪上下文中已经加载的实体,DbChangeTracker类给你关于当前实体的所有跟踪信息 注意,每个实体都要有EntityKey(主键)的属性,EntityFram ...
- centos5.5源更新方法(网易163源 很快的源)
http://blog.chinaunix.net/uid-24993824-id-189965.html 1.首先,打开终端,获取root权限 2.关闭fastestmirror插件 ...
- CreateProcess 执行CMD命令,并重定向输出
1. 参考网址:http://www.cnblogs.com/cnarg/archive/2011/02/20/1959292.html function TfrmMain.ExecDosCmd :b ...
- vmware workstation pro 安装ubantu虚拟机
参考:https://ywnz.com/linuxaz/3904.html https://www.zhihu.com/search?type=content&q=vmware%20works ...
- python_doc 读写docx文件
python读写word文档有现成的库可以处理,在这里采用了 python-docx. 首先先安装 pip install python-docx #!/usr/bin/env python # -* ...
- java--xml文件读取(DOM)
1.表现:一“.xml”为扩展名的文件 2.存储:树形结构 3.xml解析应用: 不同应用程序之间的通信-->订票软件和支付软件 不同的平台间通信-->操作系统 不同平台间数据的共享--& ...
- codeforces 632B B. Alice, Bob, Two Teams(暴力)
B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input s ...
- 热门游戏 2048 C++ 源代码分享
/*By Reason*/ #include<iostream> #include <iomanip> #include<math.h> #include<s ...
- ACM学习历程—HDU4417 Super Mario(树状数组 && 离线)
Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability re ...