Re_cursive's blog

By Re_cursive, 11 years ago, In English

Understanding the Problem

Most of you might have looked at the tutorial for this problem and are still confused as to why odd values are not included as perfect permutations?

Reason why we don't print permutations for odd values is not because they do not exist (They do exist!) but because of one of the conditions. This condition being Ppi = i or in more understandable terms P[ P[ i ] ] = i.

Example

So if you have the number 3, the possible permutations you can have to satisfy the second condition(Pi != i) are:

A = [ 3 1 2 ] or B = [ 2 3 1 ]

if we try to apply the first condition to any of the sets, we can see that

A[ A[ 2 ] ] = A[ 1 ] != 2

B[ B[ 2 ] ] = B[ 3 ] != 2

A[ A[ 1 ] ] = A[ 3 ] != 1

And as soon as one of these conditions fail, there cannot be a perfect permutation

Hope that helped

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it

By Re_cursive, 12 years ago, In English

Here is my solution. http://ideone.com/LW19fV

It produces the right answer sometimes, and other times, it messes it up. I have a few questions about this problem.

In the tutorial, it says: ...So we need to sort all available students in the order of increasing fj and try to feed 0, 1, 2, ldots first students in this order. What are ldots? In my code, I did sort the students in order of increasing food need, and code feeds as many as is possible per day.

Finally, could someone please look through my code, and tell me where I am messing up? The solving part is in the function called "Solve()" (duh).

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Re_cursive, 12 years ago, In English
#include <cstdio>

int main()
{
  int num_P, T, sum, Total = 0, *Avail, ind = 0, end = 0;
  bool MadePair = false;
  
  for (scanf("%d", &num_P), Avail = new int[num_P], sum = 0; sum < num_P; ++sum, MadePair = false)
  {
    scanf("%d", &T);
    
    if ((4 - T) > 0) {
      end = ind;
      
      while (Avail[--end]){
	if ((Avail[end] - T) >= 0){
	  Avail[end] -= T;
	  MadePair = true;
	  break;
	}
      }
      
      if (!MadePair) { //Skips this entire block {}
	++Total;
	Avail[ind++] = 4 - T;
      }
    }
    else if ((4 -T) == 0)
      ++Total;
  }
  
  printf("%d\n", Total);
  
  return 0;
}

The judge skips the if statement I pointed out. I know it does this because I ran a test on this site and and using some print statements, I saw that it did not print anything or do anything inside the if-statement.

It works for me and I'm sure anyone who sees the code would know that it should work. It might just be that the editor I'm using appends some hidden characters to the code because that was the case in my last blog. In that case, if someone sees these hidden characters, can they point it out or explain why the compiler is skipping the if statement?

Thanks

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Re_cursive, 12 years ago, In English

It is frustrating having to submit a perfectly good working code and the so-called computer tells you that the output is wrong. There needs to be a new level of constructive criticism that goes into the feedback for submissions. Feedback that actually tells you what is wrong and not just that it is not working! That is totally useless information to me. What am I supposed to do with code that is not working when I don't know what is not working?? Another level of this nonsense is when you submit and your answer it is correct when you test it on your computer, but when the checker checks it using a different operating system, and it doesn't compile correctly, instead of telling you to use a different syntax in your coding to match the allowed syntax for the OS the checker is using, oh no, it tells you ..."Compile error!". Wtf?!?

A new one I encountered today which is actually what made me write this blog is when your answer matches the answer required AND the checker shows the output and you have exactly the same thing as the answer it was looking for! But it says incorrect!?!?

Anyone who reads, please pass it on to someone who can help me fix this. I am still new here, so I don't really know where to submit bugs yet.

Full text and comments »

  • Vote: I like it
  • -29
  • Vote: I do not like it