zoj 4056


- At 0 second, the LED light is initially off. After BaoBao presses the button 2 times, the LED light turns on and the value of the counter changes to 1. The value of the timer is also set to 2.5 seconds. After DreamGrid presses the button 1 time, the value of the counter changes to 2. 
- At 2.5 seconds, the timer counts down to 0 and the LED light is off. 
- At 5 seconds, after DreamGrid presses the button 1 time, the LED light is on, and the value of the timer is set to 2.5 seconds. 
- At 7.5 seconds, the timer counts down to 0 and the LED light is off. 
- At 8 seconds, after BaoBao presses the button 2 times, the LED light is on, the value of the counter changes to 3, and the value of the timer is set to 2.5 seconds. 
- At 10 seconds, after DreamGrid presses the button 1 time, the value of the counter changes to 4, and the value of the timer is changed from 0.5 seconds to 2.5 seconds. 
- At 12.5 seconds, the timer counts down to 0 and the LED light is off. 
- At 15 seconds, after DreamGrid presses the button 1 time, the LED light is on, and the value of the timer is set to 2.5 seconds. 
- At 16 seconds, after BaoBao presses the button 2 times, the value of the counter changes to 6, and the value of the timer is changed from 1.5 seconds to 2.5 seconds. 
- At 18 seconds, the game ends. 
只要遇到a,c的倍数就会按b,d次按钮,若同是a,c的倍数,先a,后c
若按之前为暗,按一次变亮,若按之前为亮,按一次为计数器+1
每次按一下,都会让计时器重新设置为v+0.5(开始倒计时,时间到0,就会变暗)
问[0,t]的时间内,计数器最后为多少。(0为任意数的倍数)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
int T;
ll a,b,c,d,v,t;
ll gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
ll x,y,z,cnt,ans,last;
/*
明显一个最小公倍数为一个周期
0 :单独算
再计算除一个周期的结果*周期数
再加上不满一个周期的结果
*/
int main()
{
scanf("%d",&T);
while(T--){
scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&v,&t);
ans=b+d-;
x=,y=,last=,cnt=;//ans 不用再赋初值了
/* */
z=lcm(a,c);//(a,c) 不是(x,y)
while(x<z||y<z){
if(x+a<=y+c){
x+=a;
if(x<=last+v) cnt++;
cnt+=b-;
last=x;
}
else{
y+=c;
if(y<=last+v) cnt++;
cnt+=d-;
last=y;
} }
ans+=cnt*(t/z);//cnt为一个周期的结果
t%=z;
x=,y=,last=;
while(x+a<=t||y+c<=t){//保证在t的范围内
if(x+a<=y+c){
x+=a;
if(x<=last+v) ans++;
ans+=b-;
last=x;
}
else{
y+=c;
if(y<=last+v) ans++;
ans+=d-;
last=y;
}
}
printf("%lld\n",ans);
}
return ;
}
zoj 4056的更多相关文章
- The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online
		A Live Love DreamGrid is playing the music game Live Love. He has just finished a song consisting of ... 
- ZOJ 3544 / HDU 4056 Draw a Mess( 并查集好题 )
		方法参见:http://blog.acmol.com/?p=751 从最后一个线段开始倒着处理(因为之后的线段不会被它之前的线段覆盖),把这条线段所覆盖的所有线段编号合并到一个集合里,并以最左边线段编 ... 
- ZOJ  People Counting
		第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ... 
- ZOJ 3686 A Simple Tree Problem
		A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ... 
- ZOJ Problem Set - 1394 Polar Explorer
		这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ... 
- ZOJ Problem Set - 1392 The Hardest Problem Ever
		放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ... 
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
		这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ... 
- ZOJ Problem Set - 1006 Do the Untwist
		今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ... 
- ZOJ Problem Set - 1001 A + B Problem
		ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ... 
随机推荐
- 51NOD 区间的价值 V2
			http://www.51nod.com/contest/problem.html#!problemId=1674 因为题目要求的只是& 和 | 这两个运算.而这两个运算产生的值是有限的. & ... 
- 《四 spring源码》利用TransactionManager手写spring的aop
			事务控制分类 编程式事务控制 自己手动控制事务,就叫做编程式事务控制. Jdbc代码: Conn.setAutoCommite(false); // 设置手动控制事务 Hibern ... 
- Column 'xxx' in field list is ambiguous
			一 其实看一下ambiguous的翻译就好了 一开始我觉得是含糊什么的,后来找了下才知道应该是双关... 二 所以翻译过来就是 : 列'XX'在字段列表中双关 其实就是两张表有相同的字段,但是使用时, ... 
- Eclipse - 安装语言包
			Open the install wizard with 'Help' > 'Install new software...' add the Babel p2 repository: http ... 
- LCA 离线做法tarjan
			tarjan(int u) { int v; for(int i=h[u];i;i=nex[i])//搜索边的 { v=to[i]; tarjan(v); marge(u,v); vis[v]=; } ... 
- 7.Solution的Build、Rebuild和Clean
			大家好,我是原文,这篇随笔是对原文的翻译以及自己的体会. 做程序员没追求的话是永远找不到女朋友的,当然有追求也找不到,这个先不提,好在有追求的时候我是充实而且开心的.现在我们的问题是,每天调试项目,在 ... 
- Hybrid框架安全隐患分析
			Hybrid框架安全隐患分析 目前我司移动端项目中各种app如雨后春笋般生根发芽层出不穷.而利用Hybrid框架确实可以减轻一部分移动端压力.并且做到灵活发版.但是其中的安全问题往往让人忽略. 针对A ... 
- (转载)资源字典(Pro WPF 学习)
			原地址:http://www.cnblogs.com/yxhq/archive/2012/07/09/2582508.html 1.创建资源字典 下面是一个资源字典(AppBrushes.xaml), ... 
- HDU 4507 吉哥系列故事——恨7不成妻 (数位DP)
			题意: 如果一个整数符合下面3个条件之一,那么我们就说这个整数和7有关: 1.整数中某一位是7: 2.整数的每一位加起来的和是7的整数倍: 3.这个整数是7的整数倍: 给定一个区间[L,R],问在此区 ... 
- 协议详解3——IP
			1. 特点: 所有的TCP,UDP,ICMP,IGMP数据都以IP数据报格式传输. 提供不可靠,无连接服务. 不可靠: 不能保证IP数据报能成功到达目的.IP仅提供最好的传输服务.如果发生某种错误时 ... 
