10928 - My Dear Neighbours

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

Moderator: Board moderators

Post Reply
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

Post by Raj Ariyan » Thu Oct 20, 2005 12:04 am

Hi,
Here is the link abt explanation of 10928. Let me know, If u face problem again after see this page. Good Luck.
http://online-judge.uva.es/board/viewtopic.php?t=9112
Some Love Stories Live Forever ....

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Thu Oct 20, 2005 12:44 pm

Sorting isn't necessary, but the output has to be sorted. The most tricky part of this problem is reading the input data correctly. For each test case:
- get a line with P
- get P lines with the descriptions of neighborhoods
- find the index of the line that contains the least amount of numbers (if there are more possible answers, store all of them and output them in increasing order)
- output it
- if this is not the last test case, get a line (the empty line that separates test cases)

Check whether you don't have unnecessary whitespaces in your output.

Try the following test data:

Code: Select all

2
2
1
2

13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4
The correct output:

Code: Select all

1 2
2 3 4 5 6 7 8 9 10
There are no spaces after 2 and 10, there is an end-of-line character after both of them.
Last edited by misof on Thu Oct 20, 2005 11:28 pm, edited 1 time in total.

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Tue May 23, 2006 4:34 pm

You don't need to count the numbers in each line, just count the space!

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

488 WA,PLES HELP

Post by turcse143 » Wed Dec 19, 2007 2:25 pm

:(
here is sample input output: I got WA PLES help? Is there any special case?
input:
4
3
2
1 3
2 1

4
2
3
1 4 2
2 1 3

2
1
2

13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4

output:
1
1 2
1 2
2 3 4 5 6 7 8 9 10
Press any key to continue

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 » Thu Dec 20, 2007 6:34 pm

thanks changing the input technique i got accept
''I want to be most laziest person in the world''

sharath
New poster
Posts: 6
Joined: Tue Sep 16, 2008 9:21 pm

Re: 10928 - My Dear Neighbours

Post by sharath » Tue Sep 16, 2008 9:24 pm

My code below is passing all the test cases mentioned in the thread but getting WA when submitted..

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int a[1000];
int main()
{
int n,p,d,i,min;

char str[1000];

cin>>n;
while (n-- != 0)
{
i = 0;
cin>>p;
min = p-1;
memset(a,0,sizeof(a));

while (p != 0)
{
fgets(str,999,stdin);

istringstream str1(str);
while (str1 >> d)
{
a++;
}
if (a != 0)
{
if (a < min)
{
min = a;
}
i++;
p--;
}

}
for (i=0;i<1000;i++)
{
if (a == min)
{
cout<<i+1<<" ";
}
}

cout<<endl;
}
return 0;
}

What is the mistake??

mukit
New poster
Posts: 48
Joined: Wed Nov 21, 2007 10:09 am
Location: Dhaka , Bangladesh
Contact:

Re: 10928 - My Dear Neighbours

Post by mukit » Mon Dec 22, 2008 12:41 pm

I'm getting WA in this problem :(
Please give some I/O.

Code: Select all

Got Acc ...
Thank's in advance.

mukit
New poster
Posts: 48
Joined: Wed Nov 21, 2007 10:09 am
Location: Dhaka , Bangladesh
Contact:

Re: 10928 - My Dear Neighbours

Post by mukit » Mon Dec 22, 2008 1:07 pm

Ok forget that. Got AC. But one thing...
for misof's input

Code: Select all

2
2
1
2

13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4
output will be,

Code: Select all

1 2
2 3 4 5 6 7 8 9 10

So just a newline '\n' (not a blank line) after every case including the last one.

Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh
Contact:

Re: 10928 - My Dear Neighbours

Post by Shafaet_du » Sat Sep 11, 2010 9:09 pm

Too easy a problem. Dont need to make the thinks complex,just count inputs in every line,index them and find out the lowes value. then print the ouputs.
Only one space will separate the outputs,which makes the problem even more easier.

if you still get wa,check this IO:

Code: Select all

2

8
2
4 3
1 2 3
2 1 3 4
1 2 3 4 5
5 3 1 3 5 
2
5

12
11 10 9
1 2 3
1 2 3 4
5 6 7 8
4 3 1 2
11 9 3
1 2 3 4 5 6 7 8 9
1 2 10 9 8 7
1 2 3 4
6 7 8
5 4 3
1 2 3 4 5
Output from my ac code:

Code: Select all

1 7 8
1 2 6 10 11

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10928 - My Dear Neighbours

Post by DD » Fri Mar 18, 2011 3:34 am

sharath wrote:My code below is passing all the test cases mentioned in the thread but getting WA when submitted..

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int a[1000];
int main()
{
int n,p,d,i,min;

char str[1000];

cin>>n;
while (n-- != 0)
{
i = 0;
cin>>p;
min = p-1;
memset(a,0,sizeof(a));

while (p != 0)
{
fgets(str,999,stdin);

istringstream str1(str);
while (str1 >> d)
{
a++;
}
if (a != 0)
{
if (a < min)
{
min = a;
}
i++;
p--;
}

}
for (i=0;i<1000;i++)
{
if (a == min)
{
cout<<i+1<<" ";
}
}

cout<<endl;
}
return 0;
}

What is the mistake??

The size of str is not enough. The number of neighbors in this problem will not exceed 1000 but the length of each line may exceed. You should get A.C. once you enlarge the length of str. :wink:
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?
If so, you need to read Elements of Programming Interviews.

Farsan
New poster
Posts: 34
Joined: Fri Aug 12, 2011 6:37 am

Post by Farsan » Fri Aug 12, 2011 6:55 am

misof wrote:Sorting isn't necessary, but the output has to be sorted. The most tricky part of this problem is reading the input data correctly. For each test case:
- get a line with P
- get P lines with the descriptions of neighborhoods
- find the index of the line that contains the least amount of numbers (if there are more possible answers, store all of them and output them in increasing order)
- output it
if this is not the last test case, get a line (the empty line that separates test cases)[/even for the last test case you have 2 print a new line all u have 2 worry about is whitespaces]

Check whether you don't have unnecessary whitespaces in your output.

Try the following test data:

Code: Select all

2
2
1
2

13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4
The correct output:

Code: Select all

1 2
2 3 4 5 6 7 8 9 10
There are no spaces after 2 and 10, there is an end-of-line character after both of them.

moxlotus
New poster
Posts: 31
Joined: Sat Sep 17, 2011 6:47 am

Re: 10928 - My Dear Neighbours

Post by moxlotus » Sun Aug 17, 2014 10:34 am

Runtime Error on my following code. Can someone tell me why?

AC'ed
Last edited by moxlotus on Thu Dec 04, 2014 8:05 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10928 - My Dear Neighbours

Post by lighted » Mon Aug 18, 2014 6:35 pm

Increase array limit

Code: Select all

char *str = new char[size];
It must be

Code: Select all

char *str = new char[size + 1];
You will get PE. Don't print extra space after last number.

Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10928 - My Dear Neighbours

Post by uDebug » Fri Mar 13, 2015 12:55 pm

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 109 (10900-10999)”