5329. 【NOIP2017提高A组模拟8.22】时间机器

(File IO): input:machine.in output:machine.out

Time Limits: 2000 ms Memory Limits: 262144 KB

Description

Input

Output

Sample Input

3

2 2

1 4 2

3 5 1

1 4 2

2 5 1

3 2

1 3 1

2 4 1

3 5 1

1 3 2

2 5 1

2 2

1 2 2

1 2 1

1 2 1

1 2 2

Sample Output

Yes

No

Yes

Data Constraint

Hint

题解

贪心

将电阻和节点按左端点从小到大排序

按顺序考虑每一种节点

每次贪心选左端点在节点左边,右端点尽量靠近节点的电阻

用set或map维护一下左端点符合条件的右端点即可

代码

#include<cstdio>
#include<algorithm>
#include<map>
#define N 100010
using namespace std; struct point{
long x,y,z,type;
}a[N]; map<long,long>b; bool cmp(point a,point b)
{
if(a.x!=b.x)
return a.x<b.x;
else
return a.type>b.type;
} int main()
{ long tot,n,m,i;
bool t;
freopen("machine.in","r",stdin);
freopen("machine.out","w",stdout);
scanf("%ld",&tot);
while(tot--){
scanf("%ld%ld",&n,&m);
for(i=1;i<=n;i++){
scanf("%ld%ld%ld",&a[i].x,&a[i].y,&a[i].z);
a[i].type=0;
}
for(i=1;i<=m;i++){
scanf("%ld%ld%ld",&a[i+n].x,&a[i+n].y,&a[i+n].z);
a[i+n].type=1;
}
sort(a+1,a+n+m+1,cmp);
b.clear();
t=true;
for(i=1;i<=n+m;i++)
if(a[i].type){
if(!b[a[i].y])
b[a[i].y]=a[i].z;
else
b[a[i].y]+=a[i].z;
}else{
while(a[i].z){
map<long,long>::iterator iter=b.lower_bound(a[i].y);
if(iter==b.end()){
t=false;
break;
}
if(a[i].z<iter->second){
iter->second-=a[i].z;
a[i].z=0;
}else{
a[i].z-=iter->second;
b.erase(iter);
}
}
if(!t)break;
}
if(t)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器的更多相关文章

  1. JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠

    JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...

  2. JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线

    5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...

  3. [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)

    题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...

  4. 【NOIP2017提高A组模拟9.7】JZOJ 计数题

    [NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ...

  5. JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团

    100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Got ...

  6. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  7. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  8. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

  9. 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人

    [NOIP2017提高A组模拟9.17]信仰是为了虚无之人 Description Input Output Sample Input 3 3 0 1 1 7 1 1 6 1 3 2 Sample O ...

随机推荐

  1. RubyMain2016.2配置自动同步代码到服务器功能

    可以参考rubymain帮助文档:https://www.jetbrains.com/help/ruby/deployment-in-rubymine.html 在rubymain工具的Tools&g ...

  2. 金山wps的面试经历

    故事从两个月前开始说起吧. 前段时间突然想跳槽,原因也没啥,就是想折腾下,看看外面的世界?有一部分原因是想离家近一些稳定下来,博主上份工作坐标厦门,风景好的简直随便拍照就是大片. 不废话了,机缘巧合, ...

  3. BZOJ3566 [SHOI2014]概率充电器 (树形DP&概率DP)

    3566: [SHOI2014]概率充电器 Description 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品——概率充电器:“采用全新纳米级加工技术,实现元件与导线能否通电 ...

  4. Excel-DNA项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【VB.Net版】

    Excel-DNA项目中的自定义功能区和自定义任务窗格需要用到各种命名空间.添加所需文件,才能实现.后来我发现可以把所有代码都写在Class1.vb这个默认文件中. 大家可以在Visual Studi ...

  5. 关于mysql的符合主键的定义和解释

    DROP TABLE IF EXISTS `v9_vote_data`;CREATE TABLE `v9_vote_data` (  `userid` mediumint(8) unsigned DE ...

  6. js求两个数的百分比

    function toPercent(num, total) { return (Math.round(num / total * 10000) / 100.00 + "%");/ ...

  7. pytho语法基础-预备知识

    ############################################ """ 简述解释型和编译型编程语言? 解释型语言:可以直接运行,逐条翻译逐条运行 ...

  8. ORs-5-OR Subgenomes Variation among Birds, Sea Turtle and Alligator

    OR Subgenomes Variation among Birds, Sea Turtle and Alligator 由 该图数据计算每种鸟的relative percentage,得到下图: ...

  9. html,将元素水平,垂直居中的四种方式

    将元素垂直,水平居中分两种情况:一个是元素尺寸固定,二是元素尺寸不固定 一.尺寸固定 方法1:定位 ,50%,margin负距 .box{ width: 400px; height: 300px; b ...

  10. Weave实现跨主机容器互联

    安装与启动 直接从github下载二进制文件安装. docker_host1(服务器1): 下载weave # sudo wget -O /usr/local/bin/weave https://ra ...