URAL 1430. Crime and Punishment(数论)
题意 :给你a,b,n,让你找出两个数x,y,使得n-(a*x+b*y)最小。
思路 : 分大小做,然后枚举a的倍数
#include <stdio.h>
#include <string.h>
#include <iostream>
#define LL __int64 using namespace std ; int main()
{
LL a,b,n ;
while(~scanf("%I64d %I64d %I64d",&a,&b,&n))
{
if(a == )
{
printf("%I64d 0\n",n) ;
continue ;
}
if(b == )
{
printf("0 %I64d\n",n) ;
continue ;
}
bool flag = false ;
if(a < b)
{
swap(a,b) ;
flag = true ;
}
LL t = min(n/a,b) ,x;
LL minn = 999999999LL ;
for(int i = ; i <= t ; i++)
{
if((n - a * i) % b < minn)
{
minn = (n - a * i) % b ;
x = i;
}
}
if(!flag) printf("%I64d %I64d\n",x,(n-a*x)/b) ;
else printf("%I64d %I64d\n",(n-a*x)/b,x) ;
}
return ;
}
URAL 1430. Crime and Punishment(数论)的更多相关文章
- URAL 1430 Crime and Punishment
Crime and Punishment Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- 1430. Crime and Punishment(枚举)
1430 即使是枚举 也是有一定技术含量的 对于ax+by = n: 枚举max(a,b)中的系数 这样可以确定另一个 但问题是如何确定上限 假设max(a,b) = a,很显然是不会超n/a的 但这 ...
- URAL 1139 City Blocks(数论)
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...
- ural 1356. Something Easier(数论,哥德巴赫猜想)
1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime num ...
- 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.指 ...
随机推荐
- 20181103_C#线程初探, BeginInvoke_EndInvoke
在C#中学习多线程之前, 必须要深刻的理解委托; 基本上所有的多线程都在靠委托来完成 一. 进程和线程: a) 进程和线程都是计算机的概念, 跟程序语言没有任何关系 b) 进程和线程都属于计算机操 ...
- (转)Docker volume plugin - enabled create local volume on docker host
原文地址:https://hub.docker.com/r/cwspear/docker-local-persist-volume-plugin/ Short Description Create n ...
- java爬虫简单实例
爬虫的实质就是打开网页源代码进行匹配查找,然后获取查找到的结果./** 获取* 将正则规则进行对象的封装. * Pattern p = Pattern.compile("a*b") ...
- mongodb 安装、windows服务、创建用户
http://www.cnblogs.com/best/p/6212807.html 打开MongoDB的安装目录如“C:\Program Files\MongoDB\Server\3.4\bin”, ...
- IOS 后台之长时间任务 beginBackgroundTaskWithExpirationHandler 申请后台十分钟 600秒
10分钟 beginBackgroundTaskWithExpirationHandler,beginBackgroundTaskWithName endBackgroundTask 定义变量 UIB ...
- 我的Linux之路——windows10用WMware安装CentOS6.9 虚拟机详细步骤
出自:http://blog.51cto.com/13438667/2059926 一.安装环境 windows10操作系统物理机VMware Workstation 软件(可以在网上下载)CentO ...
- Redis常用类型数据操作
sortedset: 添加: zadd key score1 member1 score2 member2... zad mysort 90 laosong 100 zhangsan 获得:zsco ...
- 解决SDK未授权问题
问题描述 在启动项目的时候报错了,如下: What went wrong: A problem occurred configuring project ':app'. > You have n ...
- 奶牛易物-Alpha版本测试报告
1.在测试过程中总共发现了多少Bug?每个类别的Bug分别为多少个? a. 修复的bug: 1.mapper接口与mapper.xml文件绑定的问题; 2..配置逆向工程的配置文件的问题; 3.在编码 ...
- Linux实战教学笔记19:Linux相关网络知识梳理
第十九节 Linux相关网络知识梳理 标签(空格分隔): Linux实战教学笔记-陈思齐 一,前言 一个运维有时也要和网络打交道,所以具备最基本的网络知识,对一个运维人员来说是必要的.但,对于我们的工 ...