250:题意:知道A+B,B-C,A-B ,B+C ,的值求ABC的值,很水吧- -
做法是,先什么都不考虑就把ABC算出来,然后回过头验证是否符合
:
|
或者是枚举,ABC,3重循环。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class FoxAndIntegers {
public:
vector <int>get(int AminusB, int BminusC, int AplusB, int BplusC)
{
int A, B, C;
B = (BminusC + BplusC)/2;
A = (AminusB + AplusB)/2;
C = BplusC - B;
bool pos = true;
vector<int> ans;
if ( A-B != AminusB||A+B != AplusB||B-C != BminusC||C+B != BplusC ) pos = false;
if ( pos )
{
ans.push_back(A);
ans.push_back(B);
ans.push_back(C);
}
return ans;
}
};
500pt:
题意:
知道两数的最大公约数和最小公倍数,球这两个数。关键是此题数据比较大10^12.
根据
L=(A*B)/G
两边同时再除以一个G
L/G = (A/G) * (B/G)
这两个数也是互质的
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class FoxAndGCDLCM {
public:
long long gcd(long long a, long long b)
{
if ( a == 0) return b;
return gcd(b%a, a);
}
long long FoxAndGCDLCM::get(long long G, long long L)
{
if ( L%G != 0 ) return -1;
long long C = L/G, ans = 1LL<<60;
for ( long long i =1; i*i <= C; i++ )
{
if ( C%i == 0 )
{
long long j = C/i;
if ( gcd(i,j) == 1 )
{
ans = min(ans, G*(i+j));
}
}
}
if ( ans == 1LL<<60 ) ans =-1;
return ans;
}
};