hihocoder1391 Country
题解的那种前缀和以前没学过,感觉是种套路
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e4+5;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int Ta,Tb,X;
int N,M;
struct Node{
int st,ti,da;
void inpu() {
scanf("%d %d %d",&st,&ti,&da);
}
}A[MAXN],B[MAXN*2];
map<int,int> mp;
map<int,int>::iterator it;
int main(){
while(~scanf("%d %d %d",&Ta,&Tb,&X)) {
mp.clear();
scanf("%d %d",&N,&M);
int tot = 0; int ans;
for(int i = 1; i <= N; ++i) A[i].inpu();
for(int i = 1; i <= M; ++i) B[i].inpu();
int st = X; int ed = X+Tb;
for(int i = 1; i <= N; ++i) {
if(A[i].st+A[i].ti >= st && A[i].st+A[i].ti <= ed) {
B[++M].st = A[i].st+A[i].ti; B[M].ti = A[i].ti; B[M].da = A[i].da;
}
}
for(int i = 1; i <= M; ++i) {
tot += B[i].da; int k = 0;
if(B[i].st+2*B[i].ti >= st && B[i].st+2*B[i].ti <= ed) {
k = (ed-B[i].st-2*B[i].ti)/2/B[i].ti + 1;
}
int t1 = B[i].st+B[i].ti; int t2 = t1+2*k*B[i].ti;
if(t2-Ta < t1+1) {
mp[t2-Ta] -= B[i].da; mp[t1+1] += B[i].da;
}
}
ans = tot;
for(it = mp.begin(); it != mp.end(); ++it) {
tot += it->second;
ans = min(ans,tot);
}
printf("%d\n",ans);
}
return 0;
}
hihocoder1391 Country的更多相关文章
- wifi的country code
转自:http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.htmlCountry A 2 A 3 Number ------------- ...
- ural 1073. Square Country
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...
- 最小生成树 kruskal hdu 5723 Abandoned country
题目链接:hdu 5723 Abandoned country 题目大意:N个点,M条边:先构成一棵最小生成树,然后这个最小生成树上求任意两点之间的路径长度和,并求期望 /************** ...
- hihocoder-1391&&北京网赛09 Countries(优先队列)
题目链接: Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, country ...
- 01背包 URAL 1073 Square Country
题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5723 Abandoned country(落后渣国)
HDU 5723 Abandoned country(落后渣国) Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 ...
- HDU 5723 Abandoned country (最小生成树 + dfs)
Abandoned country 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned coun ...
- [转]How to convert IP address to country name
本文转自:http://www.codeproject.com/Articles/28363/How-to-convert-IP-address-to-country-name Download ...
随机推荐
- JDK,JRE,JVM的区别与联系
JDK : Java Development ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工 ...
- UOJ 241. 【UR #16】破坏发射台 [矩阵乘法]
UOJ 241. [UR #16]破坏发射台 题意:长度为 n 的环,每个点染色,有 m 种颜色,要求相邻相对不能同色,求方案数.(定义两个点相对为去掉这两个点后环能被分成相同大小的两段) 只想到一个 ...
- BZOJ 4455: [Zjoi2016]小星星 [容斥原理 树形DP]
4455: [Zjoi2016]小星星 题意:一个图删掉一些边形成一棵树,告诉你图和树的样子,求让图上的点和树上的点对应起来有多少方案 看了很多题解又想了一段时间,感觉题解都没有很深入,现在大致有了自 ...
- POJ1741Tree [点分治]【学习笔记】
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20098 Accepted: 6608 Description ...
- chrome_options
用法 from selenium.webdriver.chrome.options import Options chorme_option=Options() chorme_option.add ...
- 【Java】多线程初探
参考书籍:<Java核心技术 卷Ⅰ > Java的线程状态 从操作系统的角度看,线程有5种状态:创建, 就绪, 运行, 阻塞, 终止(结束).如下图所示 而Java定义的 ...
- 在tableViewCell的点击事件中处理界面跳转问题
UIViewController *controller; UIView *view = self.view; while (1) { controller = (UIViewController * ...
- 织梦搜索页使用arclist标签
织梦默认不能在搜索页使用arclist标签,我们对代码做一些小改动即可 打开include/arc.searchview.class.php 一.查找代码: require_once(DEDEINC. ...
- hdu 2048 递推&&错排
直接贴出递推公式: cnt[n]=(i-1)*(cnt[n-1]+cnt[n-2]); 数组保存的是失败的种数 AC代码: #include<cstdio> const int maxn= ...
- uva208
一道简单的路径打印,首先需要一次dfs判断能否从1到达目标点,否则可能会超时.还有一点就是那个格式需要注意下,每条路径前没有空格(看起来好像有3个空格)-. AC代码: #include<cst ...