题目地址:http://poj.org/problem?id=1065

Sample Input

  1. 3
  2. 5
  3. 4 9 5 2 2 1 3 5 1 4
  4. 3
  5. 2 2 1 1 2 2
  6. 3
  7. 1 3 2 2 3 1

Sample Output

  1. 2
  2. 1
  3. 3
  4.  
  5. 题目抽象:给你一个序列,序列的每个元素包含两个值(x,y).现在希望找到最少数目的条件序列。
    条件序列是这样的:cur.x<=(cur+1).x && cur.y<=(cur+1).y
    满足条件的序列的最少的数目是多少?
    代码:
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6. #include <cmath>
  7. #include <iostream>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <vector>
  12. #include <map>
  13. #include <algorithm>
  14. #define N 100000+100
  15.  
  16. using namespace std;
  17.  
  18. struct node
  19. {
  20. int len, weight;
  21. bool operator<(const node &dd)const{
  22. if(len==dd.len)
  23. return weight<dd.weight;
  24. else
  25. return len<dd.len;
  26. }
  27. }q[];
  28.  
  29. int main()
  30. {
  31. int tg; scanf("%d", &tg);
  32. int i, j, k;
  33. int n;
  34.  
  35. while(tg--){
  36. scanf("%d", &n);
  37. for(i=; i<n; i++){
  38. scanf("%d %d", &q[i].len, &q[i].weight );
  39. }
  40.  
  41. sort(q, q+n);
  42. int ans=;
  43. node cur=q[];
  44.  
  45. bool vis[];
  46. memset(vis, false, sizeof(vis));
  47. vis[]=true;
  48. //从当前出发 遍历整个数组只要有结构体满足条件就贪心吃掉
  49. //不断的进行这样的贪心,直到整个结构体数组集合元素全被吃掉为止
  50. //不同于以往的贪心的是:当前的不可用,不代表以后的不可用 并非遇到遇到一个不可用的
  51. //情况就停止了本组的计算!
  52. while(true){
  53. for(j=; j<n; j++){
  54. if( vis[j]==false && q[j].len>=cur.len && q[j].weight>=cur.weight ){
  55. cur=q[j]; vis[j]=true;
  56. }
  57. }//
  58. ans++; //完成了一次
  59. for(j=; j<n; j++){
  60. if(vis[j]==false){
  61. cur=q[j]; vis[j]=true; break;
  62. }
  63. }
  64. if(j==n) break;
  65. }
  66. printf("%d\n",ans);
  67. }
  68. return ;
  69. }

poj 1065 Wooden Sticks 【贪心 新思维】的更多相关文章

  1. POJ 1065 Wooden Sticks#贪心+qsort用法

    (- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.h ...

  2. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

  3. POJ 1065 Wooden Sticks (贪心)

    There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...

  4. HDU ACM 1051/ POJ 1065 Wooden Sticks

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

  5. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  6. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  7. POJ 1065 Wooden Sticks【贪心】

    题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...

  8. POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)

    题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...

  9. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

随机推荐

  1. IOS 10 微信 ajax readystate=0 status=0 解决方法

    最近做了一个 基于微信访问的网页系统 发现IOS10.2.1 版本 访问的时候 AJAX报错,安卓和IOS11.4.1 没有这样的问题. 通过Fiddler抓包发现,AJAX请求时 报错信息为  {& ...

  2. asp.net repeater Container.ItemIndex

    <asp:Repeater ID="myRepeater" runat="server"> <HeaderTemplate> <t ...

  3. php7.0 出现 curl_setopt(): Disabling safe uploads is no longer supported in 报错!

    项目换成php7.0,进行了测试,使用curl时,出现: curl_setopt(): Disabling safe uploads is no longer supported in xxx.定位到 ...

  4. linux 参数内核

    优化Linux内核参数   转自:http://www.centoscn.com/CentOS/config/2013/0804/992.html vim /etc/sysctl.conf 1.net ...

  5. 最小生成树——Kruskal(克鲁斯卡尔)算法

    [0]README 0.1) 本文总结于 数据结构与算法分析, 源代码均为原创, 旨在 理解 Kruskal(克鲁斯卡尔)算法 的idea 并用 源代码加以实现: 0.2)最小生成树的基础知识,参见 ...

  6. 【Atheros】内核调试及网卡加载等问题小结

    我做的其他很多工作就比较有针对性了,不是什么大众性的问题,比如加统计代码.实现自己的速率调整算法或者加一些自己的控制什么的,就不再单独介绍了,最后呢再罗列一些小问题,供参考. 1. 加载模块(执行wi ...

  7. 查看文档的后几行命令:tail

    假如有一个文件test.txt,内容如下: [root@lee ~]# cat test.txt 这是第1行 这是第2行 这是第3行 这是第4行 这是第5行 这是第6行 这是第7行 这是第8行 这是第 ...

  8. Laravel手记:执行route:cache时报LogicException

    laravel5的路由支持缓存.需要执行以下命令: php artisan route:cache 执行完毕后,报出以下错误: Route cache cleared! [LogicException ...

  9. springMVC的注释集合

    SpringMVC的工作原理 主要核心实现是DispatcherServlet. 一般来讲客户端对服务器发送请求,是由DispatcherServlet控制的,DispatcherServlet接受到 ...

  10. wcf读取message内容

    private string MessageToString(ref Message message) { WebContentFormat messageFormat = this.GetMessa ...