#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. POJ 之2386 Lake Counting

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20003   Accepted: 10063 D ...

  2. ConcurrentHashMap以及HashMap,HashTable的区别

    ConcurrentHashMap与HashMap,和HashTable 的区别? ConcurrentHashMap是一个线程安全的key-value数据结构,而HashMap不是.Concurre ...

  3. hdu 5475 线段树

    An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. POJ 2728 Desert King:最优比率生成树

    题目链接:http://poj.org/problem?id=2728 题意: 给你n个点(x,y,z),让你求一棵生成树,使得 k = ∑ |z[i]-z[j]| / ∑ dis(i,j)最小. | ...

  5. Sed 命令详解 正则表达式元字符

    1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕.具体过程如下 ...

  6. Windows Server 2008 R2 备份与恢复详细实例

    Windows Server 2008 R2中Windows Server Backup备份与恢复 本实验是在虚拟机操作,因公司的需求,将备份存储到另一台服务器,于是我在现有linux备份服务器搭建了 ...

  7. 动态规划 两个字符串之间的编辑距离 leetcode72

    public static int minDistance(String word1, String word2) { char[] s1 = word1.toCharArray(); char[] ...

  8. docker 安装与常用命令与常用容器(containers)环境

    注意区别 container 与 image 的关系,container 的建立需要 image 的承载,也即 container 依赖 image,停止并删除了 container 并不会删除 im ...

  9. 【二叉查找树】01不同的二叉查找树的个数【Unique Binary Search Trees】

    当数组为1,2,3,4,...,n时,基于以下原则构建的BST树具有唯一性: 以i为根节点的树,其左子树由[1,i-1]构成,其右子树由[i+1, n]构成. 我们假定f(i)为以[1,i]能产生的U ...

  10. C语言访问MCU寄存器的两种方式

    转自http://blog.csdn.net/liming0931/article/details/7752248 单片机的特殊功能寄存器SFR,是SRAM地址已经确定的SRAM单元,在C语言环境下对 ...