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. excle导出、导入、下载_jeesite注解@ExcelField

    介绍:对Apache POI 3.9的简单封装,实现Excel的导出导入功能.使用Annotation定义导出导入字段. 优点:1.简单易用,支持大数量导出,配置简单,代码量少. 2.支持Excel ...

  2. 微信小程序开发-易源API的调用

    起因:在开发一款旅游类微信小程序时,需要接入大量的景点信息,此时可以选择自己新建数据库导入数据并读取,但是对于我来说,因为只有一个人,数据库还涉及到需要维护方面,选择调用已有API. 过程:首先查阅微 ...

  3. VSAN磁盘扩容与收缩(二)

  4. [LC] 215. Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  5. 批量修改ACCESS表列名

    问题来源:从ODBC导入数据到ACCESS 再从ACCESS导入到SQL数据库,ACCESS会多带个DBO. 所以需要批量修改ACCESS的表名. 首先需要引用ADOX引用方法:打开ACCESS的VB ...

  6. 初级vector

    标准库vector类型 #include<vector> using std::vector; vector为一个类模板. vector的初始化 vector<T> v1; v ...

  7. 吴裕雄--天生自然HTML学习笔记:HTML 表格

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. a, b = a, a+b 和a=b b=a+b的区别

    n,a,b=0,0,1 while n<5: print(b) a,b=b,a+b n=n+1 和 n,a,b=0,0,1 while n<5: print(b) a=b b=a+b n= ...

  9. 初识JS之数据类型

    JavaScript JavaScript引入方式 Script标签内写代码 <script> // 在这里写你的JS代码 </script> 引入额外的JS文件 <sc ...

  10. 杂记:OSX下编译安装最新版RedisDesktopMmanager

    之前使用Redis数据库时因为操作简单,一直使用的是“redis-cli”连接Redis:后来因为数据展示的不是很直观,所以开始使用带有图形界面的Redis客户端:RedisDesktopMmanag ...