EVERYTHING HAPPENS FOR THE BES|

wnsyou

园龄:2年4个月粉丝:19关注:16

2023-05-17 19:37阅读: 21评论: 0推荐: 0

CF1183C Computer Game 题解

Computer Game

还算水的一道题。

题意

本题意为题面直接翻译的简化版,可能会比题目翻译要复杂。

q 次询问,每次给出四个数,表示一开始的电亮为 k,有 n 个回合,不插电玩一个回合则电量会减少 a,插电玩一个回合则电量会减少 b,电量在任何时刻都必须 严格大于 0

如果能玩完 n 个回合,输出不插电玩的回合数的最大值;否则输出 1

思路

由于 k 最大为 109,直接模拟肯定是不行的。

那么,这题怎样做呢?

首先,电量消耗最少的方案是每回合都插电玩,一共消耗 n×b 的电量,只有当 k 严格大于 它时才能玩完所有回合,否则就可以输出 1

如果在玩某一个回合时把电拔了,那么就要多用 ab 的电量。

要保证能玩完所有回合,可以用来自由分配的电量就只有 kn×b1,知道了这个,答案也可以很快地推出来了。

可以不插电玩的回合数的公式为:kn×b1ab

由于总共只有 n 个回合,所以答案是不能超过 n 的,正确答案公式为 min(kn×b1ab,n)

要开 long long

Code

点击查看代码
#include <bits/stdc++.h>
using namespace std;
long long q, n, k, a, b;
int main() {
for (cin >> q; q; q--) {
cin >> k >> n >> a >> b;
if (k <= n * b) { // 玩都玩不完
cout << -1;
} else {
cout << min(n, (k - n * b - 1) / (a - b)); // 套上公式即可
}
cout << '\n';
}
return 0;
}

本文作者:wnsyou の blog

本文链接:https://www.cnblogs.com/wnsyou-blog/p/17409914.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   wnsyou  阅读(21)  评论(0编辑  收藏  举报
  1. 1 勝利への道 安藤浩和
  2. 2 Minecraft’s End Eric Fullerton
  3. 3 月光曲完整版 贝多芬 云熙音乐
  4. 4 平凡之路 (Live版) 朴树
  5. 5 Minecraft C418
  6. 6 Paradise NiziU
  7. 7 叫我,灰原哀 龙大人不喷火
  8. 8 心机之蛙,一直摸你肚子 ——《名侦探柯南》原创同人曲 炊饭,叶辞樱,温海,寒砧,南柯柯,小茜玛姬,盛姝,阿崔Ac,贝壳初,千湛,兮茶子DaYu,乔慕,黎鹿北,起千温卿,遮阳伞,曲悠
  9. 9 战 歌 此去经年
Minecraft’s End - Eric Fullerton
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

I see the player you mean.

It is reading our thoughts as though they were words on a screen.

They used to hear voices.

Before players could read.

Sometimes disturbing.

Sometimes beautiful indeed.

Does it know that we love it?

That the universe is kind?

A million years ago,it still works

in the reality behind

and the universe said I love you

and the universe said you are the daylight

and the universe said you are not alone

and the universe said you are the night

Once we were called

the spirit of the mountain.

WHO ARE WE

Father sun

Mother moon

Gods demons angels aliens

the player,too.

WE ARE THE UNIVERSE.

We are EVERYTHING you think isn‘t you.

You are alive

ON A FLAT

INFINITE WORLD

generated by a source code

a million years old

and the universe said I love you

and the universe said you are the daylight

and the universe said you are not alone

and the universe said you are the night

Take a breath,now

Take another

Feel air in your lungs.

dreamed it was lost in a story.

and the game was over

Wake up.

加载中…

{{tag.name}}

{{tran.text}}{{tran.sub}}
无对应文字
有可能是
{{input}}
尚未录入,我来提交对应文字
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示