2012/03/06

Topcoder SRM 535(Div.2) Report


"Fox Jiro and Eel Saburo are good friends."

250-problem:It is the problem of the simultaneous equations. These equations are symmetric, so I can get answer by addition and subtraction of two equations. This have no answer because there are four expressions for three unknown quantity.  I am after a long absence, I solve this problem very carefully.208.97pts.

500-problem: Use Euclid's Algorithm and next theorem: m*n=GCD(m,n)*LCM(m,n). I found all L's divisor. I think, I could get L's divisor which is multiple of G. If we get the list, this problems was easier.284.88pts.

Problems are here.
Score=493.85, Standings=81/1412. Rating 1125->1200. I became Blue Coder(Division 1), I'm worry about next contest.

[Easy(C++),Accepted]


#include<cstdio>
#include<iostream>
#include<vector>


using namespace std;


class FoxAndIntegers{
public:
vector <int> get(int AminusB, int BminusC, int AplusB, int BplusC){
vector<int> ret(3);
vector<int> empty(0);
if((AplusB + AminusB)%2!=0) return empty;
if((BplusC - BminusC)%2!=0) return empty;
if((AplusB - AminusB)%2!=0) return empty;
if((AplusB - AminusB)!=(BplusC + BminusC)) return empty; 
ret[0]=(AplusB + AminusB)/2;
ret[1]=(AplusB - AminusB)/2;
ret[2]=(BplusC - BminusC)/2;
return ret;
}
};


[Medium(C++),Accepted]


#include<iostream>
#include<cmath>


using namespace std;


class FoxAndGCDLCM{
public:
long long get(long long G, long long L){
long long sum=-1,tmp;
for(long long i=1;i*i<=L;i++){
if(L%i!=0) continue;
tmp=L/i*G+i;
if(euclid(i,tmp-i)==G && (sum>tmp || sum==-1)) sum=tmp;
long long k=L/i;
tmp=L/k*G+k;
if(euclid(k,tmp-k)==G && (sum>tmp || sum==-1) ) sum=tmp;
}
return sum;
}

long long euclid(long long a,long long b){
if(b==0) return a;
return euclid(b,a%b);
}
};

0 件のコメント:

コメントを投稿