11686 - Pick up sticks
Moderator: Board moderators
11686 - Pick up sticks - possible in Java?
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?
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
11686 Runtime error Here
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.
Re: 11686 - Pick up sticks - possible in Java?
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;
}
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;
}
Re: 11686 Runtime error Here
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
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 11686 Time Limit exceeded
Code romove
After accepted
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.
Re: 11686 - Pick up sticks - possible in Java?
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.
Re: 11686 Runtime error Here
TRY THIS CASE
4 3
4 1
1 2
3 2
MY Acc code give :
3
4
1
2
4 3
4 1
1 2
3 2
MY Acc code give :
3
4
1
2
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
11686 - Pick up sticks
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.
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 11686 How can
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.
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 11686 Time Limit exceeded
Code remove
After Accepted
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.
Re: 11686 How can
Try to change cin/cout to scanf/printf. May be this could help.
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 11686 How can
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.
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 11686 Runtime error Here
ThanksMRH wrote:TRY THIS CASE
4 3
4 1
1 2
3 2
MY Acc code give :
3
4
1
2
Accepted now
Try to catch fish rather than asking for some fishes.
Re: 11686 How can
scanf/printf use another aproach how to read and how to write data, they are much more faster than cin/cout.