All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
mahade hasan
Learning poster
Posts: 87 Joined: Thu Dec 15, 2011 3:08 pm
Location: University of Rajshahi,Bangladesh
Post
by mahade hasan » Sat Sep 22, 2012 4:05 pm
brianfry713 wrote: Post your updated code if you want. I took the code you posted most recently, changed the one line as I described, and got AC.
thanks man
its work but can u explain
why gets(Input);produce TLE
and if(gets(Input)==NULL) break;
is accepted
we r surrounded by happiness
need eyes to feel it!
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Sep 25, 2012 1:03 am
Check input and AC output for thousands of problems on
uDebug !
prodhan
New poster
Posts: 2 Joined: Sat Oct 17, 2009 3:07 am
Post
by prodhan » Fri Feb 08, 2013 9:42 pm
I'm getting WA. can anybody help me pls?
Code: Select all
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int par[30];
void make_set(int i)
{
par[i] = i;
}
int find(int r)
{
if(par[r]==r) return r;
else
{
return par[r] = find(par[r]);
}
}
void Union(int a, int b)
{
int u = find(a);
int v = find(b);
if(u==v) return;
else{
par[u] = v;
}
}
int main()
{
int T,u,v,max,i,j,temp,res;
char max_char;
char edge[3];
scanf("%d\n",&T);
while(T--){
while(1){
memset(edge,'\0',sizeof(edge));
gets(edge);
if(strlen(edge)==0) break;
if(strlen(edge)==1){
max_char = edge[0];
max = (int)max_char-64;
for(i=1; i<=max; i++)
make_set(i);
continue;
}
u = (int) edge[0] - 64;
v = (int) edge[1] - 64;
Union(u,v);
}
sort(par+1,par+1+max);
res = 0;
for(i=1; i<max; i++){
if(find(par[i])!=find(par[i+1]))
res++;
}
printf("%d\n",res+1);
if(T)
printf("\n");
}
return 0;
}
Thanks in advance.
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Wed Feb 13, 2013 12:57 am
Check input and AC output for thousands of problems on
uDebug !
AKJ88
New poster
Posts: 20 Joined: Wed Feb 13, 2013 10:48 am
Post
by AKJ88 » Wed Feb 20, 2013 9:04 pm
Hello.
Can anyone tell me what's wrong with my code?
Thanks.
Code: Select all
Code was deleted after getting AC.
Last edited by
AKJ88 on Thu Feb 21, 2013 9:05 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Wed Feb 20, 2013 11:18 pm
From uhunt:
lbv> AKJ88, don't print a blank line after the last test case
Check input and AC output for thousands of problems on
uDebug !
AKJ88
New poster
Posts: 20 Joined: Wed Feb 13, 2013 10:48 am
Post
by AKJ88 » Thu Feb 21, 2013 9:04 pm
lbv & brianfry713, Thanks a lot.
Got AC.
fazel
New poster
Posts: 6 Joined: Fri Aug 02, 2013 4:44 am
Post
by fazel » Tue Aug 06, 2013 7:56 am
i've tried every i/o i found in forums and got predicted answer
but still it gives me Wrong answer
help me for god sake .....
Last edited by
fazel on Mon Sep 09, 2013 3:26 pm, edited 1 time in total.
fazel
New poster
Posts: 6 Joined: Fri Aug 02, 2013 4:44 am
Post
by fazel » Tue Aug 06, 2013 8:07 am
ACC
F***er ,
after the last output must have one endl not more or less
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Sep 10, 2013 1:16 am
Check input and AC output for thousands of problems on
uDebug !
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Wed Sep 11, 2013 1:07 am
Check input and AC output for thousands of problems on
uDebug !
dumle
New poster
Posts: 3 Joined: Mon Sep 16, 2013 9:23 pm
Post
by dumle » Mon Sep 16, 2013 9:33 pm
Why am I getting WA? Ive tried several inputs and cant find anything wrong.
Last edited by
dumle on Thu Sep 19, 2013 10:21 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Sep 17, 2013 12:06 am
Describe your algorithm.
Last edited by
brianfry713 on Tue Sep 17, 2013 10:32 pm, edited 2 times in total.
Check input and AC output for thousands of problems on
uDebug !
dumle
New poster
Posts: 3 Joined: Mon Sep 16, 2013 9:23 pm
Post
by dumle » Tue Sep 17, 2013 10:04 pm
Pretty much:
cin largest node letter, convert to int and insert into a vector
repeat until empty line:
{
getline and split the string into int a, int b
loop thru all vectors and check if a or b is in any vector
if: insert the missing one into the vector
if not: create a new vector with a and b (or only a if they're the same)
loop thru all vectors and check if you can find a or b in two vectors
if: join v and v[i+1] and remove duplicates. Remove v[i+1]
if not: do nothing
}
cout (largest node) - (sum of all vector sizes) + (number of vectors)
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Sep 17, 2013 10:32 pm
Check input and AC output for thousands of problems on
uDebug !