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

 #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. 基于wax的lua IOS插件开发

    作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf Objective-C的运行时支持新增类型和方法,但是由于 ...

  2. jquery cycle pugin

    插件地址: http://jquery.malsup.com/cycle/ <div id="propaganda"><div id="pgdImg&q ...

  3. SKPhysicsBody类

    继承自 NSObject 符合 NSCodingNSCopyingNSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit.framewo ...

  4. 更改navigationController push和pop界面切换动画

    For Push: MainView *nextView=[[MainView alloc] init]; [UIView beginAnimations:nil context:NULL]; [UI ...

  5. Apache Tomcat8必备知识

    Apache Tomcat8必备知识 作者:chszs,转载需注明.博客主页: http://blog.csdn.net/chszs 一.Apache Tomcat 8介绍 Apache Tomcat ...

  6. struts2,hibernate,spring整合笔记(1)

    今天终于配置好了ssh框架的整合,记录下过程供参考 环境:window8.1,jdk1.7 ,带有javaee的eclipse,也就是说要能发布web项目,TOMCAT服务器,tomcat配置涉及到环 ...

  7. Android 连接Wifi和创建Wifi热点 demo

    android的热点功能不可见,用了反射的技术搞定之外. Eclipse设置语言为utf-8才能查看中文注释 上代码: MainActivity.java package com.widget.hot ...

  8. 美洽SDK

    简介 GitHub地址:https://github.com/Meiqia/MeiqiaSDK-Android 开发文档:http://meiqia.com/docs/meiqia-android-s ...

  9. 利用ParameterizedType获取泛型参数类型

    //利用ParameterizedType获取java泛型的参数类型 public class Demo {     public static void main(String[] args) { ...

  10. U1总结

    import java.io.Writer; import java.util.Iterator; import javax.xml.transform.TransformerFactory; imp ...