HDU 5417 Victor and Machine

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5417

Problem Description

Victor has a machine. When the machine starts up, it will pop out a ball immediately. After that, the machine will pop out a ball every w seconds. However, the machine has some flaws, every time after x seconds of process the machine has to turn off for y seconds for maintenance work. At the second the machine will be shut down, it may pop out a ball. And while it‘s off, the machine will pop out no ball before the machine restart.

Now, at the 0 second, the machine opens for the first time. Victor wants to know when the n-th ball will be popped out. Could you tell him?

Input

The input contains several test cases, at most 100 cases.

Each line has four integers x, y, w and n. Their meanings are shown above。

1≤x,y,w,n≤100.

Output

For each test case, you should output a line contains a number indicates the time when the n-th ball will be popped out.

Sample Input

2 3 3 3

98 76 54 32

10 9 8 100

Sample Output

10

2664

939

题意:

Victor有一个机器,这个机器每次开启的瞬间会弹出一个小球,之后每隔ww秒会弹出一个小球。因为机器不是很完善,该机器每开启xx秒就得关闭yy秒进行调整,在机器关闭的瞬间可能会有小球弹出,关闭之后一直到下一次开启之前都不会有小球弹出。

00时刻,机器第一次开启,Victor想要知道第nn个小球弹出的时刻,你能够告诉他吗?

大水题,模拟。

 1 #include <iostream>
 2 using namespace std;
 3
 4 int main()
 5 {
 6     int n,w,x,y;
 7     while (cin>>x>>y>>w>>n)
 8     {
 9           int t=0,tt=0;//tt记录离刚开机多长时间
10           n--;
11           while (n>0)
12           {
13                 tt+=w;
14                 if (tt<x)
15                 {
16                          n--;
17                          t+=w;
18                 }
19                 else if (tt==x)
20                 {
21                      n--;
22                      t+=w;
23                      if (n>0)
24                      {
25                              tt=0;
26                              t+=y;
27                              n--;
28                      }
29                 }
30                 else
31                 {
32                     t+=w+x+y-tt;
33                     tt=0;
34                     n--;
35                 }
36           }
37           cout <<t<<endl;
38     }
39     return 0;
40 }
41                     

时间: 2024-12-28 06:05:46

HDU 5417 Victor and Machine的相关文章

ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fl

HDU 5418 Victor and World 允许多次经过的TSP

题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5418 bestcoder(中文): http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=619&pid=1002 Victor and World Accepts: 99 Submissions: 644 Time Limit: 4000/2000 MS (Java/Others) Memory Limi

BestCoder Round #52 (div.2) HDU 5418 Victor and World (DP+状态压缩)

[题目链接]:click here~~ [题目大意]: 问题描写叙述 经过多年的努力,Victor最终考到了飞行驾照. 为了庆祝这件事,他决定给自己买一架飞机然后环游世界. 他会驾驶一架飞机沿着规定的航线飞行.在地球上一共同拥有nn个国家,编号从11到nn.各个国家之间通过mm条双向航线连接,第ii条航线连接第u_iu?i??个国家与第v_iv?i??个国家,通过这条航线须要消耗w_iw?i??升油.且从11号国家能够直接或间接到达22到nn中随意一个国家. Victor一開始位于11号国家.他

HDU 5418——Victor and World——————【状态压缩+floyd】

Victor and World Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 891    Accepted Submission(s): 399 Problem Description After trying hard for many years, Victor has finally received a pilot li

HDU 5418 Victor and World (状态压缩dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5418 题目大意:有n个结点m条边(有边权)组成的一张连通图(n <16, m<100000).求从第一个点出发,经过每个点至少一次后回到原点的最小路径边权和. 分析:发现我还真是菜. n<16,很明显的状态压缩标记,先将所有点的编号减去1,使其从0开始编号.dp[i][j]表示从0号点出发,当前状态为i (二进制位为1表示对应点已走过,否则没走过), 当前位置为 j,  回到原点的最小代价,

HDU 4052 Adding New Machine(矩形面积并)

Adding New Machine Problem Description Incredible Crazily Progressing Company (ICPC) suffered a lot with the low speed of procedure. After investigation, they found that the bottleneck was at Absolutely Crowded Manufactory (ACM). In oder to accelerat

HDU 5419——Victor and Toys——————【线段树|差分前缀和】

Victor and Toys Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 654    Accepted Submission(s): 219 Problem Description Victor has n toys, numbered from 1 to n. The beauty of the i-th toy is wi

HDU 5067-Harry And Dig Machine(DFS)

Harry And Dig Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 435    Accepted Submission(s): 153 Problem Description As we all know, Harry Porter learns magic at Hogwarts School. Howeve

hdu 5418 Victor and World

click here~~ ***Victor and World*** Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the