Best coder 52div21001Victor and Machine
来源:互联网 发布:基于单片机音乐播放器 编辑:程序博客网 时间:2024/05/17 23:23
题意:一个机器 ,每经过w秒就会弹出一个球,但是机器有缺陷,每工作x秒后就会停止工作y秒。 在每次机器启动的瞬间,机器会首先弹出一个球。输入,x, y, w 求弹出第n 个球时所用的时间??
思路:刚开始我做的时候是推的公式,但由于思路不正确,一直想不通,后来学长说简单模拟可以过,虽然敲出来代码测试数据是对,交上去wrong了,很桑心,又推公式,终A。
下面是正确思路:把零时刻弹出球在n中减去,因为没有用时间,然后每次机器启动的瞬间要把球数加1,(我们可以把这个球数加1 想成每次工作修整时间结束的瞬间球数 +1,这样便于理解),然后在x+y时间内出球数是: x/w+1 ;这样一直循环到,当最后 一个球弹出所在的x工作时间前,一共循环了(n-1)/( x/w+1 ); 这样(n- 1 )%( x/w+1 )
就是剩下所要弹出的球,这下球弹出的时间肯定是在x的工作时间内(注意),且每弹出球的时间用时为w!这样总时间就是:(n-1)/( x/w+1 )*(x+y)+(n-1)%( x/w+1 )*w;
这是第一道在best coder上做题,虽然当时没有提交上,因为超出时间了。但是自己推完公式去看了题解,发现自己公式和题解一样,也是小小的开心了下,去看了看别人的代码,发现还是公式代码简单啊。好,下面是代码:
#include <stdio.h>int main(){ int x,y,w,n; while(scanf("%d%d%d%d",&x,&y,&w,&n)!=EOF) { n--;int sum=(n/(x/w+1)*(x+y))+n%(x/w+1)*w; printf("%d\n",sum); } return 0;}
0 0
- Best coder 52div21001Victor and Machine
- Best Coder Lotus and Characters
- Who do you think is the best coder and why?
- The Best Coder and Why? (最牛气的程序员)
- Who do you think is the best coder, and why?”
- Who do you think is the best coder, and why?
- The Best Coder and Why? (最牛气的程序员) .
- 【Best Coder 】 32 B Negative and Positive (NP)
- 【Best Coder】Baby Ming and phone number(水)
- 【Best Coder】Baby Ming and Weight lifting(水)
- best coder 第六场
- best coder 资格赛D
- zz"Who do you think is the best coder, and why?"zz
- best coder #17 1002 Select
- 【Best Coder】Go to movies
- 【Best Coder】#36 C tree
- Best Coder Matrix(数学)
- Best Coder MG loves gold
- Win32 中的字符集
- 机房收费系统—项目开发总结报告
- http请求报文详解
- 正则表达式详解及应用
- 黑马程序员——java基础—面向对象
- Best coder 52div21001Victor and Machine
- sort 与Qsort 排序
- 一个通用的把矩阵写入txt文件
- JavaScript正则表达式详解
- 读取9columns文件生成几个columns的文件。
- 第二节:springmvc传值方式
- Andriod学习系列之(四)Intent初涉
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) B. Order Book
- 抠火焰,介绍几种实用的抠黑色背景火焰素材的方法