链接:http://acm.timus.ru/problem.aspx?space=1&num=1430

题目:

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.

题意:数字abc,求n*a+m*b最大且n*a+m*b<=c的n和m(任意)

分析:数论内容(最大公约数最小公倍数),也可暴力求解

题解:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;int gcd(int a,int b)
{return (b)?gcd(b,a%b):a;
}int main()
{int a,b,n,g,t,res,x,y;scanf("%d %d %d",&a,&b,&n);bool flag=false;if(a<b){swap(a,b);flag=true;}g=gcd(a,b);n/=g;a/=g;b/=g;t=n/a;res=n;x=y=0;for(int i=0;i<=t;++i){if(res>(n-i*a)%b){x=i;y=(n-i*a)/b;res=n-x*a-y*b;if(res==0)break;}}if(flag)printf("%d %d\n",y,x);elseprintf("%d %d\n",x,y);return 0;
}

Crime and Punishment相关推荐

  1. elasticsearch查询

    1.查询方式 有两种查询方式,一种是通过在url中指定查询条件 ,另外一种是通过DSL查询.都是使用GET方法 1.1 分页查询 from 指定从文档的什么位置开始,默认值0 size 指定一次查询返 ...

  2. 【全文搜索引擎】Elasticsearch基本查询基础JavaAPI

    操作索引 ElasticSearch存储数据的地方,可以理解成关系型数据库中的数据库概念. 添加索引 PUT http://ip:端口/索引名称Kibana操作 --- PUT 索引名称 查询索引 G ...

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

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

  4. 如何将不同类型数据导入Elaticsearch中?

    Elaticsearch的原理明白了以后,手头有很多不同类型的数据,如:  1)单条数据,如程序中自己构造的JSON格式数据:  2)符合Elasticsearch索引规范的批量数据:  3)日志文件 ...

  5. ES查询-基本查询续

    为什么80%的码农都做不了架构师?>>>    1.标示符查询 用来提供标示符过滤文档. 下面查询只返回含有value数组中一个标示符的文档. {"query" ...

  6. 如何在SQL Server 2017中实现图形数据库

    介绍 (Introduction) Graph database 图形数据库 A graph database is a type of database whose concept is based ...

  7. montypython买火柴_python nltk 笔记(持续更新)

    1 基础对象与方法 1.1 nltk.text.Text >>> from nltk.book import * *** Introductory Examples for the ...

  8. 【转】100本最棒的英文侦探小说

    阅读计划2:100本最棒的英文侦探小说 2010-08-15 13:21:28 The Top 100 Crime Novels of All Time The Top 100 Crime Novel ...

  9. 朱光潜给青年的十二封信 之 谈读书

    一.谈读书 朋友: 中学课程很多,你自然没有许多时间去读课外书.但是你试抚心自问:你每天真抽不出一点钟或半点钟的功夫么?如果你每天能抽出半点钟,你每天至少可以读三四页,每月可以读一百页,到了一年也就可 ...

  10. 【书单】100部世界名著

    Top 100 Works in World Literature Source: Norwegian Book Clubs, with the Norwegian Nobel Institute, ...

最新文章

  1. mysql5.6 thread pool_mysql5.6 thread pool
  2. 清华张钹院士、人大文继荣院长展开激情辩论:人类对AI的爱痴忧惧
  3. 比特币现金被3.1万多家餐厅接受
  4. wxWidgets:操作档案manipulate archives的示例应用程序
  5. Java SSM篇3——Mybatis
  6. ora错误匹配java_上周上线碰见的ORA-00054错误回放
  7. 【推荐实践】阿里飞猪“猜你喜欢”推荐排序实践
  8. C++ 命名空间(namespace)
  9. C/C++[codeup 5901]回文串
  10. Hexo + GitHub搭建个人博客 --- Standard Edition
  11. html可视化编辑器 mac,Sparkle For Mac v2.8.11 强大的可视化网页编辑设计工具 _ 黑苹果乐园...
  12. idea安装教程(不是jdr包哦)
  13. 大唐凌烟阁开国廿四将
  14. 首发:最新CPU漏洞Meltdown详细分析
  15. 【转载】超简单集成HMS ML Kit 人脸检测实现可爱2D贴纸
  16. python修改电脑桌面壁纸_python设置windows桌面壁纸的方法
  17. PyGmae:有限状态机实践(十三)
  18. 【JAVA程序设计】(C00101)基于Servlet的在线鞋店销售管理系统
  19. 高校bbs或者科研论坛paperpass
  20. 使用C#开发了一套收银软件

热门文章

  1. Unity-TextMeshPro如何扩展材质实现字体Face+Outline流光效果
  2. 2020年美国新冠肺炎疫情数据分析
  3. 小米台灯突然自己亮了_除了彩屏和小爱,还有哪些升级?——小米手环4 NFC版...
  4. 百度AI开放平台[Python]
  5. SWUST OJ533你的QQ多少级了?
  6. 获取mp3部分信息的python代码
  7. 专利与论文-1:为什么要写专利?专利有什么好处?
  8. 【深度好文】谈谈你对MyBatis的理解
  9. 《吊打分析师》实战—深圳链家租房数据分析 | 附源码
  10. C语言OJ1116,9度OJ 题目1116:加减乘除