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. spark2.4.5计算框架中各模块的常用实例

    本项目是使用scala语言给出了spark2.4.5计算框架中各模块的常用实例. 温馨提醒:spark的版本与scala的版本号有严格的对应关系,安装请注意. Spark Core RDD以及Pair ...

  2. Spring Boot @EnableAutoConfiguration和 @Configuration的区别

    Spring Boot @EnableAutoConfiguration和 @Configuration的区别 在Spring Boot中,我们会使用@SpringBootApplication来开启 ...

  3. Ubuntu 之 win10更新ubuntu启动项消失

    问题描述: 昨晚windows更新,今天启动的时候发现启动项没有了,直接进入windows. 解决方案一: 首先进入BIOS看一看是否开启启动项选择,然后再把安全模式(secure boot)关闭(重 ...

  4. 如何装双系统win10下装Ubuntu

    如何装双系统win10下装Ubuntu 第一步 制作启动盘 下载UItraISO软件.下载Ubuntu系统(地址:https://www.ubuntu.com/download).准备一个大于8g的U ...

  5. 从实践出发:微服务布道师告诉你Spring Cloud与Boot他如何选择

    背景 随着公司业务量的飞速发展,平台面临的挑战已经远远大于业务,需求量不断增加,技术人员数量增加,面临的复杂度也大大增加.在这个背景下,平台的技术架构也完成了从传统的单体应用到微服务化的演进. 系统架 ...

  6. MySQL权限原理及删除MySQL的匿名账户

    MySQL权限系统的工作原理 MySQL权限系统通过下面两个阶段进行认证: (1)对连接的用户进行身份认证,合法的用户通过认证,不合法的用户拒绝连接: (2)对通过认证的合法用户赋予相应的权限,用户可 ...

  7. matlab混合编程向导(vc,vb,.net...)

    一.matlab与vc混编  1.通过mcc将matlab的m文件转化为cpp,c文件或dll供vc调用:     这方面的实现推荐精华区Zosco和ljw总结的方法(x-6-1-4-3-1和2)  ...

  8. apache调优技巧之一隐藏apahce版本信息

    如果你的服务器版本信息是这样的,是很 危险的. [root@xinsz63 httpd-2.2.27]# curl -I 192.168.1.38 HTTP/1.1 403 Forbidden Dat ...

  9. WebStorm 2019 3.3 安装及破解教程附汉化教程

    WebStorm2019 3.3 安装及破解教程附加汉化教程 安装包及破解补丁 链接: https://pan.baidu.com/s/19ATTAW3Tsm0huIJSqYChTw 提取码:1ei7 ...

  10. python(open 文件)

    一.open 文件 1.open('file','mode')打开一个文件 file 要打开的文件名,需加路径(除非是在当前目录) mode 文件打开的模式 需要手动关闭 close 2.with o ...