## 10550 - Combination Lock

Moderator: Board moderators

Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan

### 10550 - Combination Lock

Hi. Can anyone explain how we have to turn the dial? I follow steps with sample inputs and don't get correct answers.

Thanks.
_____________
NO sigNature

konsept
New poster
Posts: 22
Joined: Wed Dec 19, 2001 2:00 am
Contact:
you're probably rotating clockwise instead of counter-clockwise.
and vice versa.

Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan
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?
_____________
NO sigNature

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
As konsept said: you're turning the wrong way around.

Xander
New poster
Posts: 6
Joined: Thu Oct 02, 2003 11:48 pm

### 10550 Why WA?

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);
}
}

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
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

and sum = sum + 9*temp;

Hope it helps. Last edited by sohel on Sat Dec 20, 2003 10:15 am, edited 1 time in total.

Xander
New poster
Posts: 6
Joined: Thu Oct 02, 2003 11:48 pm
Thanks sohel, but still got WA...

Xander
New poster
Posts: 6
Joined: Thu Oct 02, 2003 11:48 pm

### I need Sapmle Input

Can any one give me more sample input...I want to judge my program why this is WA?

Thanks Everyone

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
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. Frostina
New poster
Posts: 23
Joined: Mon Dec 15, 2003 5:21 am
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]
Thanks for your help ! Xander
New poster
Posts: 6
Joined: Thu Oct 02, 2003 11:48 pm
Thanks Sohel once again I got it AC now , you are a jennies man sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:
Remember Always turn the dial soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:
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~

nerocrux
New poster
Posts: 7
Joined: Fri Jul 30, 2004 5:14 am
Location: city of god

### 10550 -- WA

[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!

Piotrek Mazur
New poster
Posts: 17
Joined: Thu Jul 15, 2004 10:55 am
Location: Poland, Rzeszow University of Technology

### Re: 10550 -- WA

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