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= ...
随机推荐
- 搭建Squid反向代理服务器
好吧,更新个文章,有段时间没写技术博文了.今天就说说squid反向代理这个服务,当然,这是在Linux下配置完成的.说自己没偏见似乎不可能 了.大概是相对喜欢Linux而已.但我从不否认Windows ...
- ApplicationContextRunner如何简化自动配置测试
1. 概览 众所周知,自动配置是Spring Boot的关键功能之一, 但测试自动配置可能会很棘手. 在以下部分中,我们将展示ApplicationContextRunner如何简化自动配置测试. 2 ...
- html及css
html设置网页的结构内容,css设置样式,要记的标签很多,要学好无非是多练,然后看别人怎样写的代码,对比自己的,这样能更好地理解. 关于浮动,既然所有浮动必须要清除,那在设置浮动的同时,就先把清除浮 ...
- Google Code Jam 2014 资格赛:Problem C. Minesweeper Master
Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...
- MySQL慢查询(二) - pt-query-digest详解慢查询日志 pt-query-digest 慢日志分析
随笔 - 66 文章 - 0 评论 - 19 MySQL慢查询(二) - pt-query-digest详解慢查询日志 一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它 ...
- ansible的异步执行
ansible任务的异步执行 96 茶客furu声 关注 2016.07.12 01:40* 字数 458 阅读 1777评论 0喜欢 4 ansible方便在于能批量下发,并返回结果和呈现.简单.高 ...
- struts2中在Action中如何获取servlet的api?
1.通过ActionContext类(拿到的不是真正的servlet api,而是一个map) ActionContext context = ActionContext.getContext(); ...
- R中导入excel乱码的解决办法
本文操作系统环境为win10,使用Rstdio. 要说明windows下在使用Rstdio的时候,在使用xlsx包,导入excel表乱码的解决办法. 1.我们先安装xlsx包 install.pack ...
- IOS启动页动画(uiview 淡入淡出效果 )2
Appdelegate里面右个这个函数,只要它没结束,你的等待界面就不会消失.以在启动的时候做些动画 - (BOOL)application:(UIApplication *)application ...
- ios输出想保留的整数位(占位符)
int startHour=5; int startMinute=4; //输出前面补0,不管你输入的数据前面有没有0 sp;NSLog(@"====>%@",[NSStri ...