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的更多相关文章

  1. URAL 1430. Crime and Punishment(数论)

    题目链接 题意 :给你a,b,n,让你找出两个数x,y,使得n-(a*x+b*y)最小. 思路 : 分大小做,然后枚举a的倍数 #include <stdio.h> #include &l ...

  2. 1430. Crime and Punishment(枚举)

    1430 即使是枚举 也是有一定技术含量的 对于ax+by = n: 枚举max(a,b)中的系数 这样可以确定另一个 但问题是如何确定上限 假设max(a,b) = a,很显然是不会超n/a的 但这 ...

  3. Elasticsearch查询

    Elasticsearch支持两种类型的查询:基本查询和复合查询. 基本查询,如词条查询用于查询实际数据. 复合查询,如布尔查询,可以合并多个查询, 然而,这不是全部.除了这两种类型的查询,你还可以用 ...

  4. 越狱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 ...

  5. SQLite 入门教程(一)基本控制台(终端)命令

    一.基本简介 SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所以也可以作为嵌入式数据库内建在你的应用程序中.SQLite 被应 ...

  6. SQLite 入门教程(一)基本控制台(终端)命令 (转)

    转于: SQLite 入门教程(一)基本控制台(终端)命令 一.基本简介   SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所 ...

  7. ES系列十、ES常用查询API

    1.term查询 { "query": { "term": { "title": "crime" } } } 1.1.指 ...

  8. es简单介绍及使用注意事项

    是什么? Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库. El ...

  9. SQLite 入门教程一 基本控制台(终端)命令

    一.基本简介 SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所以也可以作为嵌入式数据库内建在你的应用程序中.SQLite 被应 ...

随机推荐

  1. C#中得到两个数百分比 (转)

    //此方法得到的百分比后小数太多,不行double percent=Convert.ToDouble(2)/Convert.ToDouble(34); string result=(percent*1 ...

  2. mis导入器的加强版——vdproj文件资源浏览器

    上次做的那个导入器不够强大,限制还不小,用起来不方便.于是就再做一个这样的工具.代码基本上不同了,思想还是差不多,但功能肯定比之前的强大.经过了这次编写工具,对vdporj文件的了解又深一层了. 在v ...

  3. EF工作中踩过的坑.

    1.EF同一个linq里边不支持两个或两个以上不同dbcontext的使用,必须拆解开才能使用; ef也不支持自定义集合和dbcontext属性的混合使用. 2.如果要用用统一域账号连接databas ...

  4. Fluent NHibernate example

    http://www.codeproject.com/Articles/26466/Dependency-Injection-using-Spring-NET http://stackoverflow ...

  5. jxl导出Excel文件

    一.java项目实现读取Excel文件和导出Excel文件 实现读取和导出Excel文件的代码: package servlet; import java.io.FileInputStream; im ...

  6. 四、MyBatis主配置文件

    //备注:该博客引自:http://limingnihao.iteye.com/blog/1060764 在定义sqlSessionFactory时需要指定MyBatis主配置文件: Xml代码 收藏 ...

  7. Linux Shell系列教程之(十二)Shell until循环

    本文是Linux Shell系列教程的第(十二)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上两篇文章Linux Shell系列教程之(十)Shell for循环和Lin ...

  8. Hibernate之映射文件中索引及约束的使用

    1.添加索引: 在一对多的关系中,在多的一方会产生一个外键,这个外键没有自动 添加索引,当存在从一的一端产生对多的一端的查询时,有可能会在多的一端造成全表查询问题,数据量巨大时会产生严重的性能问题.可 ...

  9. ASP.NET Web API获取Model元数据

    using System; using System.Web.Http; using Common; namespace ConsoleApp { internal class Program { p ...

  10. SilverLight MD5加密

    效果体验:http://keleyi.com/tool/md5.htm 嵌入页面的代码: <div style="width:400px;height:230px"> ...