模拟,注意需要比较队头与当前时间的大小关系。

 #include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 10005
#define INF 0xffffff typedef struct {
int i, t;
} node_t; node_t Q[][MAXN];
int buf[MAXN];
int rear[], front[]; int main() {
int case_n;
int n, t, m;
int i, j, k, a;
int d;
char s[]; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &case_n);
for (a=; a<case_n; ++a) {
scanf("%d %d %d", &n, &t, &m);
rear[] = rear[] = ;
front[] = front[] = ;
for (i=; i<=m; ++i) {
scanf("%d %s", &k, s);
if (s[] == 'l')
j = ;
else
j = ;
Q[j][rear[j]].i = i;
Q[j][rear[j]].t = k;
rear[j]++;
}
Q[][rear[]].t = INF;
Q[][rear[]].t = INF;
d = ;
int ans = ;
while (front[]<rear[] || front[]<rear[]) {
if (Q[d][front[d]].t>ans && Q[!d][front[!d]].t<=ans) {
ans += t;
d = !d;
} else if ((Q[d][front[d]].t>Q[!d][front[!d]].t || front[d]>=rear[d]) && Q[!d][front[!d]].t>ans) {
ans = Q[!d][front[!d]].t + t;
d = !d;
}
if (ans < Q[d][front[d]].t)
ans = Q[d][front[d]].t;
j = ;
i = front[d];
while (j<n && i<rear[d] && Q[d][i].t<=ans) {
buf[Q[d][i].i] = ans + t;
++j;
++i;
}
ans += t;
front[d] = i;
d = !d;
}
if (a)
printf("\n");
for (i=; i<=m; ++i)
printf("%d\n", buf[i]);
} return ;
}

【HDOJ】1406 Ferry Loading III的更多相关文章

  1. 【HDOJ】3277 Marriage Match III

    Dinic不同实现的效率果然不同啊. /* 3277 */ #include <iostream> #include <string> #include <map> ...

  2. Ferry Loading III[HDU1146]

    Ferry Loading IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. 【LeetCode】732. My Calendar III解题报告

    [LeetCode]732. My Calendar III解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar ...

  4. 【LeetCode】170. Two Sum III – Data structure design

    Difficulty:easy  More:[目录]LeetCode Java实现 Description Design and implement a TwoSum class. It should ...

  5. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  6. 【转】error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

    错误信息: /usr/local/memcacheq/bin/memcacheq: error while loading shared libraries: libevent-2.0.so.5: c ...

  7. 【Leafletjs】6.Control.Loading推展-在地图上边框添加加载动态条

    在已有的Control.Loading控件基础上结合CSS3 animation属性实现 .nz-loading .nz-loader { display: block; -webkit-animat ...

  8. 【BZOJ】1406: [AHOI2007]密码箱

    http://www.lydsy.com/JudgeOnline/problem.php?id=1406 题意:求$0<=x<n, 1<=n<=2,000,000,000, 且 ...

  9. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

随机推荐

  1. ubuntu下mysql的常用命令

    首先安装mysql:sudo?apt-get?install?mysql-server?mysql-client? 1.终端启动MySQL:/etc/init.d/mysql start:(stop ...

  2. 图像的影像地图超链接,<map>标签浅谈

    在HTML中还可以把图片划分成多个热点区域,每一个热点域链接到不同网页的资源.这种效果的实质是把一幅图片划分为不同的热点区域,再让不同的区域进行超链接.这就是影像地图.要完成地图区域超链接要用到三种标 ...

  3. HDU 2853 Assignment(KM最大匹配好题)

    HDU 2853 Assignment 题目链接 题意:如今有N个部队和M个任务(M>=N),每一个部队完毕每一个任务有一点的效率,效率越高越好.可是部队已经安排了一定的计划,这时须要我们尽量用 ...

  4. java web mvc思想介绍

    1.首先简介一下什么是MVC思想. 在百度百科里面对MVC的说明,MVC全名是Model View Controller.是模型(model)-视图(view)-控制器(controller)的缩写. ...

  5. 云平台编程与开发(七)-使用X5Cloud云平台开发网络彩讯

    云平台编程与开发(七)-使用X5Cloud云平台开发网络彩讯 博客分类: 云平台 云计算 Java Android Android 云平台 Java 网络彩讯定义以及工作大概流程  下载试用地址:ap ...

  6. 二分-hdu-4768-Flyer

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4768 题目意思: 有n个A.B.C,每个Ai,Bi,Ci,对于每个P=Ai+k*Ci(P<=B ...

  7. Java基础知识强化93:算一下你来到这个世界多少天的案例

    1. 分析: (1)键盘录入你的出生年月日 (2)把该字符串转换为一个日期 (3)通过该日期得到一个毫秒值 (4)获取当前时间的毫秒值 (5)用(4)-(3)得到一个毫秒值 (6)把E的毫秒值转换为天 ...

  8. centos redis安装

    对redis不是很了解,先写一个简单的安装过程 系统版本:centos 6.5 redis版本:2.8.23 一.安装依赖 sudo yum install tcl gcc gcc-c++ -y 二. ...

  9. c#委托中另外一种用法

    在c#委托中,经常可能遇到函数重载的情况,可是又需要在一个函数中调用这些函数,一般我都是根据多个函数重载个数,也写上这么多个函数重载.比如 public double T1(int r) { retu ...

  10. Xml序列化自引用/循环引用问题2

    1.类定义: public class Student { public int ID { get; set; } public string Name { get; set; } //[XmlIgn ...