Cod sursa(job #1356004)
Utilizator | Data | 23 februarie 2015 09:18:08 | |
---|---|---|---|
Problema | Heavy Path Decomposition | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 2.05 kb |
#include <fstream>
using namespace std;
ifstream fin("punctul.in");
ofstream fout("punctul.out");
int n,i,j,lin,col,cerinta,nr,p;
int main()
{
fin >> cerinta;
if (cerinta==1)
{
fin >> n;
nr=0;
while (nr*(nr+1)<=n)
nr++;
nr--;
lin=col=nr;
n-=nr*(nr+1);
if (nr % 2==1)
{
if (n<=nr)
fout << nr-n << " " << nr;
if (n==nr+1)
fout << 0 << " " << nr+1;
if (n>nr+1)
fout << n-nr-1 << " " << nr+1;
}
else
{
if (n<=nr)
fout << nr << " " << nr-n;
if (n==nr+1)
fout << nr+1 << " " << 0;
if (n>nr+1)
fout << nr+1 << " " << n-nr-1;
}
}
else
{
fin >> i >> j;
if (i==j)
fout << i*i+i;
if (i<j)
{
if (i % 2==0 && j % 2==0)
{
p=j*(j+1)-j+i;
fout << p;
}
if (i % 2==0 && j % 2==1)
{
p=j*(j+1)+j-i;
fout << p;
}
if (i % 2==1 && j % 2==0)
{
p=j*(j+1)-j+i;
fout << p;
}
if (i % 2==1 && j % 2==1)
{
p=j*(j+1)+j-i;
fout << p;
}
}
if (i>j)
{
if (i % 2==0 && j % 2==0)
{
p=i*(i+1)+i-j;
fout << p;
}
if (i % 2==0 && j % 2==1)
{
p=i*(i+1)+i-j;
fout << p;
}
if (i % 2==1 && j % 2==0)
{
p=i*(i+1)-i+j;
fout << p;
}
if (i % 2==1 && j % 2==1)
{
p=i*(i+1)-i+j;
fout << p;
}
}
}
fin.close();
fout.close();
return 0;
}