calculus.saransh's blog

By calculus.saransh, 8 years ago, In English,

I ended up solving 3 questions.. the 3rd one took me a lot of time because I manually pre-computed all the configurations and wrote them in my code.


Here is a short description on how I solved the 3 problems hopefully it is helpful.

Problem A

The first problem required manual checking. As I use Java, StringTokenizer helped me to break the string using '.' as the delimiter. As I had 2 strings I could check for the last character of the first string and if it was equal to 9 I printed "GOTO Vasilisa." and for the other case I checked if the first char of the other string was greater than '5' if yes I added 1 to the first strings last char else print the same string.

Problem B

Problem B was easier considering the mathematical nature of the problem. There were a few cases to take care of and a score of 900+ was easily get able. On summing up the volumes if they don't divide equally among the n cups, then the answer is unrecoverable. If all of the values are equal to the average then the pages did not play any prank. On the other hand if more than 2 cups deviate from the average the answer is again unrecoverable. If the number of cups that deviate is 2. We can find the cups which were used for transfer and find the volume transferred by calculating the difference of the values from the mean.

Problem C

The problem is easy but during the contest I could not come with a very good approach in one go. I started waywardly and in the end pre computed all the 24 configurations which are equal to each other. Then I just checked how many different configurations can be made using the colors given. Generate all the 720 permutations of the string for that.

For the generation of the 24 configurations I fixed a top and then rotated the cube by 90 degs again and again to get all the 4 configurations for that top. Fixing all the  6 tops. We get in total 6*4=24 configurations as equivalent to each other.

code snippet

//24 configurations given
configs[]={"012345","031425","043215","024135","103254","120534",
"152304","135024","254103","215043","201453",
"240513","310542","351402","345012","304152","453201",
"425031","402351","430521","513240","521430","542310","534120"};
for(int i=0;i<720;i++)
{
                boolean different=different(in,conf[i]);
                for(int j=0;j<i;j++)
                    if(!different(conf[i],conf[j]))
                    {
                        different=false;
                        break;
                    }
                if(different)
                    tot++;
}

boolean different(String a,String b)
    {
        for(int i=0;i<24;i++)
        {
            boolean equal=true;
            for(int j=0;j<6;j++)
            {
                if(a.charAt(j)!=b.charAt(configs[i].charAt(j)-'0'))
                    equal=false;
            }
            if(equal)
                return false;
        }return true;


    }



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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Div 2 C Can anyone explan how "012345","031425" configaration are equvalet?