CF1181A Chunga-Changa (#数学)

题意翻译

wqy和他的同学要去买糖果。他有xxRMB,他同学有yyRMB,而一块糖果要zzRMB。他们想买尽可能多的糖果。

如果他们分开买,那么有可能不能买到最多的糖果。而如果其中一个人给另一个人一些RMB,那么就有可能买到更多的糖果。

比如wqy有55RMB,他同学有44RMB,一块糖果要33RMB,那么分开买只能买1+1=21+1=2块,而如果他同学给她11RMB,那么就可以买2+1=32+1=3块糖果。

现在你要求出,他们最多能买多少糖果,在这种情况下,其中一个人最少要给另一个人多少RMB。

题目描述

Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.

Sasha and Masha are about to buy some coconuts which are sold at price zz chizhiks per coconut. Sasha has xx chizhiks, Masha has yy chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.

The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.

Consider the following example. Suppose Sasha has 55 chizhiks, Masha has 44 chizhiks, and the price for one coconut be 33 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 21+1=2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 66 chizhiks, Masha will have 33 chizhiks, and the girls will buy 2 + 1 = 32+1=3 coconuts.

It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).

输入输出格式

输入格式:

The first line contains three integers xx , yy and zz ( 0 \le x, y \le 10^{18}0≤x,y≤1018 , 1 \le z \le 10^{18}1≤z≤1018 ) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.

输出格式:

Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.

输入输出样例

输入样例#1

5 4 3

输出样例#1

3 1

输入样例#2

6 8 2

输出样例#2

7 0

说明

The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 73+4=7 coconuts.


思路

昨天那道蓝题够呛。。还是刷简单点的题找回感觉吧..

数学题,首先最大值肯定是(x+y)/z,至于怎么移,就把x和y分别对z取余。谁余数小,谁就往余数大的移。这样能使移动次数最少。

#include <stdio.h>
#include <iostream>
using namespace std;
long long int x,y,z,minx; 
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	register long long int i,a,b,c;
	cin>>x>>y>>z;
	a=x%z;//实际意义是x买了z以后剩余的钱数 
	b=y%z;//同理 
	if(a+b>=z)//如果两个剩余的钱数还能够再买 
	{
		if(a>b)//谁余数小就给谁移 
		{
			minx=z-a;
		}
		else
		{
			minx=z-b;
		}
	}
	cout<<(x+y)/z<<' '<<minx<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值