Codeforces Round #331 (Div. 2) C. Wilbur and Points 贪心+排序
来源:互联网 发布:java wmf转jpg 编辑:程序博客网 时间:2024/06/06 03:23
题目~~
题意: 有n个坐标,wi为(yi-xi),再给出n个wj(j=0~n), wi==wj 则第i个坐标标号为j,而满足xi<=xj && yi<=yj (i < j) 的j标号必须大于i的标号,存在则输出YES,并且按标号输出坐标,否则输出NO,保证只有一种可能。
具体看代码
Sample test(s)
input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
output
YES
0 0
1 0
2 0
0 1
1 1
input
3
1 0
0 0
2 0
0 1 2
output
NO
#include <cstdio>#include <cstring>#include <iostream>#include <cmath>#include <map>#include <vector>#include <algorithm>using namespace std;typedef long long ll;struct node{ int x,y,id; int val; bool operator <(const node&p) const{ if(val!=p.val) return val<p.val; else if(p.x!=x) return x<p.x; return y<p.y; }}no[100005];//保存坐标,及对应的差值及标号int idd[100005];//保存差值int ans[100005];//结果,标号对应坐标的下标map<int,vector<int> >mp;//保存差值对应的所有坐标下标int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d",&no[i].x,&no[i].y); no[i].val=no[i].y-no[i].x; } sort(no,no+n);//排序 int c=0; for(int i=0;i<n;i++) { mp[no[i].val].push_back(i); } bool f=0;for(int i=0;i<n;i++){ scanf("%d",&idd[i]);}for(int i=0;i<n;i++){//放入的坐标下标已排好序,如果无法对应则是错的 if(mp[idd[i]].size()){ int x=mp[idd[i]][0]; no[x].id=i; mp[idd[i]].erase(mp[idd[i]].begin()); } else{ f=1; break; }} if(f) puts("NO"); else{ f=false; for(int i=0;i<n;i++)//给坐标编号 ans[no[i].id]=i; //再比较不同的差值的坐标是否符合要求 int xz,pr; xz=ans[0]; for(int i=1;i<n;i++) { pr=ans[i]; if(no[pr].x>=no[xz].x && no[pr].y>=no[xz].y){ xz=pr; continue; } if(no[pr].x<=no[xz].x && no[pr].y<=no[xz].y){ f=true; break; } } if(f) puts("NO"); else{ puts("YES"); for(int i=0;i<n;i++){ xz=ans[i]; printf("%d %d\n",no[xz].x,no[xz].y); } } }}
0 0
- Codeforces Round #331 (Div. 2) C. Wilbur and Points 贪心+排序
- 巧妙地利用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. 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】【脑洞 SET贪心写法】Wilbur and Points 锯齿图形差值编号,右上角的最大
- Codeforces Round #331 (Div. 2)C. Wilbur and Points(模拟+STL)
- Codeforces Round #331 (Div. 2)——C. Wilbur and Points
- Codeforces Round #331 (Div. 2)-C-Wilbur and Points(STL容器)
- Codeforces Round #331 (Div. 2) B. Wilbur and Array (贪心)
- Codeforces 596 C Wilbur and Points【贪心】
- codeforces#331-C - Wilbur and Points-set/贪心乱搞
- Codeforces Round #331 (Div. 2)-Wilbur and Array(贪心模拟)
- Codeforces 596C Wilbur and Points 【贪心 + sort】
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
- Codeforces Round #331 (Div. 2) B. Wilbur and Array
- Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
- java向mysql插入时间
- 用Leangoo做敏捷需求管理
- python——Tkinter的简单学习
- Memory Management Policy(内存管理政策)
- List排序
- Codeforces Round #331 (Div. 2) C. Wilbur and Points 贪心+排序
- 二维数组中查找是否存在某个值
- android关于base64转化二进制字符图片的问题,提交的数据报非法字符的问题的解决
- ios开发--判断是否为空
- MVC学习整理
- Tomcat6.0 版本下载安装部署
- Ubuntu 15.04 安装配置 Qt + SQLite3
- 逻辑电路 - 振荡器Clock
- 阿米巴原虫式的产品研發 V.S. 敏捷价值流开发 (产品级敏捷)