URAL 1430 Crime and Punishment
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 <cstdio>
#include <iostream> 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;
}
URAL 1430 Crime and Punishment的更多相关文章
- URAL 1430. Crime and Punishment(数论)
题目链接 题意 :给你a,b,n,让你找出两个数x,y,使得n-(a*x+b*y)最小. 思路 : 分大小做,然后枚举a的倍数 #include <stdio.h> #include &l ...
- 1430. Crime and Punishment(枚举)
1430 即使是枚举 也是有一定技术含量的 对于ax+by = n: 枚举max(a,b)中的系数 这样可以确定另一个 但问题是如何确定上限 假设max(a,b) = a,很显然是不会超n/a的 但这 ...
- Elasticsearch查询
Elasticsearch支持两种类型的查询:基本查询和复合查询. 基本查询,如词条查询用于查询实际数据. 复合查询,如布尔查询,可以合并多个查询, 然而,这不是全部.除了这两种类型的查询,你还可以用 ...
- 越狱Season 1-Episode 14: The Rat
Season 1, Episode 14: The Rat -Michael: 24 hours from now, 24小时后 my brother is scheduled to die, sch ...
- SQLite 入门教程(一)基本控制台(终端)命令
一.基本简介 SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所以也可以作为嵌入式数据库内建在你的应用程序中.SQLite 被应 ...
- SQLite 入门教程(一)基本控制台(终端)命令 (转)
转于: SQLite 入门教程(一)基本控制台(终端)命令 一.基本简介 SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所 ...
- ES系列十、ES常用查询API
1.term查询 { "query": { "term": { "title": "crime" } } } 1.1.指 ...
- es简单介绍及使用注意事项
是什么? Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库. El ...
- SQLite 入门教程一 基本控制台(终端)命令
一.基本简介 SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所以也可以作为嵌入式数据库内建在你的应用程序中.SQLite 被应 ...
随机推荐
- js获取url参数的两种方法
js获取参数,在以前我都是用正在去拆分,然后获取,这种方式感觉是最简单的 方式1: function QueryString(item) { var sValue=location.search.ma ...
- CSS3背景渐变属性 linear-gradient(线性渐变)和radial-gradient(径向渐变)
CSS3 Gradient分为linear-gradient(线性渐变)和radial-gradient(径向渐变). 为了更好的应用CSS3 Gradient,我们需要先了解一下目前的几种现代浏览器 ...
- 才知道百度也提供了智能DNS服务 - 加速乐
http://jiasule.baidu.com/ 智能DNS 依托百度多年积累的高精度DNS识别库,平均只需5秒全球DNS服务器全部生效,百度蜘蛛1秒生效.抗攻击.无限解析记录,免费支持电信.联通. ...
- poi excel export 乱码
1. Question Description: ~前端是get方式提交的,参数含有中文“测试” ~导出的excel,文件名正常, 而标题乱码 2. Solution: ~断点发现, 参数接收就是乱码 ...
- Powerbuilder编写身份证校验码
public function boolean of_calc_cardid_verifycode (string as_cardid, ref string as_verifycode); /* 计 ...
- django 中间件
django处理一个Request的过程是首先通过django 中间件,然后再通过默认的URL方式进行的.所以说我们要做的就是在django 中间件这个地方把所有Request拦截住,用我们自己的方式 ...
- webpack常用的插件安装命令
webpack常用的插件安装命令:1:npm install html-webpack-plugin --save-dev //自动快速的帮我们生成HTML.2:npm install css-loa ...
- swift学习笔记之-闭包
//闭包 import UIKit /*闭包(Closures): 函数.闭包.类都是引用类型(引用类型的实例赋值给变量或常量时,得到的都是该实例的引用,而值类型的实例变量得到的是独立的值的拷贝) 1 ...
- ABAP内表(internal table)有关的系统变量
SY-TABIX – 内表当前行的索引号.SY-TABIX 的值可以被以下命令修改,但是只适用于索引表(index table).对于哈希表(Hashed table),这个系统变量的值为空或0. A ...
- Microsoft Dynamics CRM 前瑞开发
做CRM开发最大的感受就是其前瑞开发过程中,调试起来比较麻烦,需要做一些断点还要配制一些浏览器设置,对新手来说比较困难.还有就是对REST调试,经常为了调试一个正确的结果而花费大量的时间.现在推荐一个 ...