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;
}
};