codeforce div2 educate 82 b National Project

Here Insert Picture Description
Subject to the effect that, now to build roads, more good weather road repair quality, poor weather road backward, alternating between good and bad weather, ask if there are at least half of the section of the road is good, it is up to at least a few days,

This question I just started to think of are classified, if a> b can guarantee a good way certain that more than half (Pre good way because, if a large, it is always much better way than the bad way) in this case does not require downtime the answer is, in fact, if a n n more than half, they do not consider this issue. So I think that if homeopathic B> A when the bad road must be better than a good road, so no need to consider the bad road enough, we only care about the last piece of road is in good repair somewhere, that is, first calculate w well at least the number of road, the last remainder will then ans = (w / a) * (a + b) + (w% a) in any place other than a number with this we can know that when w% a == 0 is a special sentence that is not about to walk the length of a b, but this idea has been to pay up after wa, I changed also unable to move more than an hour, you know after the game I know after reading the data in accordance with the inertia of thinking to consider the issue, since a> b regardless of when the road is not good, I subconsciously think that if b> a, then no need to consider the number of poor road, that is only considered a good way, but in fact not the case because it is finally a go first in a the ultimate time when good weather is more than bad weather, the impact will increase with the number of cycles ab group decreases, but like 823, 1034 are good evidence, so we need to use max the evaluation function to ensure that no comparison with n less floor brush
ac code is as follows

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int t,ans,w;
	long long int n,a,b;
	cin>>t;
	while(t--)
	{ans=0;
	w=0;
		cin>>n>>a>>b;
		if(a>=b||2*a>=n)
		ans=n;
		else 
		{		
		if(n%2==1)w=n/2+1;
		else w=n/2;
		if(w%a==0)ans=max(n,(w/a)*(a+b)-b);   
	    else ans=max(n,(w/a)*(a+b)+(w%a));
	    }
	    printf("%lld\n",ans);
	}
	return 0;
 } 
Published 48 original articles · won praise 17 · views 4466

Guess you like

Origin blog.csdn.net/weixin_45757507/article/details/104290099