巧妙地利用STL map set pair 贪心+排序 Codeforces Round #331 (Div. 2)C. Wilbur and Points
来源:互联网 发布:变革管理 知乎 编辑:程序博客网 时间:2024/06/06 00:07
http://codeforces.com/contest/596/problem/C
题意
给你一堆点,要求你找到一个集合,使得他的y[i]-x[i]=w[i]
且如果xj>=xi && yj>=yi,那么id[i]>id[j]
问你能否找到
题解:
巧妙地利用STL
代码
#include <bits/stdc++.h>using namespace std;const int N = 200010;int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif ios_base::sync_with_stdio(0); cin.tie(0); int n; scanf("%d", &n); map < int, set < pair <int, int> > > mp; for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); mp[y - x].insert(make_pair(x, y)); } vector < pair <int, int> > p(n); for (int i = 0; i < n; i++) { int diff; scanf("%d", &diff); if (mp[diff].empty()) { puts("NO"); return 0; } p[i] = *(mp[diff].begin()); mp[diff].erase(mp[diff].begin()); } for (int i = 1; i < n; i++) { int x = p[i].first; int y = p[i].second; int prex = p[i-1].first; int prey = p[i-1].second; if ((x<prex&&y<=prey)||(x<=prex&&y<prey)) { puts("NO"); return 0; } } puts("YES"); for (int i = 0; i < n; i++) { int x = p[i].first; int y = p[i].second; printf("%d %d\n", x, y); } return 0;}
0 0
- 巧妙地利用STL map set pair 贪心+排序 Codeforces Round #331 (Div. 2)C. Wilbur and Points
- Codeforces Round #331 (Div. 2) C. Wilbur and Points 贪心+排序
- 【Codeforces Round 331 (Div 2)C】【脑洞 SET贪心写法】Wilbur and Points 锯齿图形差值编号,右上角的最大
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
- Codeforces Round #331 (Div. 2)-C. Wilbur and Points
- Codeforces Round #331 (Div. 2)C. Wilbur and Points(模拟+STL)
- Codeforces Round #331 (Div. 2)-C-Wilbur and Points(STL容器)
- codeforces#331-C - Wilbur and Points-set/贪心乱搞
- Codeforces Round #331 (Div. 2)——C. Wilbur and Points
- Codeforces Round #331 (Div. 2) B. Wilbur and Array (贪心)
- Codeforces 596 C Wilbur and Points【贪心】
- Codeforces Round #331 (Div. 2)-Wilbur and Array(贪心模拟)
- Codeforces 596C Wilbur and Points 【贪心 + sort】
- Codeforces Round #377 (Div. 2) E. Sockets(map,pair,STL)
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
- Codeforces Round #331 (Div. 2) B. Wilbur and Array
- 应用图的深度优先遍历思路求解问题3
- 项目1--图基本算法库
- c#中异步调用asyn
- Selenium快速入门
- SQL入门语句
- 巧妙地利用STL map set pair 贪心+排序 Codeforces Round #331 (Div. 2)C. Wilbur and Points
- Spring AOP在Bean生命周期中的调用时机
- IO端口与IO内存
- java中的排序方法
- 第12周、项目3 - 图遍历算法实现
- 线性表4 – 数据结构和算法09
- 浅谈基于Selenium的Web自动化测试框架
- HDU 1022 栈
- 第十二周项目1——图基本算法库