poj 1065 Wooden Sticks 【贪心 新思维】
题目地址:http://poj.org/problem?id=1065
Sample Input
- 3
- 5
- 4 9 5 2 2 1 3 5 1 4
- 3
- 2 2 1 1 2 2
- 3
- 1 3 2 2 3 1
Sample Output
- 2
- 1
- 3
- 题目抽象:给你一个序列,序列的每个元素包含两个值(x,y).现在希望找到最少数目的条件序列。
条件序列是这样的:cur.x<=(cur+1).x && cur.y<=(cur+1).y
满足条件的序列的最少的数目是多少?
代码:
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <math.h>
- #include <cmath>
- #include <iostream>
- #include <string>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <map>
- #include <algorithm>
- #define N 100000+100
- using namespace std;
- struct node
- {
- int len, weight;
- bool operator<(const node &dd)const{
- if(len==dd.len)
- return weight<dd.weight;
- else
- return len<dd.len;
- }
- }q[];
- int main()
- {
- int tg; scanf("%d", &tg);
- int i, j, k;
- int n;
- while(tg--){
- scanf("%d", &n);
- for(i=; i<n; i++){
- scanf("%d %d", &q[i].len, &q[i].weight );
- }
- sort(q, q+n);
- int ans=;
- node cur=q[];
- bool vis[];
- memset(vis, false, sizeof(vis));
- vis[]=true;
- //从当前出发 遍历整个数组只要有结构体满足条件就贪心吃掉
- //不断的进行这样的贪心,直到整个结构体数组集合元素全被吃掉为止
- //不同于以往的贪心的是:当前的不可用,不代表以后的不可用 并非遇到遇到一个不可用的
- //情况就停止了本组的计算!
- while(true){
- for(j=; j<n; j++){
- if( vis[j]==false && q[j].len>=cur.len && q[j].weight>=cur.weight ){
- cur=q[j]; vis[j]=true;
- }
- }//
- ans++; //完成了一次
- for(j=; j<n; j++){
- if(vis[j]==false){
- cur=q[j]; vis[j]=true; break;
- }
- }
- if(j==n) break;
- }
- printf("%d\n",ans);
- }
- return ;
- }
poj 1065 Wooden Sticks 【贪心 新思维】的更多相关文章
- POJ 1065 Wooden Sticks#贪心+qsort用法
(- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.h ...
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- 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 ...
- HDU ACM 1051/ POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- poj -1065 Wooden Sticks (贪心or dp)
http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...
- POJ 1065 Wooden Sticks【贪心】
题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...
- POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)
题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
随机推荐
- IOS 10 微信 ajax readystate=0 status=0 解决方法
最近做了一个 基于微信访问的网页系统 发现IOS10.2.1 版本 访问的时候 AJAX报错,安卓和IOS11.4.1 没有这样的问题. 通过Fiddler抓包发现,AJAX请求时 报错信息为 {& ...
- asp.net repeater Container.ItemIndex
<asp:Repeater ID="myRepeater" runat="server"> <HeaderTemplate> <t ...
- 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.定位到 ...
- linux 参数内核
优化Linux内核参数 转自:http://www.centoscn.com/CentOS/config/2013/0804/992.html vim /etc/sysctl.conf 1.net ...
- 最小生成树——Kruskal(克鲁斯卡尔)算法
[0]README 0.1) 本文总结于 数据结构与算法分析, 源代码均为原创, 旨在 理解 Kruskal(克鲁斯卡尔)算法 的idea 并用 源代码加以实现: 0.2)最小生成树的基础知识,参见 ...
- 【Atheros】内核调试及网卡加载等问题小结
我做的其他很多工作就比较有针对性了,不是什么大众性的问题,比如加统计代码.实现自己的速率调整算法或者加一些自己的控制什么的,就不再单独介绍了,最后呢再罗列一些小问题,供参考. 1. 加载模块(执行wi ...
- 查看文档的后几行命令:tail
假如有一个文件test.txt,内容如下: [root@lee ~]# cat test.txt 这是第1行 这是第2行 这是第3行 这是第4行 这是第5行 这是第6行 这是第7行 这是第8行 这是第 ...
- Laravel手记:执行route:cache时报LogicException
laravel5的路由支持缓存.需要执行以下命令: php artisan route:cache 执行完毕后,报出以下错误: Route cache cleared! [LogicException ...
- springMVC的注释集合
SpringMVC的工作原理 主要核心实现是DispatcherServlet. 一般来讲客户端对服务器发送请求,是由DispatcherServlet控制的,DispatcherServlet接受到 ...
- wcf读取message内容
private string MessageToString(ref Message message) { WebContentFormat messageFormat = this.GetMessa ...