POJ | 1065 Wooden Sticks | 贪心
来源:互联网 发布:重庆生活频道 网络直播 编辑:程序博客网 时间:2024/05/01 06:39
思路:先排序l,对于相等的情况排序w,然后求最大上升子序列。
#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct _node { int l; int w; bool visit;}Node;Node a[5010];int n, m;int cmp(const void *b, const void *c){ if ((*(Node *)b).l == (*(Node *)c).l) return (*(Node *)b).w - (*(Node *)c).w; else return (*(Node *)b).l - (*(Node *)c).l;}int greedy(){ int result = 0, max = 0; for (int i = 0; i < m; ++i) { if (!a[i].visit) { result++; int weight = a[i].w; a[i].visit = true; for (int j = i + 1; j < m; ++j) { if (!a[j].visit && weight <= a[j].w) { a[j].visit = true; weight = a[j].w; } } } } return result;}int main(){ while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; ++i) { scanf("%d", &m); for (int j = 0; j < m; ++j) { scanf("%d%d", &a[j].l, &a[j].w); a[j].visit = false; } qsort(a, m, sizeof(Node), cmp); printf("%d\n", greedy()); } }}
- POJ 1065 Wooden Sticks 贪心
- POJ | 1065 Wooden Sticks | 贪心
- POJ 1065 Wooden Sticks (贪心)
- POJ 1065 Wooden Sticks 贪心
- poj 1065 Wooden Sticks【贪心】
- POJ 1065 Wooden Sticks 【贪心】
- POJ 1065-Wooden Sticks 贪心问题
- poj 1065Wooden Sticks (简单的贪心)
- poj 1065 Wooden Sticks(贪心算法)
- poj 1065 Wooden Sticks (贪心)
- POJ 1065-Wooden Sticks(贪心+暴力)
- Poj 1065 Wooden Sticks【贪心+LIS?】
- poj 1065 Wooden Sticks贪心水过
- Poj 1065 Wooden Sticks【贪心+LIS?】
- POJ 1065 && HDU 1051 Wooden Sticks 贪心
- POJ 1065 Wooden Sticks
- poj 1065 Wooden Sticks
- poj 1065 Wooden Sticks
- arcgis api for flex 开发入门(二)map 的创建
- getch
- uva 10905-Children’s Game
- WSAEventSelect模型中FD_READ 网络事件的处理
- 数据库分库分表(sharding)系列
- POJ | 1065 Wooden Sticks | 贪心
- RIA Service部署IIS6 - WIN2003
- arcgis api for flex 开发入门(三)地图浏览控件的使用
- qt编译不识别tslib报找不到问题的解决
- hdu4180-RealPhobia
- arcgis api for flex 开发入门(四)Darw控件的使用
- 用Visual C++.NET进行GDI+编程
- arcgis api for flex 开发入门(五)查询
- HDU-3786找出直系亲属