Vova is playing a computer game. There are in total nn turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is kk.

During each turn Vova can choose what to do:

  • If the current charge of his laptop battery is strictly greater than aa, Vova can just play, and then the charge of his laptop battery will decrease by aa;
  • if the current charge of his laptop battery is strictly greater than bb (b<ab<a), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by bb;
  • if the current charge of his laptop battery is less than or equal to aa and bb at the same time then Vova cannot do anything and loses the game.

Regardless of Vova's turns the charge of the laptop battery is always decreases.

Vova wants to complete the game (Vova can complete the game if after each of nn turns the charge of the laptop battery is strictly greater than 00). Vova has to play exactly nn turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.

Your task is to find out the maximum possible number of turns Vova can just play(make the first type turn) or report that Vova cannot complete the game.

You have to answer qq independent queries.

Input

The first line of the input contains one integer qq (1≤q≤1051≤q≤105) — the number of queries. Each query is presented by a single line.

The only line of the query contains four integers k,n,ak,n,a and bb (1≤k,n≤109,1≤b<a≤1091≤k,n≤109,1≤b<a≤109) — the initial charge of Vova's laptop battery, the number of turns in the game and values aa and bb, correspondingly.

Output

For each query print one integer: -1 if Vova cannot complete the game or the maximumnumber of turns Vova can just play (make the first type turn) otherwise.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,k,n,a,b;
int main()
{
cin>>q;
while(q--)
{
cin>>k>>n>>a>>b;
ll x;
if((k-b*n)<=) cout<<-<<endl;
else
{ x=(k-n*b)/(a-b);if((k-n*b)%(a-b)==)x--;
cout<<min(x,n)<<endl;
} }
return ;
}

思路分析:提供了电池剩余电量k,要使用轮数n,玩游戏消耗电量a,边充电边玩消耗电量b。先输入查询轮数q。然后输入每轮的k、n、a、b。如果电量减去所有轮数使用b方法消耗电量剩余电量还是小于等于0,就输出-1,代表没有使用a方法,且不能完成n轮任务。否则n轮全用b方法会有剩余电量,设变量x为总电量减去假设n轮全使用b方法消耗后剩余的电量再除以a、b两种电量使用方式之差,如果总电量减去假设n轮全使用b方法消耗后剩余的电量再除以a、b两种电量使用方式的余数为0.x减1.再输出x和n的最小值就是a方式再能完成n轮任务且有电量剩余情况下能使用的最多轮数。

 #include<iostream>
using namespace std;
int main() {
long long q,cnt=-;
bool flag=false;
cin>>q;
long long k[q],n[q],a[q],b[q];
for(long long i=; i<q; i++) {
cin>>k[i]>>n[i]>>a[i]>>b[i];
}
for(int i=; i<q; i++) {
if(k[i]/a[i]>) {
cnt=k[i]/a[i];
} else {
if(b[i]>=k[i]||b[i]*n[i]>=k[i]) {
cout<<-<<endl;
} else {
cout<<<<endl;
}
}
while(cnt>=) {
if(cnt>n[i]) {// 9 17 18 15
cout<<n[i]<<endl;
break;
} else if(cnt<=n[i]) {
if((n[i]-cnt)*b[i]+a[i]*cnt<k[i]) {
cout<<cnt<<endl;
flag==true;
break;
} else {
cnt--;
}
if(cnt==&&(n[i]-cnt)*b[i]>=k[i]) {
cout<<-<<endl;
}
}
}
cnt=-;
}
}

思路分析:先判断剩余电量k除以a方式消耗电量的值为正,再看最多可以使用几次a方式再加上剩余轮数全使用b方式的值要是小于剩余电量就输出使用a的次数cnt,否则将次数减一再进行同样判断。如果b方式消耗值大于剩余电量或者全部轮数使用b方式用电大于剩余电量k就将a的次数输出为-1,若全部轮数使用b方式用电小于等于剩余电量k就将a的次数输出为0。

Codeforces1183C(C题)Computer Game的更多相关文章

  1. hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  2. 水题 HDOJ 4716 A Computer Graphics Problem

    题目传送门 /* 水题:看见x是十的倍数就简单了 */ #include <cstdio> #include <iostream> #include <algorithm ...

  3. HDU 4716 A Computer Graphics Problem (水题)

    A Computer Graphics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  4. UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)

    UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用) 题意分析 绝对的好题. 先说做完此题的收获: 1.对数据结构又有了宏观的上的认识; 2.熟悉了常用STL ...

  5. HDU 3695 Computer Virus on Planet Pandora(AC自动机模版题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  6. hdu 2196 Computer 树形dp模板题

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. HDU 2196 Computer 树形DP 经典题

    给出一棵树,边有权值,求出离每一个节点最远的点的距离 树形DP,经典题 本来这道题是无根树,可以随意选择root, 但是根据输入数据的方式,选择root=1明显可以方便很多. 我们先把边权转化为点权, ...

  8. CodeForces 492D Vanya and Computer Game (思维题)

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. HDU-4716 A Computer Graphics Problem 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4716 直接搞.. //STATUS:C++_AC_0MS_288KB #include <fun ...

随机推荐

  1. 在php中如何实现cookie即时生效,不用刷新就可以使用

    参考:https://www.jianshu.com/p/0468ef5dbf4d 今天在用php设置cookie的时候,发现cookie如果只是赋值一次的话,要手动刷新一下浏览器才能把数据及时更新, ...

  2. 基于centos7搭建kvm

    其他的和安装一般的系统没有差别 安装完成后. 1]使用ping www.baidu.com 2]修改静态ip,也可以不修改 3]下载brctlyum -y install bridge-utils 4 ...

  3. 获取 保存 系统信息 [Windows]

    出处:https://www.technig.com/find-windows-10-system-information/ 在“运行”里,运行 msinfo32. System Informatio ...

  4. [Qt] 文本文件读写, 摘自官方文档

    Reading Files Directly The following example reads a text file line by line: QFile file("in.txt ...

  5. vue与众不同的学习方式,让她年薪200多万

    学习vue正确思路,是先学vue-cli,再学vue.js单文件引用的用法,这样会在极短时间内撤底撑握vue,如果先学vue.js单文件用法,再去学vue-cli4,可以说是重新学vue,,,,难处大 ...

  6. ES6特性之:参数默认值

    作为一个开发者,跟进行业步伐是非常需要的,不能躺在现有的知识和经验温床上做美梦.JavaScript的ES2015标准(即我们说的ES6)在2016年已经被广泛应用了,还没开始使用的朋友,赶紧来磨一下 ...

  7. Eclipse Mac OS 安装中文简体语言包

    打开Eclipse软件,在导航Eclipse下拉菜单中点开 About Eclipse 查看版本 我的是 Eclipse IDE for Enterprise Java Developers. Ver ...

  8. 《LabVIEW 虚拟仪器程序设计从入门到精通(第二版)》一1.3 小结

    本节书摘来自异步社区<LabVIEW 虚拟仪器程序设计从入门到精通(第二版)>一书中的第1章,第1.3节,作者 林静 , 林振宇 , 郑福仁,更多章节内容可以访问云栖社区"异步社 ...

  9. 一张图告诉你UML图怎么画❀

    UML 能帮我们做什么? 我们在进行项目的时候,通过使用 UML 的面向对象图的方式来更明确.清晰的表达项目中的架设思想.项目结构.执行顺序等一些逻辑思维. UML 介绍: 1997年,OMG 组织( ...

  10. FTP服务器项目的一些整理

    几个月前按照网上的教程写了一个FTP的服务器,现在回头整理一下里面的一些知识. FTP简介 FTP是文件传输协议(File Transfer Protocol),工作在TCP/IP协议族的应用层,其传 ...