丽娃河的狼人传说

Time limit per test: 1.0 seconds

Time limit all tests: 1.0 seconds

Memory limit:  megabytes

丽娃河是华师大著名的风景线。但由于学校财政紧缺,丽娃河边的路灯年久失修,一到晚上就会出现走在河边要打着手电的情况,不仅非常不方便,而且影响安全:已经发生了大大小小的事故多起。

方便起见,丽娃河可以看成是从  到 n 的一条数轴。为了美观,路灯只能安装在整数点上,每个整数点只能安装一盏路灯。经专业勘测,有 m 个区间特别容易发生事故,所以至少要安装一定数量的路灯,

请问至少还要安装多少路灯。
Input 第一行一个整数 T (≤T≤),表示测试数据组数。 对于每组数据: 第一行三个整数 n,m,k (≤n≤,≤m≤,≤k≤n)。 第二行 k 个不同的整数用空格隔开,表示这些位置一开始就有路灯。 接下来 m 行表示约束条件。第 i 行三个整数 li,ri,ti 表示:第 i 个区间 [li,ri] 至少要安装 ti 盏路灯 (≤li≤ri≤n,≤ti≤n)。 Output 对于每组数据,输出 Case x: y。其中 x 表示测试数据编号(从 开始),y 表示至少要安装的路灯数目。如果无解,y 为 −。
Examples
Input Output Case :
Case :
Case : Note 因为今天不是满月,所以狼人没有出现。
Source
华东师范大学网赛 /**
题目:Problem #3263 丽娃河的狼人传说
链接:http://acm.ecnu.edu.cn/problem/3263/
题意:给定一个数n,表示一个1-n的数轴,给定一个k,表示数轴上k个位置已经安装了灯。给定一个m,表示有m个区间[l,r],
每个区间后面有个整数值表示在这个区间至少要有多少盏灯。l,r都是整数。灯只可以安装在数轴的整数点上。
问至少要安装多少盏灯,才能使所有区间都满足自己要求的条件。如果无解,输出-1. 思路:贪心,对r进行排序即可。 */ #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int maxn = 1e5+;
int T, n, m, k;
int lgt[];
struct node
{
int l, r, t;
bool operator < (const node&k)const {
return r<k.r;
}
}a[];
int main()
{
cin>>T;
int cas = ;
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
memset(lgt, , sizeof lgt);
for(int i = ; i <= k; i++){
int x;
scanf("%d",&x);
lgt[x] = ;
}
int flag = ;
for(int i = ; i < m; i++){
scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].t);
if(a[i].r-a[i].l+<a[i].t){flag = ;}
}
if(flag){
printf("Case %d: -1\n",cas++) ; continue;
}
sort(a,a+m);
int ans = ;
for(int i = ; i < m; i++){
int l = a[i].l, r = a[i].r;
int cnt = ;
for(int j = l; j <= r; j++){
cnt += lgt[j];
}
if(cnt>=a[i].t) continue;
cnt = a[i].t-cnt;
for(int j = r; j >= l&&cnt; j--){
if(lgt[j]==){
lgt[j] = ; cnt--;
ans ++;
}
}
}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}

Problem #3263 丽娃河的狼人传说 区间满足灯数,r排序后贪心。的更多相关文章

  1. ECNU 3263 丽娃河的狼人传说(差分约束)

    丽娃河的狼人传说 Time limit per test: 1.0 seconds Memory limit: 256 megabytes 丽娃河是华师大著名的风景线.但由于学校财政紧缺,丽娃河边的路 ...

  2. ECNU 3263 - 丽娃河的狼人传说

    一定要纪念一下第一道在比赛中自己做出来的贪心. 题目链接:http://acm.ecnu.edu.cn/problem/3263/ Time limit per test: 1.0 seconds T ...

  3. ECNU 3263 丽娃河的狼人传说 (贪心)

    链接:http://acm.ecnu.edu.cn/problem/3263/ 题意: 从 1 到 n 的一条数轴.有 m 个区间至少要安装一定数量的路灯,路灯只能装在整数点上,有k盏路灯已经安装好  ...

  4. EOJ 3263 丽娃河的狼人传说

    差分约束系统,$spfa$. 首先判断无解,若某个约束的$t$大于区间长度,则一定无解. 否则一定有解,可以得到一系列的不等式: 最终区间和大于等于目前的区间和:$S[R]-S[L-1]≥val$, ...

  5. EOJ3263:丽娃河的狼人传说(贪心)

    传送门 题意 分析 考虑将区间按右端点排序,再遍历区间,操作即可 建议以加方式写 trick 1.不需要判区间重合 代码 #include<cstdio> #include<cstr ...

  6. POJ 3468 A Simple Problem with Integers(线段树功能:区间加减区间求和)

    题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  7. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  8. (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)

    称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...

  9. Problem after converting keras model into Tensorflow pb - 将keras模型转换为Tensorflow pb后的问题

    I'm using keras 2.1.* with tensorflow 1.13.* backend. I save my model during training with .h5 forma ...

随机推荐

  1. nodejs全局变量设置设置

    编辑 ~/.npmrc 加入下面内容 prefix = D:\tool\nodejs\node_global cache = D:\tool\nodejs\node_cache registry = ...

  2. Swift数独游戏优化——C++与OC混编、plist自动生成

    一.为什么要C++与OC混编? 在我之前的数独游戏中涉及到的数独游戏生成算法是参考的网上其他人的算法,是利用C++来实现的.   但是在我的例子中我发现这样存在一定的局限性: 1.我是利用Termin ...

  3. Android修改状态栏颜色全方位教程

    关键字:状态栏着色 透明状态栏 沉浸式 白底黑字 Github Demo:https://github.com/imflyn/Eyes 参考文章: Android-transulcent-status ...

  4. http://blog.chinaunix.net/uid-20577907-id-3519578.html

    http://blog.chinaunix.net/uid-20577907-id-3519578.html

  5. 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告

    今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...

  6. [Typescript] Improve Readability with TypeScript Numeric Separators when working with Large Numbers

    When looking at large numbers in code (such as 1800000) it’s oftentimes difficult for the human eye ...

  7. jbpm4(参数设置)

    1.processDefinition.getDescription() <process name="task_test_2" xmlns="http://jbp ...

  8. python 页面信息抓取

    1. 特点 在python 解析html这篇文章中已经做了初步的介绍,接下来再坐进一步的说明.python抓取页面信息有下面两个特点: 依赖于HTML的架构. 微小的变化可能会导致抓取失败,这取决于你 ...

  9. 【Java】Java_06 基本数据类型

    1.基本数据类型 Java是一种强类型语言,每个变量都必须声明其类型. .  Java的数据类型分为两大类:基本类型(primitive type)和引用类型    (reference type) ...

  10. Eclipse安装Properties Editore插件

    Properties Editor for Eclipse3[1].0-3.2安装使用-http://jzgl-javaeye.iteye.com/blog/386010 PropertiesEdit ...