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= ...
随机推荐
- Android---06---2中动画效果
1,先看FrameAnimation,此动画是用来实现动态动画就是把一帧帧图片迭代起来 放在drowable中的xml: <?xml version="1.0" encodi ...
- orcad 里误给元件添加了属性,如何删除
1.先尝试点击delete property 2.第一步不行就右键选择filters----->remove current filter进行删除
- LinkedList add remove get 代码分析
add void linkLast(E e) { //e 要添加的元素 final Node<E> l = last; // 最后一个元素 final Node<E> newN ...
- iOS tableView嵌套部分WebView效果实现
对于一些资讯类的app,比如网易新闻,今日头条这样的,他们的文章详情页大部分基本都是tableView中嵌套webView来实现的效果,其中顶部标题,关注按钮等这些可能是原生的,内容部分是webVie ...
- bzoj4069【APIO2015】巴厘岛的雕塑
4069: [Apio2015]巴厘岛的雕塑 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 192 Solved: 89 [Submit][Stat ...
- HTTP Status Codes 状态码
Network Connect Timeout Error
- python第三方库地址
python第三方库的地址: requests: http://docs.python-requests.org/zh_CN/latest/user/quickstart.html beautifus ...
- 解决ListView滑动上下出现阴影
网上大部分说在listview的属性中通过设置android:fadingEdge="none"来解决问题,需要说明的是是在2.3版本之前有效! 方法一. public class ...
- POJ 3253 Fence Repair(哈夫曼树)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26167 Accepted: 8459 Des ...
- 爬虫入门【2】Requests库简介
发送请求 使用Requests发送网络请求很简单 #首先要导入requests库 import requests #返回一个Response对象 r=requests.get('https://git ...