问题 J: Workout for a Dumbbell

时间限制: 1 Sec  内存限制: 128 MB

题目描述

Jim Ratt has just joined a local fitness center. He’s especially excited about a sequence of 10 machines that he cycles through three times for his workout. He has a fixed time which he spends on each machine, as well as a fixed recovery time after using a machine. Jim’s not the brightest guy in the world, but in the absence of anything else even he would easily be able to calculate how long his workout would take. 
But of course, Jim isn’t the only person who uses the fitness center and wouldn’t you know it but when Jim shows up there are always 10 other people there, each using one of the ten machines exclusively. Like Jim, each person has a fixed time they use on their machine as well as a fixed recovery time. This will sometimes cause Jim to have to wait for a particular machine, and Jim’s usage sometimes results in the other people having to wait as well (though if both Jim and another person want to start using a machine at the same time, Jim is polite enough to let the other person go first). Jim has gone to the center often enough that he has a good idea what everyone’s usage and recovery times are, but he has trouble determining how long it will take him to perform his workout. That’s where you are going to flex your programming muscles.

输入

Input starts with a line containing twenty integers; the first two give Jim’s usage and recovery time for machine 1, the next two give Jim’s usage and recovery time for machine 2, etc. The next line contains 3 integers u r t; the first two values are the usage and recovery times for the person who is using machine 1,and t is the time when he/she first starts using the machine. The next 9 lines specify similar information for machines 2 through 10. All usage and recovery times are positive and ≤ 5 000 000 and all start times t satisfy |t| ≤ 5 000 000. You should assume that Jim is ready to use machine 1 at time 0.

输出

Display the time when Jim has finished his workout, i.e., the moment when he has finished his usage time on machine 10 for the third time (don’t count the last recovery time for that machine).

样例输入

5 5 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 1
8 3 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0

样例输出

100

题意:小花想起了初中生物书上的蛋白质,于是要锻炼肌肉。当然这一段是跟题意没关系的。健身房有十台机器,现在给出了小花在每台机器的锻炼时间和休息时间,机器不是小花专属的,每个机器上还有一个捣蛋鬼在锻炼,捣蛋鬼有自己的锻炼时间,休息时间和开始时间,在开始时间之后,就开始不停的在这台机器上锻炼休息锻炼休息循环往复,小花在0时刻从1号机器开始锻炼,一直锻炼到10号机器,要锻炼三个来回。问锻炼完之后一共需要多少时间,最后一个锻炼的休息时间不计算在内。做法:这道题就是模拟,场上的时候因为没有读出来小花是从1号到10号有顺序进行的,以为很复杂的可以优先选择,于是,就放弃了。这个锅有点沉,我先放一放。我用d[],x[]分别代表小花在每台机器的锻炼时间和休息时间,dd[],xx[],st[]分别代表每台机器捣蛋鬼的锻炼时间,休息时间和开始时间,这里的st[]要不断更新,因为捣蛋鬼是循环往复锻炼的,所以每次的开始时间都是更新的。tim记录现在的时间,j记录现在要开始锻炼哪一台机器了,要是此时这台机器的st[]在tim之后,就代表捣蛋鬼还没开始锻炼或者处在上一轮的休息时间之中,于是,我就可以直接开始锻炼,此时st[j]就要更新,如果我锻炼完你还没开始,那么st[j]还是不变的,如果我锻炼完已经超过了你的st[j],那么st[j]就更新成我锻炼完的时间。  如果这台机器的st[j]在tim之前,我就找到最近一次开始的时间,于是判断一下捣蛋鬼此时是在锻炼还是在休息,如果在锻炼,我就需要先等一下再开始锻炼,如果在休息,我就可以直接开始锻炼,并且不要忘记更新下一次捣蛋鬼开始的时间。代码如下:
#include<stdio.h>
#include<iostream>using namespace std;long long d[15] , x[15];
long long dd[15] , xx[15] , st[15];
//long long flag[15];
long long tim;int main()
{while( scanf("%lld%lld" , &d[1] , &x[1]) != EOF){for(long long i=2; i<=10; i++){scanf("%lld%lld" , &d[i] , &x[i]);}
//        printf(".......\n");for(long long i=1; i<=10; i++){scanf("%lld%lld%lld" , &dd[i] , &xx[i] , &st[i]);
//            flag[i] = 0;   ///当st[j]>tim时  我们需要判断是还未开始训练 还是正在休息
        }
//        printf(".......\n");tim = 0;for(long long i=1; i<=30; i++){long long j = i%10;   ///现在要锻炼第几个器材if(j == 0)  j = 10;if(st[j]>tim ){tim += (d[j]+x[j]);     ///如果开始的时间在tim的后面   要么是捣蛋鬼还没有开始 如果捣蛋鬼已经快开始了 并且我从这里走过一遍了 那么捣蛋鬼现在一定不是在锻炼///因为 我上次遇见他的时候 他如果在休息 我再次遇见她 他还没与开始 那就还是在休息 如果上次遇见是在锻炼 他不锻炼完我是不会完成任务的/// 于是我走的时候捣蛋鬼也是在休息if(st[j] <= tim-x[j]){st[j] = tim-x[j];}}else if(st[j]<=tim){while( st[j]+dd[j]+xx[j] <= tim)st[j] += (dd[j]+xx[j]);   ///找到捣蛋鬼最近一次开始的时间
//                printf("%lld.%lld.%lld.%lld.\n" , j , tim , st[j] , flag[j]);
//                flag[j] = 1;if(tim <= st[j]+dd[j])   ///如果到达的时候捣蛋鬼正在健身
                {tim += st[j]+dd[j]-tim;   ///等待一段时间之后可以开始锻炼了tim += (d[j]+x[j]);       ///持续将锻炼和休息做完st[j] = max(st[j]+dd[j]+xx[j] , tim-x[j]);   ///捣蛋鬼开始的时间 要么是自己的休息昨晚 要么是等jony的运动做完 就是现在的总时间减去休息时间
                }else                     ///如果到达的时候捣蛋鬼正在休息
                {tim += (d[j]+x[j]);st[j] = max(st[j]+dd[j]+xx[j] , tim-x[j]);}}//            printf("%lld......%lld......%lld......\n" , j , tim , st[j]);
        }tim -= x[10];printf("%lld\n" , tim);}return 0;
}/*5 5
3 3
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2 2 1
8 3 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 00 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0*/

 

转载于:https://www.cnblogs.com/Flower-Z/p/9602748.html

ecna 2017 J Workout for a Dumbbell (模拟)相关推荐

  1. ECNA 2017 Problem J: Workout for a Dumbbell 模拟

    参考博客 提交链接 FROM SDUT 2018 Summer Team Contest 8th 地址 #include <iostream> #include<bits/stdc+ ...

  2. 计算机网络远程管理作业答案,石大远程2017春 计算机网络原理(含模拟实验)一次作业...

    中石油北京2017春 <计算机网络原理(含模拟实验)>第一次在线作业7 J  p3 y9 ^$ I8 o2 G 1 在OSI模型中,提供路由选择功能的层次是__________2 e* y ...

  3. 2017安徽省二c语言模拟题,2017计算机二级考试C语言模拟题及答案

    2017计算机二级考试C语言模拟题及答案 二.基本操作题(共18分) 请补充函数proc(),该函数的功能是计算下面公式SN的值: SN=1+1/3十4/5+...+2N-1/SN-1 例如,当N=2 ...

  4. 2017中石计算机网络基础试题答案,石大远程2017春计算机网络原理(含模拟实验)作业三...

    中石油北京2017春 <计算机网络原理(含模拟实验)>第三次在线作业 . l0 i9 t$ `! G$ e' z1 以下属于网络层协议的是$ X! X. |: C4 K$ _" ...

  5. 电大计算机统考模拟题在哪里学,[2017年电大]电大-计算机统考模拟题.doc

    [2017年电大]电大-计算机统考模拟题 一.单选题(每小题1分,共40分) 1.计算机问世至今已经经历四代,而划分四代的主要依据是计算机的_________. A. 规模B. 功能C. 性能D. 构 ...

  6. 计算机ps基础考试题,2017年计算机一级PS考试模拟题及答案

    2017年计算机一级PS考试模拟题及答案 Photoshop可分为图像编辑.图像合成.校色调色及特效制作部分等功能.下面是小编整理的计算机一级PS考试测试题,一起来练习练习吧! 1. 当我们在Phot ...

  7. 计算机上机操作模拟试题,2017计算机二级考试WEB上机模拟题

    2017计算机二级考试WEB上机模拟题 引导语:大家知道计算机二级考试WEB上机考试是怎么样的吗,以下是百分网小编分享给大家的2017计算机二级考试WEB上机模拟题,欢迎阅读学习! 1.打开SQLSe ...

  8. 2017年计算机自主招生试题,2017年自主招生机考模拟题

    2017年自主招生机考模拟题 (12页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 11.90 积分 2017年自主招生机考模拟试题---3说明:1. 本 ...

  9. 职称计算机word模拟题,2017职称计算机《Word》模拟测试题

    2017职称计算机<Word>模拟测试题 导语:为了方便大家职称计算机考试的考试复习,下面是小编给大家提供的职称计算机<Word>模拟测试题,大家可以参考练习,更多习题练习请关 ...

最新文章

  1. 扩增子三部曲:1分析图表解读大全(箱线,散点,热,曼哈顿,火山,韦恩,三元,网络)...
  2. IE6动态插入option
  3. java中try,catch,finally的作用
  4. python语言特点依赖平台吗_python语言的特点
  5. rhel 4/oracle linux 4/centos linux 4 配置本地yum资源库
  6. Python程序员每天必做的几个动作
  7. USB转TTL、USB转串口、USB转RS232的区别
  8. sqlite3数据存储最多存储多少条数据?达到上限如何处理?_把 14 亿人拉到一个微信群,如何实现?...
  9. Gossip协议笔记--谣言、流行病协议
  10. 刷机入门 手把手教程
  11. 花了3个小时解决了和异地女朋友一起看电影的需求(内附源码)
  12. List集合中 中contains方法的使用详解
  13. 相机PHP,C/C++、C#、PHP相机开发实例 大恒相机SDK
  14. vue拖拽盒子;vue移动
  15. Origin Pro2017使用PatchOriginPro.exe破解提示Patch unsuccessfully or already
  16. foxmail邮件只能显示邮件头,不能显示内容
  17. CSS------定位和动画
  18. 护眼灯真能护眼吗?学习专用的护眼灯推荐
  19. 知乎 | 博士毕业,选择进高校还是30万年薪私企?
  20. Firebug初级教程

热门文章

  1. TF-A中的工具介绍
  2. SLAM闲谈(一)--词袋模型
  3. FSOS森林模拟优化模型学习笔记
  4. OCIOS开发小技巧总结
  5. 成都中忻嘉业:抖音怎样查看直播回放
  6. 14岁初中生将免去四考,保送清华本硕博连读,乡亲们敲锣打鼓祝贺
  7. 解决微信小程序TypeError
  8. 经验:如何快速地写出格雷码
  9. 电脑重装系统后,在连接网络的小图标上出现红叉,并且只有一个飞行模式,未出现wlan的解决思路
  10. 智能家居创意产品一智能插座