Blobs' Exhibition opentrains
来源:互联网 发布:淘宝客服该怎么做 编辑:程序博客网 时间:2024/06/03 21:10
这题就是个贪心题
通过对价值排序,然后从高到低,每次找一个尽量小的能放得下的位置放置就好了
我是用了multiset和lowerbound来查找
时间是nlogn的
#include <bits/stdc++.h>#include <set>#include <algorithm>using namespace std;struct Node { int v, w, index; Node() {} Node(int vv, int ww, int ii): v(vv), w(ww), index(ii) {} bool operator<(const Node &other) const { if (v > other.v) return true; if (v < other.v) return false; return w < other.w; }};struct NNode { int w, index; NNode() {} NNode(int ww, int ii): w(ww), index(ii) {} bool operator<(const NNode &other) const { return w < other.w; }};const int maxn = 10010;multiset<NNode> s;int f[maxn];Node a[maxn];int n, m, x;int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &x); s.insert(NNode(x, i)); } for (int i = 1; i <= m; i++) { scanf("%d %d", &a[i].v, &a[i].w); a[i].index = i; } sort(a+1, a+1+m); for (int i = 1; i <= m; i++) { multiset<NNode>::iterator k = s.lower_bound(NNode(a[i].w, 1)); if (k != s.end()) { f[(*k).index] = a[i].index; s.erase(k); } } for (int i = 1; i < n; i++) printf("%d ", f[i]); printf("%d\n", f[n]);}
阅读全文
0 0
- Blobs' Exhibition opentrains
- Sequence (opentrains)
- Selection (opentrains)
- Bubble (opentrains)
- Maze (opentrains)
- Tree packing opentrains
- Caffe Blobs
- Oracle BLOBs, CLOBs tips
- Base Provider Key BLOBs
- caffe源码学习:Blobs
- POJ2184Cow Exhibition
- Cow Exhibition
- Cow Exhibition
- Cow Exhibition
- Cow Exhibition
- Designing Data Storage Architecture - Understanding Block Blobs and Page Blobs
- DirectX Sample-Blobs实现原理
- caffe blobs 共享内存分析
- 2.2[Lib]ardupilot设备驱动实现方式
- centos 关闭防火墙以及关闭selinux方法
- strrchr
- HTML5 -- canvas实现简易画板
- 从0开始搭建阿里云(腾讯云)ubuntu16.04 nodejs + nginx + mysql + pm2 服务(二、搭建nginx环境)
- Blobs' Exhibition opentrains
- 找出两个不相交连续子数组的最大和
- 《Python全栈开发》学习过程笔记【3】
- input requried 提示文字修改
- js模拟QQ好友列表的实现
- 第十一届湖南大学生程序设计竞赛 阶乘除法(思维)
- Android 内存泄露分析
- Quick Sorting/Extract
- Extjs6.2 Form中组件的使用及正则验证