问题 C: Criss-Cross Cables

时间限制: 2 Sec  内存限制: 128 MB
提交: 72  解决: 18
[提交] [状态] [命题人:admin]

题目描述

As a participant in the BAPC (Bizarrely Awful Parties Competition) you are preparing for your next show. Now,you do not know anything about music, so you rip off someone else’s playlist and decide not to worry about that any more. What you do worry about, though, is the aesthetics of your set-up: if it looks too simple, people will be unimpressed and they might figure out that you are actually a worthless DJ.
It doesn’t take you long to come up with a correct and fast solution to this problem. You add a long strip with a couple of useless ports, and add some useless cables between these ports. Each of these cables connects two ports, and these special ports can be used more than once. Everyone looking at the massive tangle of wires will surely be in awe of your awesome DJ skills.
However, you do not want to connect the same two ports twice directly. If someone notices this, then they will immediately see that you are a fraud!
You’ve made a large strip, with the ports in certain fixed places, and you’ve found a set of cables with certain lengths that you find aesthetically pleasing. When you start trying to connect the cables, you run into another problem. If the cables are too short, you cannot use them to connect the ports! So you ask yourself the question whether you’re able to fit all of the cords onto the strip or not. If not, the aesthetics are ruined, and you’ll have to start all over again.

输入

The first line has 2 ≤ n ≤ 5 · 105 and 1 ≤ m ≤ 5 · 105, the number of ports on the strip and the number of wires.
• The second line has integers 0 ≤ x1 < · · · < xn ≤ 109, the positions of the n sockets.
• The third line has m integers l1, . . . , lm, the lengths of the wires, with 1 ≤ li ≤ 109.

输出

Print yes if it is possible to plug in all the wires, or no if this is not possible.

样例输入

复制样例数据

4 4
0 2 3 7
1 3 3 7

样例输出

yes

题意:给出n个接线柱的坐标,m个线的长度,问是否能把所有的线都接上,条件是:不能有多根线接在相同的两根上,比如说:1号线接1 2柱,其他的线就不能接1 2柱了,当然一条线只能接2个接线柱。

题解:如果把所有的距离都放进优先队列里面,肯定会T,因为找距离就是O(n^2),所以我们考虑先把 放到队列里面,把线的长度排序,看看最小的,与优先队列里面最小的是否匹配,如果匹配,pop掉,假设pop的两个的位置是i,j那么再往队列里面加,如果不匹配直接输出“no”,因为不会有更小的距离了。注意标记两个接线柱之间只能用一次。

注意:可能是我的写法问题,用long long会超内存,改成int,用map标记会T,改成unordered_map标记

上代码:

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <tr1/unordered_map>
using namespace std;
using namespace tr1;
const int MAX = 5e5+100;
struct hh{int l,r,w;bool operator < (const hh& b) const{return w>b.w;}
}tmp;
priority_queue<hh> q;
int b[MAX];
int c[MAX];
unordered_map<int,unordered_map<int,int> > mp;
int main(){int n,m;scanf("%d%d",&n,&m);for (int i = 0; i < n;i++){scanf("%d",&c[i]);}for (int i = 0; i < m;i++){scanf("%d",&b[i]);}for (int i = 0; i < n-1;i++){tmp.l=i;tmp.r=i+1;tmp.w=c[i+1]-c[i];q.push(tmp);}sort(b,b+m);int cnt=0;while(!q.empty()){hh fuck=q.top();q.pop();//cout << fuck.w << " " << fuck.l << " " << fuck.r  << endl;if(b[cnt]>=fuck.w){cnt++;int l=fuck.l;int r=fuck.r;tmp.l=l-1;tmp.r=r;if(tmp.l>=0&&mp[tmp.l][tmp.r]==0){mp[tmp.l][tmp.r]=1;tmp.w=c[tmp.r]-c[tmp.l];q.push(tmp);// cout << tmp.w << " " << tmp.l << " " << tmp.r << "*" << endl;}tmp.l=l;tmp.r=r+1;if(tmp.r<n&&mp[tmp.l][tmp.r]==0){mp[tmp.l][tmp.r]=1;tmp.w=c[tmp.r]-c[tmp.l];q.push(tmp);//cout << tmp.w << " " << tmp.l << " " << tmp.r << "&" << endl;}}else{if(cnt<m){puts("no");return 0;}}if(cnt==m) break;}if(cnt==m) puts("yes");else puts("no");return 0;
} 

2019年我能变强组队训练赛第十场 C Criss-Cross Cables(优先队列模拟)相关推荐

  1. Contest1819 - 2019年我能变强组队训练赛第十一场(补题场)

    赛后总结 菜 问题 E: Faulhaber's Triangle 问题 E: Faulhaber's Triangle 单纯模拟题,模拟分数加法 代码 #include <bits/stdc+ ...

  2. Contest1819 - 2019年我能变强组队训练赛第十一场

    题目: The King's Ups and Downs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  3. 2019年第二阶段我要变强个人训练赛第十八场 扶桑号战列舰(线段树+递归)

    问题 N: 扶桑号战列舰 时间限制: 1 Sec  内存限制: 128 MB  Special Judge 题目描述 众所周知,一战过后,在世界列强建造超无畏级战列舰的竞争之中,旧日本海军根据&quo ...

  4. Contest1802 - 2019年第二阶段我要变强个人训练赛第十八场 问题 N: 扶桑号战列舰 线段树+贪心

    题目链接:http://icpc.upc.edu.cn/problem.php?cid=1802&pid=13 问题 N: 扶桑号战列舰 时间限制: 1 Sec  内存限制: 128 MB   ...

  5. 石油大 2019年第二阶段我要变强个人训练赛第十八场 Problem N 扶桑号战列舰(线段树+区间更新+区间查询)

    链接:http://icpc.upc.edu.cn/problem.php?cid=1803&pid=13 题意:给出一个n,接下来一行给出n个数.才开始所有数为0,每次操作可以选一个区间[l ...

  6. 石油大 Contest1777 - 2019年第二阶段我要变强个人训练赛第九场 I 热狗树(树形dp)

    题目描述 "我是番茄酱!" "我是黄芥末酱!" "合在一起就是--美式热狗上加的,那个!" 热狗树上的每个节点都涂有番茄酱或者黄芥末酱中的一 ...

  7. UPC 2020年秋季组队训练赛第十四场

    问题 A: Too Expensive to Buy a House 时间限制: 1 Sec 内存限制: 128 MB 题目描述 WNJXYK and DIDIDI are good friends ...

  8. UPC2018组队训练赛第六场

    题目来自UKIEPC2017 A题:Alien Sunset 有n个星球,输入每个星球一天的时间,日出和日落的时间.从日落到日出(包括日出.日落)是黑夜.其他的为白天.问在前1825天里能不能有一个时 ...

  9. 石油大--2020年秋季组队训练赛第十二场----J、Greedy Termite(线段树)

    题面: 题意: 给定正整数 nnn 和起始位置 sss. nnn 表示有 nnn 个杆子,每个杆子由属性 (xi,hi)(x_i,h_i)(xi​,hi​) 构成,表示在 xix_ixi​ 处有一根高 ...

  10. 【upc】2020年秋季组队训练赛第十二场J Greedy Termite | 删点线段树

    状态 题目描述 There are n wooden rods vertically placed over a horizontal line. The rods are numbered 1 th ...

最新文章

  1. 基于自然的灵感算法--元启发式
  2. 真香!3个月0基础转型大厂数据分析师,他做对了什么?
  3. 足够应付面试的Spring事务源码阅读梳理
  4. linux 用户态 spinlock,spinlock作用
  5. 安卓TTS语音合成经验分享(科大讯飞语音+)集成
  6. Linux下如何安装软件
  7. 放弃月薪过万的城市工作,返乡创业做农业,面对未知风险,你敢尝试吗?
  8. android 日历_适用于Android的十大最佳日历应用
  9. 三阶段提交协议(有限状态自动机)
  10. 《JavaScript权威指南第7版》第4章 表达式和运算符
  11. 毕业论文排版(六)-三线表
  12. linux多个网卡丢包,linux系统双网卡绑定及丢包问题
  13. 可在linux运行的酷q,Linux通过docker安装运行酷Q--用QQ骰子君进行跑团
  14. 怎么 如何劫持DNS 加速 转发 教程
  15. Edge浏览器中不输oneTab的标签整理插件
  16. 苹果Airplay协议以及AirTunes流程总结
  17. AI帮我画出了小说里的人物,我这么多年的小说好像白看了。。。
  18. 微信小程序回车键传值
  19. 浏览器禁止访问某个网站
  20. python在线diff工具在哪_Python - deepdiff

热门文章

  1. mysql replace into 异常1365 - Division by 0
  2. 苹果电脑修改MAC地址方法
  3. c语言封皮,C语言程序设计封皮.doc
  4. Android实现身份证号码验证
  5. 微生物生态数据分析——冗余分析
  6. 14.linux中的无人职守安装脚本kickstart
  7. 下载youtube 在线工具_5款不用下载的免费在线做图工具,满足你日常图片处理需求...
  8. [精简]托福核心词汇60
  9. LAB、HSB、RGB和CMYK色彩模式简介
  10. 【算法】两矩形相交的判定