#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream> using namespace std;
int a,b,c; int exgcd(int a,int b,int &x,int &y){
if (b==){
x = ;
y = ;
return a;
}
int d = exgcd(b,a%b,x,y);
int temp = x;
x = y;
y = temp - a / b * y;
return d;
} int f(int a){
if (a < )
a = -a;
return a;
} int main(){
//freopen("1.txt","r",stdin);
while(scanf("%d%d%d",&a,&b,&c)!=EOF){
if (!a && !b && !c)
break;
int x,y;
int flag = ;
if (a < b){
swap(a,b);
flag = ;
}
int d = exgcd(a,b,x,y);
x = x * (c / d);
y = y * (c / d);
int u,v;
u = x;
v = y;
int mx = ;
int x1,y1;
int t = y * d / a; // 凹函数,极点处取最值
for (int i = t - ;i <= t + ;i++){
u = x + b / d * i;
v = y - a / d * i;
if (f(u)+f(v)<mx){
mx = f(u) + f(v);
x1 = u;
y1 = v;
}
}
if (flag){
printf("%d %d\n",f(y1),f(x1));
}else {
printf("%d %d\n",f(x1),f(y1));
}
}
return ;
}

poj 2142 拓展欧几里得的更多相关文章

  1. poj 2142 扩展欧几里得解ax+by=c

    原题实际上就是求方程a*x+b*y=d的一个特解,要求这个特解满足|x|+|y|最小 套模式+一点YY就行了 总结一下这类问题的解法: 对于方程ax+by=c 设tm=gcd(a,b) 先用扩展欧几里 ...

  2. The Balance POJ 2142 扩展欧几里得

    Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...

  3. POJ.2142 The Balance (拓展欧几里得)

    POJ.2142 The Balance (拓展欧几里得) 题意分析 现有2种质量为a克与b克的砝码,求最少 分别用多少个(同时总质量也最小)砝码,使得能称出c克的物品. 设两种砝码分别有x个与y个, ...

  4. poj 1061 青蛙的约会 拓展欧几里得模板

    // poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...

  5. POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)

    POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...

  6. POJ.1061 青蛙的约会 (拓展欧几里得)

    POJ.1061 青蛙的约会 (拓展欧几里得) 题意分析 我们设两只小青蛙每只都跳了X次,由于他们相遇,可以得出他们同余,则有: 代码总览 #include <iostream> #inc ...

  7. poj 1845 【数论:逆元,二分(乘法),拓展欧几里得,费马小定理】

    POJ 1845 题意不说了,网上一大堆.此题做了一天,必须要整理一下了. 刚开始用费马小定理做,WA.(poj敢说我代码WA???)(以下代码其实都不严谨,按照数据要求A是可以等于0的,那么结果自然 ...

  8. POJ 2891 Strange Way to Express Integers(拓展欧几里得)

    Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express ...

  9. poj 1061 青蛙的约会+拓展欧几里得+题解

    青蛙的约会+拓展欧几里得+题解 纵有疾风起 题意 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出 ...

随机推荐

  1. webservice 接口通过 HTTP 获取数据

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Ne ...

  2. 关于c#的事件如何使用

    c#的委托delegate事件的详细使用 一.无参数,无返回的委托事件 委托事件类.事件的发生源.1.声明委托  2定义事件 3具体方法 public class Test { // …. publi ...

  3. EhCache RMI 分布式缓存/缓存集群

    EhCache 系统简介 EhCache 是一个纯 Java 的进程内缓存框架,具有快速.精干等特点. EhCache 的主要特性有: 快速.精干 简单: 多种缓存策略: 缓存数据有两级:内存和磁盘, ...

  4. iOS中编写单例类的心得

    单例 1.认识过的单例类有哪些: NSUserDefaults.NSNotificationCenter.NSFileManager.UIApplication 2.单例类 单例类某个类在代码编写时使 ...

  5. ie,火狐,谷歌 select清除默认样式 设置新的样式

    select { border: solid 1px #000; /*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/ appearance:none; -moz-appearan ...

  6. TP框架,根据当前应用状态对应的配置文件

    index.php define('APP_STATUS','website'); /ThinkPHP/Library/Think/Dispatcher.class.php /** * 应用程序初始化 ...

  7. Python.Module.site

    site " This module is automatically imported during initialization. The automatic import can be ...

  8. [转]学术型 github 畅想

    转自 http://wulfric.me/2013/09/github-and-academy/ 以 github 的精神提供学术服务,也许是一个不错的方向. 什么是 github? Github 是 ...

  9. ABP的语言切换

    在ABP官网http://www.aspnetboilerplate.com/创建一个Multi Page Web Application项目并打开,在Web项目下可以找到一个Controllers/ ...

  10. service XXX does not support chkconfig

    有时候为了方便管理,我们常常喜欢在Linux中将之安装为服务,然后就可以使用服务来管理. 但是当我们运行安装服务的命令时候,假设服务名为myservice #chkconfig --add myser ...