JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
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】时间机器的更多相关文章
- JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠
JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...
- [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)
题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...
- 【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 ...
- JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团
100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Got ...
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)
5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...
- 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 ...
- 【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 ...
随机推荐
- winform显示word和ppt文档
最近所做的项目中需要在Winform窗体中显示Office文档.刚开始就使用webBrowser控件实现的,但是后来发现这个控件在显示Office文档的时候有个限制:只支持Office2003之前的版 ...
- linux awk详解
awk: awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑, awk在其对数据分析并生成报告时,显得尤为强大. 简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开 ...
- Eclipse创建java web工程
Eclipse创建java web工程 eclipse版本:eclipse-jee-4.5-win32-x64 tomcat版本:apache-tomcat-7.0.63-windows-x64 jd ...
- hadoop报错:could only be replicated to 0 nodes, instead of 1
错误 [root@hadoop test]# hadoop jar hadoop.jarcom.hadoop.hdfs.CopyToHDFS 14/01/26 10:20:00 WARN hdfs.D ...
- 《内蒙古自治区第十二届大学生程序设计竞赛试题_G: 最大收益》
问题 G: 最大收益 内存限制:128 MB时间限制:1 S标准输入输出 题目类型:传统评测方式:文本比较上传者:外部导入 提交:87通过:23 返回比赛提交提交记录 题目描述 Elly的叔叔经营一家 ...
- [LC] 236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
- 吴裕雄--天生自然python学习笔记:Python3 数据结构
列表 Python中列表是可变的,这是它区别于字符串和元组的最重要的特点,一句话概括即:列表可以修改,而字符串和元组不能. list.append(x) 把一个元素添加到列表的结尾,相当于 a[len ...
- 吴裕雄--天生自然 R语言开发学习:导入数据
2.3.6 导入 SPSS 数据 IBM SPSS数据集可以通过foreign包中的函数read.spss()导入到R中,也可以使用Hmisc 包中的spss.get()函数.函数spss.get() ...
- maven依赖找不到,快速解决
以微信支付依赖为例子 wxpay-sdk-3.0.9.jar1.阿里云仓库搜索地址https://maven.aliyun.com/mvn/search 2.搜索你要找的依赖,对号入座 3.确保mav ...
- python django 模板语言循环字典
urls.py from django.conf.urls import url from django.contrib import admin from cmdb import views url ...