博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 1430 Crime and Punishment
阅读量:5217 次
发布时间:2019-06-14

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

Crime and Punishment

Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

 

Description

Background

Petty bureaucrat Victor Thiefton was disposed towards stealing from his childhood. But one thing is to legally privatize national factories, diamond fields and oil derricks at the cost of billions dollars. And another thing is to filch some money from a poor regional budget. Our legislation is very strict. Therefore Victor felt that justice is on the alert just after he extracted his hand from the national pocket. What should he do to escape inevitable punishment?

Mr. Thiefton has once heard that in accordance with the criminal legislation standards he would be condemned to long imprisonment for a theft whereas in case of a peculation he could escape with a suspended sentence only. So if the most part of stolen money is peculated, the duration of imprisonment will be reduced.

Problem

The same evening Mr. Thiefton burst into "MegaApril" superstore and rushed for overflowing storefronts carrying a purse with N stolen dollars. It appeared that unlimited number of high-quality goods and goods at moderate price were on sale in the superstore. High-quality goods cost A dollars per piece, and goods at moderate price cost B dollars per piece. Victor should spend as much stolen money as possible to reduce the duration of imprisonment to a minimum.

Input

The only line contains the integer numbers A, B and N (1 ≤ A, B, N ≤ 2∙109).

Output

You should output the number of high-quality goods and the number of goods at moderate price, which should be bought to guarantee the minimal duration of imprisonment for Victor. The numbers should be separated by single space. If the problem has several solutions, you should output any of them.

Sample Input

input

output

8 5 22
2 1
 
一下东西都是摘抄的,囧
 
题目大意:给出a,b,N,要你找出自然数x,y满足:N-(a*x+b*y)最小,如果有多组解是,输出任意一组。
::做法貌似是暴力加贪心。
view code#include 
#include
using namespace std;int main(){ int a, b, n; scanf("%d%d%d", &a, &b, &n); int flag = 0; if(a < b) swap(a,b), flag = 1; int x = n / a; n %= a; int y = n / b; n %= b; int ans = n, ansx = x, ansy = y; for(int i = 1, end = min(x,b); i <= end; i++){
// 如果有 n / a > b时,那么一定会枚举都某个i,i = (b + x),那么 a * (b + x) = a * b + a * x,那么b个a就可以用a个b来表示 x--, n += a, y += n / b, n %= b; if(n < ans) ans = n, ansx = x, ansy = y; } if(flag) swap(ansx, ansy); printf("%d %d\n", ansx, ansy); return 0;}

转载于:https://www.cnblogs.com/zyx1314/p/3890001.html

你可能感兴趣的文章
18款在线代码片段测试工具
查看>>
20.C++- &&,||逻辑重载操作符的缺陷、,逗号重载操作符的分析
查看>>
静态变量数组实现LRU算法
查看>>
在SQL中怎么把一列字符串拆分为多列
查看>>
中文系统 上传file的input显示英文
查看>>
css样式写一个三角形
查看>>
比callback更简洁的链式执行promise
查看>>
android permission
查看>>
javascript获取textarea中所选文本的开始位置、结束位置和选择的文本
查看>>
【译】在Asp.Net中操作PDF - iTextSharp - 使用字体
查看>>
事务备份还原分离附加
查看>>
JSch - Java实现的SFTP(文件上传详解篇)
查看>>
一些注意点
查看>>
.net 文本框只允许输入XX,(正则表达式)
查看>>
C#修饰符
查看>>
20.核心初始化之异常向量表
查看>>
[BSGS][哈希]luogu P3846 可爱的质数
查看>>
Python 第四十五章 MySQL 内容回顾
查看>>
iostat参数说明
查看>>
js 封装获取元素的第一个元素
查看>>