博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #567 (Div. 2)A
阅读量:4595 次
发布时间:2019-06-09

本文共 2601 字,大约阅读时间需要 8 分钟。

A. Chunga-Changa

题目链接:

题目

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 z
chizhiks per coconut. Sasha has x chizhiks, Masha has y
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 5
chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1+1=2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2+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).
Input
The first line contains three integers x, y and z (0≤x,y≤10^18, 1≤z≤10^18) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
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.
Examples
Input
Copy
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
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=7
coconuts.

题意

两个人各有一定数量的钱,求在两个人的钱混合在一起能买多少个物品和其中一个人要给另一个人最小的钱数来买到这么多物品。
 

思路

两人钱数相加除以单价即为购买物品个数,每个人的钱数模单价减去单价的绝对值即为其中一个人要给另一个人的钱数。
 
 
//// Created by hjy on 19-6-5.//#include
using namespace std;const int maxn = 2e5 + 10;typedef long long ll;int main(){ ll a,b,c; while(cin>>a>>b>>c) { ll result=(a+b)/c; if((a/c)+(b/c)==result) cout<
<<' '<<0<

 

转载于:https://www.cnblogs.com/Vampire6/p/11048500.html

你可能感兴趣的文章
关于R软件的安装
查看>>
MySQL数据库免安装版配置
查看>>
你必知必会的SQL面试题
查看>>
html5 Canvas绘制时钟以及绘制运动的圆
查看>>
Unity3D热更新之LuaFramework篇[05]--Lua脚本调用c#以及如何在Lua中使用Dotween
查看>>
JavaScript空判断
查看>>
洛谷 P1439 【模板】最长公共子序列(DP,LIS?)
查看>>
python timeit
查看>>
Wireless Network 并查集
查看>>
51nod 1019 逆序数
查看>>
rtmpdump代码分析 转
查看>>
20145202马超《JAVA》预备作业1
查看>>
[导入]参考OpenSceneGraph的3ds插件学习lib3ds
查看>>
java基础-四大特征
查看>>
linux文档查看器
查看>>
如何使用 ccs7.2调试代码
查看>>
2016.8.22 Axure两级下拉框联动的实现
查看>>
C#集合类:动态数组、队列、栈、哈希表、字典(转)
查看>>
基于bootstrap 的datatable插件的使用(php版)
查看>>
展示图片的自动和手动切换
查看>>