牛客挑战赛 41 A

https://ac.nowcoder.com/acm/contest/6012/A

其实这题想的思路是对的,就是代码……好像有点繁杂。后来看了别人的代码,才知道还可以这样。
思路就是尽可能去凑2,如果k是奇数就去补1,如果直接模拟发现会非常麻烦,写着写着会把自己绕进去。但我们可以发现,我们尽可能去凑2,然后补1,但总体的数量还是不变的,所以我们就直接用总体的数量去除k就好了。

#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
int t,n,m,k;
signed main()
{
	cin>>t;
	while(t--)
	{
		scanf("%lld %lld %lld",&n,&m,&k);
		printf("%lld\n",(n+2*m)/k);
	}
 } 

猜你喜欢

转载自blog.csdn.net/qq_37073764/article/details/106866692