11686 - Pick up sticks

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

Moderator: Board moderators

ymgve
New poster
Posts: 7
Joined: Mon Oct 15, 2007 1:17 am

11686 - Pick up sticks - possible in Java?

Post by ymgve »

Hi, I'm trying to do the Pick up sticks problem and wonder if it's possible to do in Java with normal data structures. Just using one ArrayList for each node already gives me a TLE. Any suggestions?

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

11686 Runtime error Here

Post by arifcsecu »

Remove Now wrong answer
Last edited by arifcsecu on Thu Oct 01, 2009 8:05 am, edited 1 time in total.
Try to catch fish rather than asking for some fishes.

Tuz
New poster
Posts: 1
Joined: Mon Sep 28, 2009 7:12 am

Re: 11686 - Pick up sticks - possible in Java?

Post by Tuz »

you can try this:
struct edge_t
{
int u;
int v;
int next;
};
int first[MAXN];
int tot;
void add_edge(int u, int v)
{
e[++tot].u = u; e[tot].v = v; e[tot].next = first; first = next;
}

Chimed
New poster
Posts: 12
Joined: Mon Oct 20, 2008 10:37 am

Re: 11686 Runtime error Here

Post by Chimed »

arifcsecu wrote:i solve the problem but getting Run Time error
Please any body help me
where the error occured

My code is :
#include<stdio.h>
int main()
{
long int s[1000001][2];
blah blah...
for(i=1;i<=n;i++)
if(s[1]==0)
{
j=i;
break;

}
printf("%ld\n",j);
a=s[j][0];
for(;1;)
{
if(a==0)
break;
printf("%ld\n",a);
a=s[a][0];
}
blah blah...
PLEASE ANY BODY HELP ME


1st. your program stack overflows I suggest you write the declaration of s before the main function.
2nd. does your solution is really correct here is the simple input
3 1
1 2
0 0
Expected answer is
1
2
3
or
3
1
2
or
1
3
2

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 11686 Time Limit exceeded

Post by arifcsecu »

Code romove
After accepted
Last edited by arifcsecu on Tue Oct 06, 2009 8:04 pm, edited 2 times in total.
Try to catch fish rather than asking for some fishes.

ymgve
New poster
Posts: 7
Joined: Mon Oct 15, 2007 1:17 am

Re: 11686 - Pick up sticks - possible in Java?

Post by ymgve »

That doesn't answer the question, though. If you have to reinvent data structures that are already in the language, you're not focusing on the right part of the problem.

MRH
Learning poster
Posts: 51
Joined: Mon Aug 11, 2008 9:09 pm

Re: 11686 Runtime error Here

Post by MRH »

TRY THIS CASE
4 3
4 1
1 2
3 2
MY Acc code give :
3
4
1
2

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

11686 - Pick up sticks

Post by arifcsecu »

remove
Last edited by arifcsecu on Mon Oct 05, 2009 6:43 pm, edited 2 times in total.
Try to catch fish rather than asking for some fishes.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 11686 How can

Post by helloneo »

Try "Topological Sort" :-)

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 11686 How can

Post by arifcsecu »

remove
Last edited by arifcsecu on Tue Oct 06, 2009 6:00 pm, edited 1 time in total.
Try to catch fish rather than asking for some fishes.

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 11686 Time Limit exceeded

Post by arifcsecu »

Code remove
After Accepted
Last edited by arifcsecu on Tue Oct 06, 2009 7:42 pm, edited 1 time in total.
Try to catch fish rather than asking for some fishes.

Igor9669
Learning poster
Posts: 85
Joined: Sun Jun 08, 2008 12:58 pm

Re: 11686 How can

Post by Igor9669 »

Try to change cin/cout to scanf/printf. May be this could help.

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 11686 How can

Post by arifcsecu »

Igor9669 wrote:Try to change cin/cout to scanf/printf. May be this could help.

Thanks
Accpted now
This problem makes me one third mad

Please Can u explain me what does it happen
Try to catch fish rather than asking for some fishes.

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 11686 Runtime error Here

Post by arifcsecu »

MRH wrote:TRY THIS CASE
4 3
4 1
1 2
3 2
MY Acc code give :
3
4
1
2
Thanks
Accepted now
Try to catch fish rather than asking for some fishes.

Igor9669
Learning poster
Posts: 85
Joined: Sun Jun 08, 2008 12:58 pm

Re: 11686 How can

Post by Igor9669 »

scanf/printf use another aproach how to read and how to write data, they are much more faster than cin/cout.

Post Reply

Return to “Volume 116 (11600-11699)”