Page 1 of 2

10550 - Combination Lock

Posted: Thu Sep 25, 2003 7:44 pm
by Farid Ahmadov
Hi. Can anyone explain how we have to turn the dial? I follow steps with sample inputs and don't get correct answers.

Thanks.

Posted: Thu Sep 25, 2003 7:45 pm
by konsept
you're probably rotating clockwise instead of counter-clockwise.
and vice versa.

Posted: Thu Sep 25, 2003 8:10 pm
by Farid Ahmadov
Here is problem statement:
turn the dial clockwise 2 full turns
stop at the first number of the combination
turn the dial counter-clockwise 1 full turn
continue turning counter-clockwise until the 2nd number is reached
turn the dial clockwise again until the 3rd number is reached
pull the shank and the lock will open.
for example: 0 10 0 10
Initial position 0
2 full turns = 720 degree
stop at the first number 10 = 720 + 90 = 810
1 full turn and return to the same place = 810 + 360 = 1170
turning counter-clockwise from 1st position 10 to the 2nd 0 = 1170 + 90 = 1260
now the last turn clockwise from 2nd 0 to 3rd 10 = 1260 + 90 = 1350
The answer in sample output is 1890, but I didn't get the correct answer.

Which of this steps are wrong?

Posted: Thu Sep 25, 2003 10:14 pm
by little joey
As konsept said: you're turning the wrong way around.
The answer is 720+270+360+270+270=1890.

10550 Why WA?

Posted: Fri Dec 12, 2003 8:53 am
by Xander
I don't know why WA...but sample input gives correct answer...anyone help me....

#include <stdio.h>

void main(){
long int a, b, c, d, sum,temp;
while(scanf("%ld %ld %ld %ld",&a,&b,&c,&d)){
if(a==0&&b==0&&c==0&&d==0)break;
sum=1080;

temp=(a-b);
if(temp<0)temp=temp*(-1);

sum=sum+360-9*temp;

temp=(b-c);
if(temp<0)temp=temp*(-1);

sum=sum+360-9*temp;

temp=(c-d);
if(temp<0)temp=temp*(-1);

sum=sum+360-9*temp;

printf("%ld\n",sum);
}
}

Posted: Fri Dec 12, 2003 3:38 pm
by sohel
Hi Xander,
Your technique is not quite correct. I have made few modifications and got it AC.

this part of your code is wrong :

if(temp<0)temp=temp*(-1);
sum=sum+360-9*temp

instead of multiplying by -1, add 40 to tmp if necessary.
and sum = sum + 9*temp;

Hope it helps. :wink:

Posted: Sat Dec 13, 2003 7:51 am
by Xander
Thanks sohel, but still got WA...

I need Sapmle Input

Posted: Mon Dec 15, 2003 7:24 am
by Xander
Can any one give me more sample input...I want to judge my program why this is WA?

Thanks Everyone

Posted: Mon Dec 15, 2003 7:38 am
by sohel
Xander,

Remember from 2nd number to 3rd number the lock is moved counter-clockwise. so instead of
temp=(b-c);---------> temp=(c-b);


change
[cpp]
sum=1080;

temp=(a-b);
if(temp<0)temp=temp*(-1);
sum=sum+360-9*temp;

temp=(b-c);
if(temp<0)temp=temp*(-1);
sum=sum+360-9*temp;

temp=(c-d);
if(temp<0)temp=temp*(-1);
sum=sum+360-9*temp
[/cpp]

to

[cpp]
sum=1080;

temp=(a-b);
if(temp<0)temp=temp+40;
sum=sum+9*temp;

temp=(c-b);
if(temp<0)temp=temp + 40;
sum=sum+9*temp;

temp=(c-d);
if(temp<0)temp=temp + 40;
sum=sum+9*temp
[/cpp]

hope it helps.
:wink:

Posted: Mon Dec 15, 2003 1:17 pm
by Frostina
I'm confused with clockwise and counter-clockwise...

here is my code, and it's AC ...

But I still can't realise why ..... @_____@

[cpp]
#include <iostream>
using namespace std;
int turn (int a,int b,int d) {
if (d) { // clockwise
if (b>a) return (b-a);
else return (40-a+b);
}
else {
if (a>b) return (a-b);
else return (40-b+a);
}
}
int main() {
int a,b,c,d,s;
while (cin >>a>>b>>c>>d) {
if (!a&&!b&&!c&&!d) break;
s = 120;
s+=turn(a,b,0); // why here is counter-clockwise ?!
s+=turn(b,c,1);
s+=turn(c,d,0);
cout << s*9 << endl;
}
return 0;
}

[/cpp]

Posted: Sat Dec 20, 2003 2:50 am
by Xander
Thanks Sohel once again I got it AC now :D , you are a jennies man 8)

Posted: Sun Dec 28, 2003 7:28 pm
by sjn
Remember Always turn the dial :lol:

Posted: Wed Feb 18, 2004 6:54 am
by soyoja
The only trick of this problem is distinguish between clockwise and
counter-clocwise.
Counting angle for clockwise is (start point) - ( end point )
Counting angle for counter clockwise is (end point) - (start point )

Good luck~

10550 -- WA

Posted: Sat Jul 31, 2004 8:03 am
by nerocrux
[cpp]#include <iostream.h>
#include <stdio.h>

int main()
{
int a,b,c,d,sum;
while(cin>>a>>b>>c>>d)
{
if(a==0&&b==0&&c==0&&d==0) break;
sum=1080+(120+a-2*b+2*c-d)*9;
cout<<sum<<endl;
}
return 0;
}[/cpp]

I dont know where goes wrong but I got WA all the time,can u give me some test data??thx!

Re: 10550 -- WA

Posted: Sat Jul 31, 2004 9:40 am
by Piotrek Mazur
You should write the code like this:
[cpp]#include <iostream>
using namespace std;

/* code */

[/cpp]
1) there is no need to include stdio, if you use only cin and cout
2) declaration of iostream was wrong - but this cause only warning message

And the major problem, you calculate the output in wrong way. Try this:
5 15 35 5
5 15 25 35
0 0 0 0
Output for this test is:
1800
1710