ZOJ 2283 Challenge of Wisdom
来源:互联网 发布:abp框架源码 编辑:程序博客网 时间:2024/05/18 19:47
题意:在一个n * m的地图里,有p个宝藏,每次只能向横纵坐标增加的方向走,问最少走几次能把宝藏都拿走。
解法:按横坐标排序,纵坐标的一个不下降子序列就是一条合法路径,要求多少条不下降子序列可以覆盖所有点,这个问题可以转化为最长下降子序列的长度。
代码:
#include<stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<math.h>#include<limits.h>#include<time.h>#include<stdlib.h>#include<map>#include<queue>#include<set>#include<stack>#include<vector>#define LL long longusing namespace std;struct node{ int x, y;}tre[100005];int cmp(node a, node b){ if(a.x == b.x) return a.y < b.y; else return a.x < b.x;}vector <int> v;int main(){ int p, n, m; while(~scanf("%d%d%d", &n, &m, &p)) { v.clear(); for(int i = 0; i < p; i++) scanf("%d%d", &tre[i].x, &tre[i].y); sort(tre, tre + p, cmp); for(int i = 0; i < p; i++) { vector <int> :: iterator it = upper_bound(v.begin(), v.end(), tre[i].y); if(it != v.begin()) { it--; *it = tre[i].y; } else v.insert(v.begin(), tre[i].y); } printf("%d\n", v.size()); } return 0;}思想好神···知道真相的我眼泪掉下来QAQ
0 0
- zoj 2283 Challenge of Wisdom
- ZOJ 2283 Challenge of Wisdom
- ZOJ 2283 Challenge of Wisdom
- ZOJ2283 Challenge of Wisdom(DP+二分求最长非上升子序列)
- Words Of Wisdom
- Wisdom of Kong Fu Panda
- Wisdom
- Nuggets of Wisdom from eBay's Architecture
- 《The wisdom of the few》读书笔记
- Today I will pluck grapes of wisdom from ..........
- 少数人的智慧(The Wisdom of the Few)
- 65. An ounce of luck is better than a pound of wisdom. 聪明才智,不如运气
- Instant wisdom
- Instant wisdom
- Nuggets of Wisdom from eBay's Architecture(eBay架构的思想金矿)
- 2014年 Thinking of Technical Challenge of Hardware Design
- Sum of Factorials zoj
- Ace of Aces ZOJ
- UVa #11400 Lighting System Design (例题9-6)
- 背包九讲
- delphi 中的一个线程池单元的归纳说明
- codeforces 509C Sums of Digits (贪心对位操作)
- Zend Studio12.0破解方法(附网盘下载)
- ZOJ 2283 Challenge of Wisdom
- Vmware vSphere常见问题及解决办法
- C++ STL 算法:对所有元素排序
- 国内各大城市的IT行业特色
- Java—读写锁的简单使用
- IsDebuggerPresent官方出处
- hadoop/spark调优以及遇到的问题
- 选择排序
- 如何获得设备环境句柄(HDC)--Win32 SDK