1430. Crime and Punishment(枚举)
即使是枚举 也是有一定技术含量的 对于ax+by = n; 枚举max(a,b)中的系数 这样可以确定另一个 但问题是如何确定上限 假设max(a,b) = a,很显然是不会超n/a的 但这样还是会超时的
可以设想一下假如x比b大 那么它可以拆分为x'+b吧 那把b合并y那里就好了 很明显也是不会超过b的 这样复杂度就不会超过sqrt(n)
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define LL long long
int main()
{
LL a,b,n,i;
while(cin>>a>>b>>n)
{
int aa = a,bb = b;
if(n%a==)
cout<<n/a<<" "<<"0\n";
else if(n%b==)
cout<<"0 "<<n/b<<endl;
else if(a==b)
{
printf("%lld %d\n",n/a,);
}
else
{
LL t;
if(a<b){t = a;a = b;b = t;}
int minz = n+,x,y;
for(i = ; i <= min(n/a,b) ; i++)
{
int o = (n-a*i)%b;
if(o<minz)
{
minz = o;
x = i;
y = (n-a*i)/b;
}
if(o==) break;
}
if(aa>bb)
cout<<x<<" "<<y<<endl;
else
cout<<y<<" "<<x<<endl;
}
}
return ;
}
1430. Crime and Punishment(枚举)的更多相关文章
- URAL 1430 Crime and Punishment
Crime and Punishment Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- URAL 1430. Crime and Punishment(数论)
题目链接 题意 :给你a,b,n,让你找出两个数x,y,使得n-(a*x+b*y)最小. 思路 : 分大小做,然后枚举a的倍数 #include <stdio.h> #include &l ...
- 第02章 查询DSL进阶
本章内容 Lucene默认评分公式是如何工作的. 什么是查询重写. 查询二次评分是如何工作的. 如何在单次请求中实现批量准实时读取操作. 如何在单次请求中发送多个查询. 如何对包括嵌套文档和多值字段的 ...
- 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 ...
随机推荐
- [geeksforgeeks] Convert a given Binary Tree to Doubly Linked List
http://www.geeksforgeeks.org/in-place-convert-a-given-binary-tree-to-doubly-linked-list/ Given a Bin ...
- IE如何兼容placeholder属性
在前端开发中,经常需要为input设置placeholder属性,但是placeholder是HTML5新属性,在IE10以下不兼容,那么如何完美兼容呢? 网上搜索了一下,其实也挺简单的,可以采用以下 ...
- Error Code: 1175 Mysql中更新或删除时报错(未带关键字条件)
SET SQL_SAFE_UPDATES = 0; SQL_SAFE_UPDATES = {0 | 1} 如果设置为0,则MySQL会放弃在WHERE子句或LIMIT子句中不使用关键字的UPDATE或 ...
- 初识IOS
编译环境: ssh cloud@10.0.4.148 mx-cloud 1.关于ARM架构 IPHONE上的ARM-CPU架构在不断的进化过程中,目前情况如下: ARMv8 / ARM64 = iP ...
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- POJ 2080
import java.util.*; public class Main { public static void main(String args[]){ Scanner cin=new Scan ...
- 2013 ACM/ICPC Asia Regional Changsha Online - C Color Representation Conversion
这个纯粹是一个细节题啊!!! 由于某个地方的浮点数比较写错了,WA了无数次啊…… 代码如下: #include<iostream> #include<cstdio> #incl ...
- MyEclipse — Maven+Spring+Struts+Hibernate 整合 [学习笔记-2]
引入Spring 修改 pox.xml 文件 添加jar包引用 <!-- spring3 --> <dependency> <groupId>org.springf ...
- C#中out的用法
out的用法 out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数,方法定义和调用方法都必须显式使用 out ...
- C#格式化输出
double a = 12354.365; Console.WriteLine(string.Format("{0:f4}", a)); 输出a的四位小数