Please, I've just tried to submit 10087 for several times, and ---- WA. I'm afraid I didn't understand the problem well, for:
1. Whether negative and 0 are allowed to construct the magic square?
2. Are there any special test numbers I didn't consider well?
I have two functions to construct the square, and they are certainly right. The following is my main():
[cpp]
int n, sum;
while(fin>>n>>sum)
{
int magic_const = n*(n*n+1)/2;
if( (sum - magic_const)%n == 0 && sum - magic_const >= 0 )
{
int add = (sum - magic_const)/n;
int *p=new int[n*n];
if(n%2 != 0)
oddArray(p, n);
else
evenArray(p, n);
for(int i=0; i<n*n; ++i)
p += add;
output(p, n, fout);
delete[] p;
}
else
fout<<"You can't be like Shahjahan!\n\n";
}[/cpp]
10087 - The Tajmahal of ++Y2k
Moderator: Board moderators