嗯...

题目链接:http://poj.org/problem?id=2142

AC代码:

 #include<cstdio>
#include<iostream> using namespace std; inline int _abs(int x){
if(x < ) return -x;
return x;
} inline void exgcd(int a, int b, int &g, int &x, int &y){
if(!b) { g = a; x = ; y = ;}
else { exgcd(b, a % b, g, y, x); y -= x * (a / b);}
} inline void work(int a, int b, int c, int &g, int &x, int &y){
exgcd(a, b, g, x, y);
x *= c / g;
int t = b / g;
x = (x % t + t) % t;
y = _abs((a * x - c) / b);
} int main(){
int a, b, c, x1, g, y1, x2, y2;
while(~scanf("%d%d%d", &a, &b, &c)){
if(!a && !b && !c) break;
work(a, b, c, g, x1, y1);
work(b, a, c, g, x2, y2);
if(x1 + y1 < x2 + y2) printf("%d %d\n", x1, y1);
else printf("%d %d\n", y2, x2);
}
return ;
}

AC代码

POJ 2142 The Balance(exgcd)的更多相关文章

  1. POJ - 2142 The Balance(扩展欧几里得求解不定方程)

    d.用2种砝码,质量分别为a和b,称出质量为d的物品.求所用的砝码总数量最小(x+y最小),并且总质量最小(ax+by最小). s.扩展欧几里得求解不定方程. 设ax+by=d. 题意说不定方程一定有 ...

  2. POJ 2142 The Balance (解不定方程,找最小值)

    这题实际解不定方程:ax+by=c只不过题目要求我们解出的x和y 满足|x|+|y|最小,当|x|+|y|相同时,满足|ax|+|by|最小.首先用扩展欧几里德,很容易得出x和y的解.一开始不妨令a& ...

  3. 【题解】POJ 2115 C Looooops (Exgcd)

    POJ 2115:http://poj.org/problem?id=2115 思路 设循环T次 则要满足A≡(B+CT)(mod 2k) 可得 A=B+CT+m*2k 移项得C*T+2k*m=B-A ...

  4. POJ 2115 C Looooops(Exgcd)

    [题目链接] http://poj.org/problem?id=2115 [题目大意] 求for (variable = A; variable != B; variable += C)的循环次数, ...

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

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

  6. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  7. POJ 3253 Fence Repair (优先队列)

    POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...

  8. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  9. Poj 3613 Cow Relays (图论)

    Poj 3613 Cow Relays (图论) 题目大意 给出一个无向图,T条边,给出N,S,E,求S到E经过N条边的最短路径长度 理论上讲就是给了有n条边限制的最短路 solution 最一开始想 ...

随机推荐

  1. LitElement(六)生命周期

    1.概述 基于LitElement的组件通过响应观察到的属性更改而异步更新. 属性更改是分批进行的,如果在请求更新后,更新开始之前,发生更多属性更改,则所有更改都将捕获在同一次更新中. 在较高级别上, ...

  2. 管理QT的组件

    1.在qt的安装目录找到'%QTROOT%\MaintenanceTool.exe'. 2.点击MaintenanceTool的设置,可以设置默认储存库.临时储存库.用户定义储存库,选择其中的临时储存 ...

  3. git创建远程分支并推送

    1.查看所有分支(-a=>'查看全部的分支') git branch -a 2.创建本地test分支 git branch test 2.2切换test分支 git checkout test ...

  4. 记manjaro图形驱动删除后的一次补救

    #一.前言 众所周知,NVIDIA的闭源驱动在Linux上的兼容性不是很好,再加上我不玩游戏,于是我就想卸载独显只留核显.我以为我装了独显和核显两种驱动,原本想直接删除独显驱动,没想到删除的是bumb ...

  5. DisplayNameFor()方法的工作原理

    DisplayNameFor()方法的工作原理原创Peter Yelnav 最后发布于2018-11-23 11:09:51 阅读数 1308 收藏展开最近研究了一下ASP.NET MVC,困惑于视图 ...

  6. 使用 NuGet 包管理器在 Visual Studio 中安装和管理包

    https://docs.microsoft.com/zh-cn/nuget/consume-packages/install-use-packages-visual-studio 通过 Window ...

  7. C++-POJ3274-Gold Balanced Lineup[hash]

    不是很懂? 胡乱hash #include <set> #include <map> #include <cmath> #include <queue> ...

  8. backward的gradient参数的作用

    backward的gradient参数的作用 待办 https://zhuanlan.zhihu.com/p/29904755 https://zhuanlan.zhihu.com/p/2992309 ...

  9. codeforces E. The Contest(最长上升子序列)

    题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...

  10. ErgExp-lookbehind assert(后行断言)

    //先行断言:先遇到一个条件,判断后面的条件是否满足 let test = 'hello world' console.log(test.match(/hello(?=\sworld)/)) //后行 ...