Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine an…
首先,可以知道题目要求解一个\(ax+by=c\)的方程,且\(x+y\)最小. 感性证明: 当\(a>b\)时,\(y\)取最小正整数解,\(b\)减的多,\(a\)增的少,此时\(x+y\)取最小值.(类似比热容与温度之间) 反之亦然. #include<iostream> #include<cmath> #include<cstdlib> using namespace std; int a, b, c; int exgcd(int a, int b, in…
The Balance http://poj.org/problem?id=2142 Time Limit: 5000MS Memory Limit: 65536K Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 3…
嗯... 题目链接:http://poj.org/problem?id=2142 AC代码: #include<cstdio> #include<iostream> using namespace std; inline int _abs(int x){ ) return -x; return x; } inline void exgcd(int a, int b, int &g, int &x, int &y){ ; y = ;} else { exgcd…
d.用2种砝码,质量分别为a和b,称出质量为d的物品.求所用的砝码总数量最小(x+y最小),并且总质量最小(ax+by最小). s.扩展欧几里得求解不定方程. 设ax+by=d. 题意说不定方程一定有解.对于不定整数方程pa+qb=c,若 c mod Gcd(p, q)=0,则该方程存在整数解,否则不存在整数解. 也就是说,d mod gcd(a,b)=0. a,b,d同时除以gcd(a,b)得到a'x+b'y=d'; 用扩展欧几里德求出 a'x+b'y=gcd(a',b')=1的解(x,y),…