uva 10134 - AutoFish(simulation)
来源:互联网 发布:天地图 数据库 编辑:程序博客网 时间:2024/05/29 16:56
Question 4: AutoFish
The Problem
You've built an amazing fish-catching robot, but you've discovered one small flaw: the robot can't decide whether to fish or cut bait.
You've designed a language for the Control of Oceangoing Devices (COD) which you plan to use to program the robot. COD has three instructions:
fish Fish for ten minutes. bait Cut bait for ten minutes. lunch No operation for ten minutes.
Bait is required to catch fish. The robot must cut bait for twenty minutes (execute twobait instructions) to generate a single bait unit, enough bait to catch a single fish. Other instructions (fish andlunch) may be interleaved between the two bait instructions that generate a bait unit. The robot has storage for three bait units; it cannot cut any more bait if it is already storing three bait units. If the robot is storing three bait units, a bait instruction is treated as if it were a lunch instruction (a NOP). Catching a fish consumes a bait unit.
Fish have deterministic behaviour. A fish cannot be caught more often than once every seventy minutes, and after a fish has been caught the robot must fish for thirty minutes before catching another fish (they get shy). In order to successfully complete a fish instruction, the robot must have a least one bait unit. If the robot has no bait, afish instruction cannot be successfully completed and is treated as if it were alunch instruction. When the robot first starts fishing, a fish is caught on the firstfish instruction that completes (beginner's luck). If at least one fish has already been caught then a fish is caught on the completion of afish instruction if and only if: 1) the fish instruction is at least the seventh COD instruction executed since the last instruction on which a fish was caught, and 2) thefish instruction is at least the third fish instruction successfully completed since the last instruction on which a fish was caught.
The execution of a lunch instruction allows time to pass, but has no other purpose.
The robot starts with no bait; no fish have been caught.
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.Input consists of a sequence of fish, bait and lunch instructions, terminated by the end-of-file.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.Output is a line containing a single integer, indicating the number of fish the robot has caught at the end of the sequence.
Sample Input
1fishfishlunchbaitfishbaitfishbaitbaitfishfishfishfishlunchlunchlunchlunchfishfishfish
Sample Output
2
#include <iostream>#include <cstdio>using namespace std;int bait , fish , remain , sum;string execute;void initial(){bait = 0;fish = 0;remain = 0;sum = 0;}void readcase(){while(getline(cin , execute) && execute.length() != 0){if(execute == "fish"){if(bait >= 2 && ((remain >= 7 && fish >= 2) || sum == 0)){sum++;fish = 0;remain = 0;bait -= 2;}else{fish++;}remain++;}if(execute == "bait"){if(bait < 6) bait++;remain++;}if(execute == "lunch") remain++;}printf("%d\n" , sum);}int main(){int t;scanf("%d" , &t);getchar();getline(cin , execute);while(t--){initial();readcase();if(t) printf("\n");}return 0;}
- uva 10134 - AutoFish(simulation)
- Petri Net Simulation UVA
- UVa Problem 114 - Simulation Wizardry
- UVa Problem 114 - Simulation Wizardry
- uva 187 Transaction Processing(simulation)
- UVa 804 Petri Net Simulation
- Uva - 804 - Petri Net Simulation
- UVA 804 Petri Net Simulation
- uva 10901 - Ferry Loading III(simulation)
- uva 162 - Beggar My Neighbour(simulation)
- UVa 804 - Petri Net Simulation(模拟)
- [中等] UVa OJ 804 Petri Net Simulation
- ZOJ-1834 AutoFish
- Behavioral Simulation,Structural Simulation,Timing Simulation
- Cloth Simulation
- Simulation Robot
- Game Simulation
- Rigidbody Simulation
- 基于按annotation的hibernate主键生成策略
- 如何解决MyEclipse中的乱码问题
- uva 1554 - Binary Search(暴力)
- python修改文件内容
- Singleton
- uva 10134 - AutoFish(simulation)
- 为什么拷贝构造函数必须为引用传递,不能是值传递?
- adb opendir failed ,permission denied
- Paste Deployment简介以及cinder-api-paste.ini的解析(1)
- UITableView学习心得
- J2EE——servlet
- 标签的使用
- c++ this 指针详解
- Balanced Binary Tree