#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. Java NIO教程 目录

    "Java NIO系列教程" 是笔者hans为NIO的初学者编写的一份入门教程,想仔细学习的同学可以按照顺序去阅读.由于我学的也不是特别的精,所以错误.疏漏在所难免,希望同学们指正 ...

  2. dg

    package excel; import java.util.Scanner; public class doExcel { public static void main(String args[ ...

  3. pandas中将timestamp转为datetime

    参考自:http://stackoverflow.com/questions/35312981/using-pandas-to-datetime-with-timestamps 在pandas Dat ...

  4. Redis GetTypedClient

    C#操作Redis   未包含GetTypedClient定义 原创,转载请注明出处. VS版本:2015 用NuGet安装了Redis的包 按照百度的各种教程来操作,但是发现网上下载的DEMO可以正 ...

  5. C#实现简单的委托异步调用

    delegate void textAsy(); static void Main(string[] args) { textAsy t = texts; AsyncCallback callBack ...

  6. 统一资源定位符URL类

    package j2se.core.net.base; import java.io.BufferedReader;import java.io.IOException;import java.io. ...

  7. ajax 异步加载显示等待效果

    css: #loading { width:170px; height:25px; border:3px solid #C3DAF9; position:absolute; top:300px; le ...

  8. CMakeLists for tesseract

    在网上找了很多,直接用都不行,试了半天的到以下的结果. cmake_minimum_required(VERSION 2.8) project( test ) include_directories ...

  9. [[UIScreen mainScreen] bounds] 返回的屏幕尺寸不对

    在使用cocos2d-iphone 2.0生成项目的时候,用5s测试时全屏中上下一直有黑条,发现[[UIScreen mainScreen] bounds]返回的屏幕尺寸不是320*568的,而是32 ...

  10. Matlab(3) -- 编写M文件(函数)

    转自:http://blog.csdn.net/misskissc/article/details/8178089 matlab的命令编辑窗口(Command Window)界面主要是用来调用系统命令 ...