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中的数据库操作

    PDO project data object 连接到数据库 $db=new PDO("mysql:dbname=database;host=sever","userna ...

  2. thinkphp5--model数据操作的坑

    最近用thinkphp5开发,经常用到model了来操作数据,但是操作多了,就发现他的坑了. 就好像如果你只是初始化一个model对象,但是你却用这个对象进行多次的数据操作,这时候他的数据就会发生混乱 ...

  3. php时间:获取上一个月,本月天数,下一个月

    时间戳转日期 date() 日期转时间戳 strtotime() 当前时间戳time() 获取当前月的天数: $i=; $y=; echo date("t",strtotime(& ...

  4. zabbix 微信告警机制

    微信告警首先得注册一个企业微信,然后才能实现微信告警.自行百度 微信: 添加一个用户到上面创建的部门里面 创建完成记住 AgentID  和 Secret 下一步:记住企业 ID 1)编辑zabbix ...

  5. Linux 获取网卡名字列表

    lspci | egrep -i --color 'network|ethernet'

  6. Pascal 字符串

    Dancing with Strings http://baskent.edu.tr/~tkaracay/etudio/ders/prg/pascal/PasHTM1/pas/pasl1007.htm ...

  7. [QT] QProcess finished 信号,关联的 slot 必须检查返回码

    void QProcess::finished(int exitCode, QProcess::ExitStatus exitStatus)

  8. python教程(目录)

    很早就想出一套python的零基础入门教程,各种原因一直没动手.今天立个flag,2020年一定完成这个目标. 入门篇 完全零基础的小白应该从这里看起. 一.计算机原理 这里不是要让大家去深入的学习计 ...

  9. (转)如何学好C语言

    原文:http://coolshell.cn/articles/4102.html    作者:陈皓 有人在酷壳的留言版上询问下面的问题 keep_walker : 今天晚上我看到这篇文章. http ...

  10. 使用Spring Boot搭建你的第一个应用程序

    文章目录 依赖配置 main程序配置 MVC配置 安全配置 存储 Web 页面和Controller 异常处理 测试 结论 Spring Boot是Spring平台的约定式的应用框架,使用Spring ...