Alright I keep getting WA for 10022, and I can't find the bug at all. I have tested on M,N from 1 to 25 extensively, and the program seems to be working perfectly. Can anyone test my program and tell me some test cases that can break my program? THANKS.
#include <iostream.h>
#include <stdlib.h>
void findlevel(unsigned, unsigned[]);
int main()
{
unsigned M, N, levelM, levelN, answer=0;
unsigned left, right, numInLevel, result[2];
unsigned leftMost, rightMost, level, temp1, temp2;
cin >> temp1 >> temp2;
M = (temp1 < temp2 ? temp1 : temp2);
N = (temp1 == M ? temp2 : temp1);
findlevel(M, result);
levelM = result[0];
numInLevel = result[1];
findlevel(N, result);
levelN = result[0];
answer+=(2 * (levelN - levelM));
level = levelM;
leftMost = M;
rightMost = M;
while(true)
{
if(level == levelN)
break;
leftMost+=numInLevel;
rightMost+=(2 + numInLevel);
level++;
numInLevel+=2;
}
//cout << "leftmost: " << leftMost << "\t" << "rightmost: " << rightMost;
//cout << "\n";
//cout << "answer at line 37: " << answer << "\n";
if(levelM == levelN)
answer = N - M;
else if(N >= leftMost && N <= rightMost)
{
answer = ((N - leftMost)%2 == 0 ? answer : answer+1);
}
else if(N > rightMost)
{
answer+=(N - rightMost);
}
else if(N < leftMost)
{
answer+=(leftMost - N);
}
// cout << "answer at line 53: " << answer << "\n";
if((levelM%2 == 0 && M%2 == 0) || (levelM%2 == 1 && M%2 == 1))
{
if(N>=leftMost && N<=rightMost &&
((levelN%2 == 0 && N%2==1) || (levelN%2 == 1 && N%2==0)))
answer-=2;
}
cout << answer << "\n";
return 0;
}
void findlevel(unsigned num, unsigned result[])
{
unsigned level=1, numInLevel=1, sofar=1;
while(true)
{
if(sofar >= num)
{
result[0] = level;
result[1] = numInLevel;
return;
}
level++;
numInLevel+=2;
sofar+=numInLevel;
}
}
10022 - Delta-wave
Moderator: Board moderators
NEVERMIND...It's Multiple Input thingy
Alright this multiple input thingy keeps screwing me up. Well kinda my bad, I didn't read carefully and thought green key is multiple input, when blue one is multiple input as well. haha...you fellows out there should watch out for those too.
-
- Experienced poster
- Posts: 192
- Joined: Sat Nov 30, 2002 5:14 am
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10022 - Delta-wave
I just got A.C., and the Judge's input seems do not very tricky. Even my poor algorithm which simulates directly the whole process could solve this problem in a short time. 

Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?