1018 ACM-ICPC 青岛赛区网络赛-J Press the Button(瞎搞)

BaoBao and DreamGrid are playing a game using a strange button. This button is attached to an LED light (the light is initially off), a counter and a timer and functions as follows:

  • When the button is pressed, the timer is set to (v+0.5) seconds (no matter what the value of the timer is before the button is pressed), where v is a given integer, and starts counting down;
  • When the button is pressed with the LED light off, the LED light will be lit up;
  • When the button is pressed with the LED light on, the value of the counter will be increased by 1;
  • When the timer counts down to 0, the LED light goes out (that is to say, the light is off).

During the game, BaoBao and DreamGrid will press the button periodically. If the current real time (that is to say, the time elapsed after the game starts, NOT the value of the timer) in seconds is an integer and is a multiple of a given integer a, BaoBao will immediately press the button b times; If the current time in seconds is an integer and is a multiple of another given integer c, DreamGrid will immediately press the button d times.

Note that

  • 0 is a multiple of every integer;
  • Both BaoBao and DreamGrid are good at pressing the button, so it takes no time for them to finish pressing;
  • If BaoBao and DreamGrid are scheduled to press the button at the same second, DreamGrid will begin pressing the button d times after BaoBao finishes pressing the button b times.

The game starts at 0 second and ends after t seconds (if the button will be pressed at t seconds, the game will end after the button is pressed). What's the value of the counter when the game ends?

Input

There are multiple test cases. The first line of the input contains an integer T (about 100), indicating the number of test cases. For each test case:

The first and only line contains six integers abcdv and t (1≤a,b,c,d≤10​6​​, 1≤v,t≤10​12​​). Their meanings are described above.

Output

For each test case output one line containing one integer, indicating the value of the counter when the game ends.

Sample Input

2
8 2 5 1 2 18
10 2 5 1 2 10

Sample Output

6
4

Hint

We now explain the first sample test case.

  • 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.

作者: 浙江大学竞赛命题组

单位: ACMICPC

时间限制: 1000 ms

内存限制: 128 MB

代码长度限制: 32 KB

 

题解:因为a和c只有1e6这么大,因此我们考虑暴力a和c的所有倍数,并从小到大保存下来,这些时间点是要按按钮的时间点,我们可以考虑值暴力a和c的最小公倍数内的答案,然后由总时间t得出总共的,多余的再爆力一遍就好了,然后剩下的问题就是去除呢些需要开灯耗费的次数,因为他们对答案是不产生贡献的,这是之前的排序就起上作用了,简单判断一下就好啦。

#include<vector>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define maxn 100005
#define ll long long
ll a,b,c,d,t,v,ans;
vector<ll>q;
ll gcd(ll a,ll b)
{
	if(a%b==0)
		return b;
	return gcd(b,a%b);
}
int main(void)
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ll ans=0,last=0;
		while(q.empty()==0) 
			q.pop_back();
		scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&v,&t);
		ll tmp=gcd(a,c);tmp=a*c/tmp;
		if(t>=tmp)
		{
			q.push_back(0);
			for(ll i=a;i<tmp;i+=a)
				q.push_back(i),ans+=b;
			for(ll i=c;i<tmp;i+=c)
				q.push_back(i),ans+=d;
			q.push_back(tmp);
			sort(q.begin(),q.end());
			for(ll i=1;i<q.size();i++)
				if(q[i]-q[i-1]>v)
					ans--;
			ans+=b+d;
			ll num=t/tmp; ans=ans*num;
			last=tmp*num;
			//printf("%lld\n",ans);
			ans+=b+d-1;
		}
		//printf("%lld\n",ans);
		while(q.empty()==0) 
			q.pop_back();
		tmp=t%tmp;q.push_back(0);
		for(ll i=a;i<=tmp;i+=a)
			q.push_back(i),ans+=b;
		for(ll i=c;i<=tmp;i+=c)
			q.push_back(i),ans+=d;
		sort(q.begin(),q.end());
		for(ll i=1;i<q.size();i++)
			if(q[i]-q[i-1]>v)
				ans--;
		//printf("%lld\n",ans);
		if(last==0) ans+=b+d-1;
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1
1 1 1 2 3 3 
*/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值