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…
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…
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11878 Accepted: 7417 Description Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arm…
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),…
题目传送门 一遇到数学就卡住,我这是怎么肥4...(或许到图论会愉悦吧,逃) Description * 给出两种重量为的 A, B 的砝码,给出一种使用最少的砝码的方式,称出重量 C. 我们可以比较容易地列出方程$Ax+By=C$.之后来一发exgcd搞,求出方程的一组特解.平时我们求的往往是最小解,但这次它却要求两解之和最小.我们要做特殊的变形. 首先我们应该知道方程的通解:(约定:设x0,y0为一组特解,t为任意整数,设a>b(不行再交换)) 那么有 $x=x0+b/gcd*t$ $y=y…