hihoCoder 1391 Countries【预处理+排序+优先队列】2016北京网络赛
题目:http://hihocoder.com/problemset/problem/1391
题目大意:
A和B两个国家互射导弹,每个国家都有一个防御系统,在防御系统开启的时间内可以将到达本国的导弹反弹回去(掉头,防御系统不能开开关关)。
现在已知:Ta、Tb为A、B两国导弹防御能开启的持续时间,X为B国开启导弹防御系统的时刻(持续时间为[X,Tb+X],包含端点)
A向B发射N枚导弹,B向A发射M枚导弹。每枚导弹有3个值:发射时间,从A到B或从B到A的飞行时间,伤害值。
现在A可以在任意时刻开启防御系统,求A所受到的最小伤害值。
题目思路:
【预处理+排序+堆】
首先预处理,求出每枚导弹不会打到A需要A国防御系统开启的时间段[st,et],只有A开启防御的时间段[Y,Y+Ta]包含[st,et]那么这枚导弹不会打到A。
预处理之后将每枚导弹按照et从小到大排序。
从1到n+m枚导弹,对于当前这枚导弹,如果需要被防御,那么A防御系统的结束时间就为et,那么开启时间就为et-Ta
那么将之前已经被防御的导弹中st<et-Ta的移除出去,表示这些导弹不能在当前决策中被防御。
可以开个STL的优先队列或者堆记录之前被防御的导弹序号,按照st从小到大存,每次比较最小的st和开启时间et-Ta。并在过程中增减伤害值,并记录最小伤害。
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 20004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas, cass;
int n, m, lll, ans;
int Ta, Tb, X, sum;
struct xxx
{
LL st, ct, et, d;
}a[N], b[N];
struct cmp1
{
bool operator ()(const int &aa, const int &bb)
{
return a[aa].st > a[bb].st;
}
};
bool cmp(xxx aa, xxx bb)
{
return aa.et < bb.et;
}
int main()
{
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
int i, j, k;
int x, y, z;
while (~scanf("%d%d", &Ta, &Tb))
{
lll = ; ans = MAX; sum = ;
scanf("%d%d%d", &X, &n, &m);
for (i = ; i <= n; i++)
{
scanf("%d%d%d", &b[i].st, &b[i].ct, &b[i].d);
b[i].et = b[i].st + b[i].ct;
if (b[i].et >= X && b[i].et <= X + Tb)
{
sum += b[i].d;
a[++lll].st = b[i].et + b[i].ct;
j = Tb + X - a[lll].st;
j = j % ( * b[i].ct);
a[lll].et = Tb + X - j;
a[lll].d = b[i].d;
if (j >= b[i].ct)a[lll].et += b[i].ct + b[i].ct;
if (a[lll].st + b[i].ct<X || a[lll].st>Tb + X)a[lll].et = a[lll].st;
}
}
for (i = ; i <= m; i++)
{
scanf("%d%d%d", &b[i].st, &b[i].ct, &b[i].d);
b[i].et = b[i].st + b[i].ct;
sum += b[i].d;
a[++lll].st = b[i].et;
j = Tb + X - a[lll].st;
j = j % ( * b[i].ct);
a[lll].et = Tb + X - j;
a[lll].d = b[i].d;
if (j >= b[i].ct)a[lll].et += b[i].ct + b[i].ct;
if (a[lll].st + b[i].ct<X || a[lll].st>Tb + X)a[lll].et = a[lll].st;
}
sort(a + , a + lll + , cmp);
priority_queue<int, vector<int>, cmp1>q; for (i = ; i <= lll; i++)
{
q.push(i); y = a[i].et;
sum -= a[i].d;
x = q.top();
while (y - a[x].st > Ta && !q.empty())
{
sum += a[x].d;
q.pop(); x = q.top();
}
ans = min(ans, sum);
}
printf("%d\n", ans);
}
return ;
}
hihoCoder 1391 Countries【预处理+排序+优先队列】2016北京网络赛的更多相关文章
- 2016北京网络赛 hihocoder 1391 Countries 树状数组
Countries 描述 There are two antagonistic countries, country A and country B. They are in a war, and ...
- 离线树状数组 hihocoder 1391 Countries
官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...
- hihocoder1236(北京网络赛J):scores 分块+bitset
北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT
2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...
- 2015北京网络赛 J Scores bitset+分块
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...
- hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)
时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...
随机推荐
- keystone v3 相关介绍
1) 涉及到如下几个概念:User.Tenant.Role.Token.http://www.ibm.com/developerworks/cn/cloud/library/1506_yuwz_key ...
- POJ 1503
http://poj.org/problem?id=1503 对于这个题我也是醉了,因为最开始是有学长和我们说过这个题目的,我以为我记得题目是什么意思,也就没看题目,结果按案例去理解题意,结果WA了一 ...
- struts2 学习路线
1.请求:开发struts2流程,(常见配置.action的方法的访问.ServletApi的访问.结果页面类型) 2.强求:封装参数.类型转换.数据校验.国际化.拦截器. 3.响应页面的生成:文件上 ...
- 使用logrotate管理nginx日志文件
本文转载自:http://linux008.blog.51cto.com/2837805/555829 描述:linux日志文件如果不定期清理,会填满整个磁盘.这样会很危险,因此日志管理是系统管理员日 ...
- 8.js模式-状态模式
1. 状态模式 var offLightState = function(light){ this.light = light; } offLightState.prototype.buttonWas ...
- PLSQL
select t.*,rowid from Table t; 编辑器设置
- Android状态栏微技巧,带你真正意义上的沉浸式
记得之前有朋友在留言里让我写一篇关于沉浸式状态栏的文章,正巧我确实有这个打算,那么本篇就给大家带来一次沉浸式状态栏的微技巧讲解. 其实说到沉浸式状态栏这个名字我也是感到很无奈,真不知道这种叫法是谁先发 ...
- 仿知乎程序 fragment的切换以及toolbar在不同页面下显示的menu不同
我们在看知乎的时候,你会发现,首页,发现,关注,收藏,草稿这五项,你在点击之后进入到相应页面之后,侧滑菜单还在,你左侧滑一下,这个侧滑菜单还在,而提问,左滑屏幕,这个页面就没有,有点像返 ...
- 【leetcode】Merge Two Sorted Lists(easy)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- 【编程题目】在从 1 到 n 的正数中 1 出现的次数
30.在从 1 到 n 的正数中 1 出现的次数(数组)题目:输入一个整数 n,求从 1 到 n 这 n 个整数的十进制表示中 1 出现的次数.例如输入 12,从 1 到 12 这些整数中包含 1 的 ...