10550 - Combination Lock

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

Moderator: Board moderators

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

10550 - Combination Lock

Post by Farid Ahmadov » Thu Sep 25, 2003 7:44 pm

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
Location: Waterloo, Canada
Contact:

Post by konsept » Thu Sep 25, 2003 7:45 pm

you're probably rotating clockwise instead of counter-clockwise.
and vice versa.

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

Post by Farid Ahmadov » Thu Sep 25, 2003 8:10 pm

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

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Thu Sep 25, 2003 10:14 pm

As konsept said: you're turning the wrong way around.
The answer is 720+270+360+270+270=1890.

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

10550 Why WA?

Post by Xander » Fri Dec 12, 2003 8:53 am

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

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » Fri Dec 12, 2003 3:38 pm

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:
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
Location: Dhaka, Bangladesh

Post by Xander » Sat Dec 13, 2003 7:51 am

Thanks sohel, but still got WA...

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

I need Sapmle Input

Post by Xander » Mon Dec 15, 2003 7:24 am

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

Thanks Everyone

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » Mon Dec 15, 2003 7:38 am

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:

Frostina
New poster
Posts: 23
Joined: Mon Dec 15, 2003 5:21 am

Post by Frostina » Mon Dec 15, 2003 1:17 pm

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
Location: Dhaka, Bangladesh

Post by Xander » Sat Dec 20, 2003 2:50 am

Thanks Sohel once again I got it AC now :D , you are a jennies man 8)

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

Post by sjn » Sun Dec 28, 2003 7:28 pm

Remember Always turn the dial :lol:

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja » Wed Feb 18, 2004 6:54 am

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

Post by nerocrux » Sat Jul 31, 2004 8:03 am

[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

Post by Piotrek Mazur » Sat Jul 31, 2004 9:40 am

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

Post Reply

Return to “Volume 105 (10500-10599)”