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.指 ...
随机推荐
- read/write/fsync与fread/fwrite/fflush的关系和区别
read/write/fsync: 1. linux底层操作: 2. 内核调用, 涉及到进程上下文的切换,即用户态到核心态的转换,这是个比较消耗性能的操作. fread/fwrite/fflush: ...
- 什么是 MVC ?
本篇博客打算简单介绍一下MVC是什么,为接下来MVC的学习做一下铺垫. MVC是一种架构设计模式,是一种设计理念.是为了达到分层设计的目的,从而使代码解耦,便于维护和代码的复用.MVC是3个单词的缩写 ...
- SVN专题(Visual SVN Server + TortoiseSVN + Visual SVN)
参考资料: 1.Windows环境下搭建SVN服务器.原文地址:https://blog.csdn.net/lu1024188315/article/details/74082227 2.Git|SV ...
- Django学习---自定义分页
自定义分页 简单例子: urls.py: from django.contrib import admin from django.urls import path from django.conf. ...
- mongodb主从复制 副本集(六)
主从复制副本集 8888.conf dbpath = D:\software\MongoDBDATA\07\8888 #主数据库地址port = 8888 #主数据库端口号bind_ip = 127. ...
- 使用ssh client与bash scripts轻松管理多台主机
当我们需要控制一个局域网中的很多台服务器时,一个简单的全局操作可能会被放大地异常繁琐,这时我们就会需要新的工具来快速完成这种工作. 我们将使用ssh客户端提供的一些工具来快速完成这一开发工作,我们的开 ...
- Delphi IOS class_addMethod
class_addMethod 学习FMX.Platform.iOS.pas文件的处理办法 d:\program files (x86)\embarcadero\studio\17.0\source\ ...
- bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form
bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form
- sql常用优化
最近因工作需要,查找资料整理了一下sql的常见优化,具体如下: 1.尽量避免全表扫描,一般在where或order by 涉及的列上建立索引: 2.尽量避免在where子句中对索引字段进行null值判 ...
- angular.module方法
关于module的定义为:angular.module(‘com.ngbook.demo’, []).关于module函数可以传递3个参数,它们分别为: name:模块定义的名称,它应该是一个唯一的必 ...