10651 - Pebble Solitaire

All about problems in Volume 106. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Tomislav Novak
New poster
Posts: 44
Joined: Fri Feb 20, 2004 5:52 pm

10651 - Pebble Solitaire

Post by Tomislav Novak »

Hi. I'm trying to solve problem 10651. I have a variable mask which denotes the state (1 if there is a pebble in a cavity, 0 otherwise), and I'm using a memoized recursive function to calculate the minimum number of pebbles left. I also wrote a routine to print the optimal process of removing the pebbles, however I can't find a test case where it fails (WA on online judge). Perhaps I misunderstood the problem?
Here's my code:

Code: Select all

removed
Thanks in advance!
Last edited by Tomislav Novak on Fri Jan 20, 2006 7:02 pm, edited 2 times in total.
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

The input begins with a positive integer n on a line of its own. Thereafter n different games follow.
So don't wait fro EOF.
Tomislav Novak
New poster
Posts: 44
Joined: Fri Feb 20, 2004 5:52 pm

Post by Tomislav Novak »

mamun wrote:So don't wait fro EOF.
It makes no difference. Still wrong answer.
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

Here are some I/O for you
Input

Code: Select all

4
oo--oooo-ooo
oooo-oooo-oo
-oooo-oo-oo-
oooooooo-oo-
Output

Code: Select all

2
1
1
2
Tomislav Novak
New poster
Posts: 44
Joined: Fri Feb 20, 2004 5:52 pm

Post by Tomislav Novak »

mamun wrote:Here are some I/O for you
I've finally spotted the bug. It was the 'else if' part in my recursive function... :oops:
Thank you very much.
newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 10651 - Pebble Solitaire

Post by newkid »

Hi,
I am trying to solve this problem. But all the time i get TLE. my code snippet is below..

Code: Select all

int state[15];

int getmin(int index) {
......
}
int main() {
  int test;
  char line[15];
  char ch;

  scanf("%d", &test);

  while (test--) {
    int index = 0;

    for (int i = 0; i < 12;) {
      ch = getchar();
      if (ch == 'o' || ch == '-') {
        index = index  * 2 + (ch == 'o' ? 1 : 0); 
        state[i] =  (ch == 'o' ? 1 : 0);  
        i++;
      } else if (ch == '\n' || ch == (char)EOF)
        break;
      else
        continue;
    }

    // i get TLE without even calling the getmin()..
    //int res = getmin(index);
    //printf("%d\n", res);

    printf("%d\n", index%12);
  }

  return 0;
}
problem is i get TLE even without calling the getmin() function. I tried with gets() but the result is same..
help please..
hmm..
newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 10651 - Pebble Solitaire

Post by newkid »

got the problem.. its not with the input scanning.. I had one macro to hide freopen(..), my mistake was there..
anyway judge didn't give me Restricted Function.. that was odd!!
hmm..
Post Reply

Return to “Volume 106 (10600-10699)”