#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;

}

  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. struct SIZE
  5. {
  6. int l;
  7. int w;
  8. }sticks[5005];
  9. int flag[5005];
  10. bool cmp(const SIZE &a,const SIZE &b)//这里是排序!
  11. {//写排序函数的时候要特别的小心!
  12. //if(a.w!=b.w)//这里写错了,这里表示如果重量不等,按照长度排,如果重量相等,则按照重量排!(没意义!)
  13. if(a.l!=b.l)
  14. return a.l>b.l;//长度不等时按照长度排,从大到小排
  15. else
  16. return a.w>b.w;//长度相等时,再按照重量从大到小排列
  17. }
  18. int main()
  19. {
  20. int n,min,cases;
  21. int i,j,s;
  22. cin>>cases;
  23. for(j=0;j<cases;j++)
  24. {
  25. cin>>n;
  26. for(i=0;i<n;i++)
  27. {
  28. cin>>sticks[i].l>>sticks[i].w;
  29. flag[i]=0;
  30. }
  31. sort(sticks,sticks+n,cmp);
  32. s=0;
  33. for(i=0;i<n;i++)
  34. {
  35. if(flag[i]) continue;
  36. min=sticks[i].w;
  37. for(int j=i+1;j<n;j++)
  38. {
  39. if(min>=sticks[j].w && !flag[j])
  40. {
  41. min=sticks[j].w;
  42. flag[j]=1;
  43. }
  44. }
  45. s++;
  46. }
  47. cout<<s<<endl;
  48. }
  49. //system("pause");
  50. return 0;
  51. }

hdu1051的更多相关文章

  1. hdu1051(LIS | Dilworth定理)

    这题根据的Dilworth定理,链的最小个数=反链的最大长度 , 然后就是排序LIS了 链-反链-Dilworth定理 hdu1051 #include <iostream> #inclu ...

  2. HDU1051 贪心

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. hdu1051 Wooden Sticks

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051 大意:求最少升序序列的个数. #include <cstdio> #include &l ...

  4. HDU1051 Wooden Sticks 【贪婪】

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDU1051:Wooden Sticks

    Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...

  6. hdu1051 Wooden Sticks---贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1051 题目大意:给你n根木棍的长度和重量.根据要求求出制作该木棍的最短时间.建立第一个木棍需要1分钟 ...

  7. 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 ...

  8. hdu1051 Wooden Sticks(贪心+排序,逻辑)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. Wooden Sticks(hdu1051)

    Wooden Sticks Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. dede调用二级下拉菜单方法

    <div id="menu">    <ul>  {dede:channelartlist typeid='top'  row='6' orderby='s ...

  2. EntityFramework 学习 一 Change Tracking in Entity Framework

    EntityFramework自动跟踪上下文中已经加载的实体,DbChangeTracker类给你关于当前实体的所有跟踪信息 注意,每个实体都要有EntityKey(主键)的属性,EntityFram ...

  3. centos5.5源更新方法(网易163源 很快的源)

    http://blog.chinaunix.net/uid-24993824-id-189965.html 1.首先,打开终端,获取root权限 2.关闭fastestmirror插件         ...

  4. CreateProcess 执行CMD命令,并重定向输出

    1. 参考网址:http://www.cnblogs.com/cnarg/archive/2011/02/20/1959292.html function TfrmMain.ExecDosCmd :b ...

  5. vmware workstation pro 安装ubantu虚拟机

    参考:https://ywnz.com/linuxaz/3904.html https://www.zhihu.com/search?type=content&q=vmware%20works ...

  6. python_doc 读写docx文件

    python读写word文档有现成的库可以处理,在这里采用了 python-docx. 首先先安装 pip install python-docx #!/usr/bin/env python # -* ...

  7. java--xml文件读取(DOM)

    1.表现:一“.xml”为扩展名的文件 2.存储:树形结构 3.xml解析应用: 不同应用程序之间的通信-->订票软件和支付软件 不同的平台间通信-->操作系统 不同平台间数据的共享--& ...

  8. 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 ...

  9. 热门游戏 2048 C++ 源代码分享

    /*By Reason*/ #include<iostream> #include <iomanip> #include<math.h> #include<s ...

  10. ACM学习历程—HDU4417 Super Mario(树状数组 && 离线)

    Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability re ...