POJ 3282 Ferry Loading IV(简单模拟)
来源:互联网 发布:沙特知乎 编辑:程序博客网 时间:2024/05/22 14:24
Description
Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of the ferry.
There is an l-meter-long ferry that crosses the river. A car may arrive at either river bank to be transported by the ferry to the opposite bank. The ferry travels continuously back and forth between the banks so long as it is carrying a car or there is at least one car waiting at either bank. Whenever the ferry arrives at one of the banks, it unloads its cargo and loads up cars that are waiting to cross as long as they fit on its deck. The cars are loaded in the order of their arrival; ferry's deck accommodates only one lane of cars. The ferry is initially on the left bank where it broke and it took quite some time to fix it. In the meantime, lines of cars formed on both banks that await to cross the river.
Input
The first line of input contains c, the number of test cases. Each test case begins with l, m. m lines follow describing the cars that arrive in this order to be transported. Each line gives the length of a car (in centimeters), and the bank at which the car arrives ("left" or "right").
Output
For each test case, output one line giving the number of times the ferry has to cross the river in order to serve all waiting cars.
Sample Input
420 4380 left720 left1340 right1040 left15 4 380 left720 left1340 right1040 left15 4 380 left720 left1340 left1040 left15 4 380 right720 right1340 right1040 right
Sample Output
3356
简单模拟,最后20分钟开的这道题,写的急了,wa了3发,真想骂自己SB。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<queue>using namespace std;int t,len,n;int main(){ char str[15]; int x; scanf("%d",&t); while(t--) { queue<int>l; queue<int>r; scanf("%d%d",&len,&n); for(int i=0;i<n;i++) { scanf("%d%s",&x,str); if(str[0]=='l') l.push(x); else r.push(x); } int d=1;//记录船在哪边1代表左 int num=0; while(!l.empty()||!r.empty()) { int sum=len*100; if(d==1) { int s=0; while(!l.empty()&&s+l.front()<=sum) { s+=l.front(); l.pop(); } d=-d; num++; } else { int s=0; while(!r.empty()&&s+r.front()<=sum) { s+=r.front(); r.pop(); } d=-d; num++; } } printf("%d\n",num); } return 0;}
- POJ 3282 Ferry Loading IV(简单模拟)
- POJ 3282 Ferry Loading IV(模拟)
- POJ 3282 Ferry Loading IV(模拟,队列)
- POJ 3282 Ferry Loading IV(模拟,队列)
- POJ-3282(摆渡问题)(Ferry Loading IV )
- POJ 3282 Ferry Loading IV 可能会
- Ferry Loading IV(队列)
- POJ-2336 Ferry Loading II(简单DP)
- Sicily 1366. Ferry Loading IV
- poj 2336 Ferry Loading II
- POJ 2609 Ferry Loading 笔记
- 贪心之 Ferry Loading II (POJ 2336)
- POJ 2336 Ferry Loading II (贪心或动态规划)
- UVA 10901 Ferry Loading III 队列模拟
- POJ 2336 Ferry Loading II [贪心 DP]
- POJ 2609 Ferry Loading 双塔DP
- poj 2336 Ferry Loading II 贪心
- POJ 2609 Ferry Loading(双塔DP)
- Oracle创建删除用户、角色、表空间、导入导出
- tomcat manager
- hdu2544最短路
- 额特然图一5有人有人特与人同意
- XML中DTD,XSD的区别与应用
- POJ 3282 Ferry Loading IV(简单模拟)
- 单例模式的七种写法
- ListView,CursorAdapter,ContextMenu之间的映射关系学习笔记。
- Java基础知识之Class结构
- poj3159(差分约束)
- Orz教主第五次模拟(做题情况+题目分析+代码)[未完]
- springMVC源码下载
- UVa 11538 - Chess Queen (组合数学)
- editplus创建时候的几个注意事项