10940 - Throwing cards away II
Moderator: Board moderators
Crazy WA..
Some one please help me I think i have done it by simulation... But what should be done now... It's giving me WA.. But I think it will not overflow... What's wrong....
Code: Select all
#include<stdio.h>
int main()
{
long int n,x,ans,s;
while(scanf("%ld",&n)==1)
{
if(n==0)
break;
else
{
x=1;
while(x<n)
{
x=x*2;
s=x%n;
ans=n-s;
}
printf("%ld\n",ans);
}
}
return 0;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Still WA...
[/quote]
I got WA... again & again... But where is my error...! Why this gives me WA...
[/code]
I got WA... again & again... But where is my error...! Why this gives me WA...
[/code]
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: Still WA...
carefully consider the case when n=1.Obaida wrote: I got WA... again & again... But where is my error...! Why this gives me WA...
Confusion
When n=1 then what will be the output... 1 or 0.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: Confusion
Obaida wrote: When n=1 then what will be the output... 1 or 0.
Problem Description wrote:Given is an ordered deck of n cards numbered 1 to n
Oh..
I think I have it... If n==1 then output will be 1.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: Oh..
So you got Accepted. Is it?Obaida wrote: I think I have it... If n==1 then output will be 1.
It should be... I got Acc.. before posting...
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10940 - Throwing cards away II
It should be a dynamic programming problem but how can some people solved this problem in 0.012secs
Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?
Re: 10940 - Throwing cards away II
This is not a dynamic programming problem @DD...this is a very interesting problem that i solved using simple mathematics.
I didn't even use recursions or functions in my code
My hint is solve 10935 before attempting this
Second hint is after you solve 10935, you can't solve this using the same method because you will get TLE, still worth a try isn't it?
Note: May be it is possible to solve this using DP or some complex algorithm, but there is always a smarter way. You only need to know the basic of programming for the simplest solution which I could find, just think for a while.
And @DD, my best for this problem is 0.032 sec, and I don't know much about code optimization. So why is it not possible to get AC in 0.012 seconds with optimizations like fread or faster I/O?
I didn't even use recursions or functions in my code
My hint is solve 10935 before attempting this
Second hint is after you solve 10935, you can't solve this using the same method because you will get TLE, still worth a try isn't it?
Note: May be it is possible to solve this using DP or some complex algorithm, but there is always a smarter way. You only need to know the basic of programming for the simplest solution which I could find, just think for a while.
And @DD, my best for this problem is 0.032 sec, and I don't know much about code optimization. So why is it not possible to get AC in 0.012 seconds with optimizations like fread or faster I/O?
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Re:
To solve this problem I took Jan's hint and evaluated the values from 1 through 15 (you don't need to really go all the way to 50). Though I initially started this by hand, I realized it'd be easier to do this using UVA Toolkit. If you're completely stuck like I was, then this might be a good start.Jan wrote:Just evaluate the values upto 50. And you will get an easy sequence. If you still dont find it then I will tell you.
Also, here's some input / output that I found useful during testing / debugging.
Input:
Code: Select all
1
22
3333
444444
500000
66666
777
89
9999
0
Code: Select all
1
12
2570
364600
475712
2260
530
50
3614
Re: 10940 - Throwing cards away II
I solved it with DP. It is not complex at all, very simple recurrence. My best for this problem is also 0.032.plamplam wrote:This is not a dynamic programming problem @DD...this is a very interesting problem that i solved using simple mathematics.
I didn't even use recursions or functions in my code
My hint is solve 10935 before attempting this
Second hint is after you solve 10935, you can't solve this using the same method because you will get TLE, still worth a try isn't it?
Note: May be it is possible to solve this using DP or some complex algorithm, but there is always a smarter way. You only need to know the basic of programming for the simplest solution which I could find, just think for a while.
And @DD, my best for this problem is 0.032 sec, and I don't know much about code optimization. So why is it not possible to get AC in 0.012 seconds with optimizations like fread or faster I/O?
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman