B. Astrophysicists

Problem - B - Codeforces

Input

In the first line of input, there is one integer t (1≤t≤10e4) denoting the number of test cases.

Each of the following t lines describes one test case and contains three integers n, k, g (1≤n≤10e9 1≤≤109, 0≤k≤10e9 , 2≤g≤10e9 ) — respectively the number of astrophysicists in the company, total number of gold coins to assign and the number of silver coins that one gold coin corresponds to.

Output

In a separate line for each test case, output a single integer — the maximum number of silver coins that could be saved due to rounding.

 n==物理学家人数,k==金币数量,g==转化概率;

四舍五入程序如下。如果天体物理学家的奖金等于 x银币,我们表示 r=x mod g, 然后:

  • 如果 r≥⌈g/2⌉, 天体物理学家收到 x+(g−r)银币;
  • 否则,天体物理学家会收到 x−r银币。
  • 当 g=10时 g/2==5;即四舍五入;

最后献上图图姐姐代码

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
 
void solve()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k,g;
		cin>>n>>k>>g;
		ll ans=(g-1)/2*n;
		ans=min(ans/g,k);
		cout<<ans*g<<'\n';
	}
}
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值