i am getting wa for http://www.spoj.pl/problems/BMJ/
My logic is that i have seen that the numbers in Willi's Coordinate
System vertically downwards from 1 are following a pattern and i
have stored that pattern in array ar and the index of the array for
each value of Willi's Coordinate System is the y co-ordinate of Maja's
Coordinate System and as we proceed in the clockwise fashion in Maja's
Coordinate System from any value of the index of array ar say for example
0 2 we observe that 1st x decreases and then y decreases and then
(x increases and y decreases simultaneously) and the y increases and the
last one i have seen that is always 1 y(1 2) in this case.
i have attached my code.
please help!
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
int main()
{
int ar[183] = {1,2, 9, 22, 41, 66, 97, 134, 177, 226, 281,
342, 409, 482, 561, 646, 737, 834, 937, 1046, 1161, 1282, 1409,
1542,1681, 1826, 1977, 2134, 2297, 2466, 2641, 2822, 3009, 3202, 3401,
3606, 3817, 4034, 4257, 4486, 4721, 4962, 5209, 5462, 5721, 5986,
6257, 6534, 6817, 7106, 7401, 7702, 8009, 8322, 8641, 8966, 9297,
9634, 9977, 10326, 10681, 11042, 11409, 11782, 12161, 12546, 12937,
13334, 13737, 14146, 14561, 14982, 15409, 15842, 16281, 16726, 17177,
17634, 18097, 18566, 19041, 19522, 20009, 20502, 21001, 21506, 22017,
22534, 23057,23586, 24121, 24662, 25209, 25762, 26321, 26886, 27457,
28034, 28617, 29206, 29801, 30402, 31009, 31622, 32241, 32866, 33497,
34134, 34777, 35426, 36081, 36742, 37409, 38082, 38761, 39446, 40137,
40834, 41537, 42246, 42961, 43682, 44409, 45142, 45881,46626, 47377,
48134, 48897, 49666, 50441, 51222, 52009, 52802, 53601, 54406, 55217,
56034, 56857, 57686, 58521, 59362, 60209,61062, 61921, 62786, 63657,
64534, 65417, 66306, 67201, 68102,69009, 69922, 70841, 71766, 72697,
73634, 74577, 75526, 76481, 77442, 78409, 79382, 80361, 81346, 82337,
83334, 84337, 85346,86361, 87382, 88409, 89442, 90481, 91526, 92577,
93634, 94697, 95766, 96841, 97922, 99009};
int n;
while(cin>>n)
{
int st=0,end=182,mid=(st+end)/2;
int ans=ar[mid];
while(st<=end)
{
ans=ar[mid];
mid=(st+end)/2;
if(n>ar[mid])
st=mid+1;
else if(n<ar[mid])
end=mid-1;
else if(n==ar[mid])
{ break;}
}
// cout<<"mid="<<mid<<" st="<<st<<" end="<<end<<"
ans=<<"<<ans<<" ar[mid]="<<ar[mid]<<"\n";
if(n==ar[mid])
{cout<<0<<" "<<mid<<"\n";continue;}
else
{
int yy=end;
int ini=ar[end];
int x=0;
int y=yy;
while(ini<n&&x>-yy)
{
x--;
ini++;
}
if(ini==n)
{cout<<x<<" "<<y<<"\n";continue;}
while(ini<n&&y>0)
{
y--;
ini++;
}
if(ini==n)
{cout<<x<<" "<<y<<"\n";continue;}
while(ini<n&&x<yy)
{
x++;
if(y>-yy)
y--;
ini++;
}
if(ini==n)
{cout<<x<<" "<<y<<"\n";continue;}
while(ini<n&&y<yy-1)
{
y++;
ini++;
}
if(ini==n)
{cout<<x<<" "<<y<<"\n";continue;}
y=yy;x=1;
cout<<x<<" "<<y<<"\n";
}
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.