#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. Android电池驱动【转】

    本文转载自:http://blog.sina.com.cn/s/blog_66a6a5ec0100n6ej.html Android的电池的管理分为三个部分:Java部分,JNI部分以及kenel部分 ...

  2. 51nod 1681

    题目 神犇题解 这题挺神的..思路很巧妙 首先想到DFS序(毕竟是子树问题),这道题可以转化成:我们对于每一个节点的子树区间去看,两棵树同一节点的这个子树区间有多少个相同元素,设个数为x,那么这个点的 ...

  3. EntityFramework 学习 一 Add New Entity using DBContext in Disconnected Scenario

    using System; using System.Collections.Generic; public partial class Student { public Student() { th ...

  4. Android_微信_设置

    减少 内存的使用 (http://news.ifeng.com/a/20170716/51440541_0.shtml) 1.关闭“附近的人” 打开微信,依次点击[我]—[设置]—[通用]—[功能], ...

  5. Javascript- Javascript学习

    Javasrcipt的引入方式 内部引入方式 直接将javascript代码写入到<script type="text/javascript"></script& ...

  6. linux 设备文件

    一.设备文件 在dev目录下 外部设备通过创建好的设备文件连接到服务器上,例如可以通过设备号给连接上去的硬件发消息. 二.设备文件分类 块设备 按块为单位,随机访问的设备 常见的有 硬盘 字符设备 按 ...

  7. 普林斯顿算法(1.3)并查集(union-find算法)——本质就是一个数 下面的子树代表了连在一起的点

    转自:https://libhappy.com/2016/03/algs-1.3/ 假设在互联网中有两台计算机需要互相通信,那么该怎么确定它们之间是否已经连接起来还是需要架设新的线路连接这两台计算机. ...

  8. codeforces 29D Ant on the Tree (dfs,tree,最近公共祖先)

    D. Ant on the Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. gcc 4.8.5安装

    在利用张乐博士的最大熵模型工具包(Maximum Entropy Modeling Toolkit for Python and C++)和条件随机场的经典工具包CRF++(CRF++: Yet An ...

  10. stl_deque.h

    stl_deque.h // Filename: stl_deque.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http:/ ...