450 - Little Black Book

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

Mahmud776
New poster
Posts: 22
Joined: Mon Dec 22, 2003 9:29 am
Location: Canada

Not Specified

Post by Mahmud776 » Sun Feb 15, 2004 9:57 pm

:oops: :(

Hello Everybody,
What will be the highest size for the every input line and what will
be the highest number for the total persons.


Please tell me.I am in confusions.

:( :(

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Mon Feb 16, 2004 12:26 am

I used 8192 for line input, 8192 for max number of people, and 128 for each individual field. Way more than enough I bet.

Bug!
New poster
Posts: 24
Joined: Thu Oct 30, 2003 10:19 am

need help -> 450-TLE

Post by Bug! » Tue Apr 20, 2004 9:43 am

I try to solve this prob but i still get TLE :cry: , anyone can help me pls??
here's my code:
*code deleted*
Thanx,
Andre :wink:

Bug!
New poster
Posts: 24
Joined: Thu Oct 30, 2003 10:19 am

Now WA

Post by Bug! » Fri Apr 23, 2004 7:08 am

I change my code, and it save me from TLE. But now i got WA with this problem.... Is my algorithm wrong???
Here's my code
*got AC now*
Cheers,
Andre
Last edited by Bug! on Tue Jul 20, 2004 3:49 am, edited 1 time in total.

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Max peeps.

Post by _.B._ » Mon May 31, 2004 5:53 am

Greetings!.
I used 4100 for maximun number of people.
Ah!, and since I used BubbleSort, and got TLE, I used 2 books, one for 'A' to 'L', and one for 'M' to 'Z', and got ACed :D. You may try QuickSort if you want, but I didn't want to change the sorting 8)
Keep posting!.
_.

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Sun Jul 18, 2004 1:51 pm

I increased the size of arrays in the struct to 300, and the code got AC. :wink:

Bug!
New poster
Posts: 24
Joined: Thu Oct 30, 2003 10:19 am

Post by Bug! » Tue Jul 20, 2004 3:42 am

Argh.... Finally I got AC with this prob.... Thx a lot Shamim.... :wink:
Cheers..
Andre

wolf
New poster
Posts: 34
Joined: Sun Aug 22, 2004 4:20 am
Location: Poland

Post by wolf » Wed Aug 25, 2004 1:56 pm

Hi !
What's wrong with my code, I have "Invalid memory reference", but it works on my machine !

[cpp]
#include <iostream>
#include <string>
#include <stdio.h>
//#include <conio.h>

using namespace std;

int n,m,k,i,j;
char dep[60],os[309];

struct person
{
char title[20],name[50],lastname[50],adress[70],hphone[20],wphone[20],campusbox[10],department[60];
} dane[250],temp;

void save()
{
strcpy(dane[j].department,dep);
k=0;
for (m=0;;k++,m++)
{
if (os[k]==',') break;
dane[j].title[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].name[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].lastname[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].adress[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].hphone[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].wphone[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==0) break;
dane[j].campusbox[m]=os[k];
}
}

void sort_me()
{
j--;
for (k=0;k<=j;k++)
for (m=0;m<j;m++)
{
if (strcmp(dane[m].lastname,dane[m+1].lastname)>0)
{
temp=dane[m];
dane[m]=dane[m+1];
dane[m+1]=temp;
}
}
}

void display()
{
for (k=0;k<=j;k++)
{
cout << "----------------------------------------\n";
cout << dane[k].title << " " << dane[k].name << " " << dane[k].lastname << endl;
cout << dane[k].adress << endl;
cout << "Department: " << dane[k].department << endl;
cout << "Home Phone: " << dane[k].hphone << endl;
cout << "Work Phone: " << dane[k].wphone << endl;
cout << "Campus Box: " << dane[k].campusbox << endl;
}
}

int main()
{
scanf("%d\n",&n);
j=0;
for (i=0;i<n;i++)
{
gets(dep);
for (;;j++)
{
if (gets(os)==NULL) break;
if (os[0]==0) break;
save();
}
}
sort_me();
display();
//getch();
return 0;
}
[/cpp]

The method of sorting is very simple (maybe I'll have a TLE later), but this is only test now.

User avatar
tetuya
New poster
Posts: 14
Joined: Thu May 27, 2004 2:31 pm

Post by tetuya » Thu Aug 26, 2004 5:55 pm

hello wolf

why don't you append '\0' at the last of string?
sorry for my poor English.

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Thu Aug 26, 2004 7:22 pm

You may have to increase the size of your arrays.. there may be more than 250 people [and each string may or may not be longer than your limits].. there's no limits stated in the problem which kind of sucks having to guess at them..

wolf
New poster
Posts: 34
Joined: Sun Aug 22, 2004 4:20 am
Location: Poland

Post by wolf » Thu Aug 26, 2004 11:26 pm

Thx, now time to do the quicksort (TLE)

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Fri Aug 27, 2004 9:30 am

One useful hint (I got Accepted now this problem):

In input is more than one test case :(

Best ragards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Ivo Sluganovic
New poster
Posts: 12
Joined: Tue Sep 21, 2004 10:08 pm

450 (Little Black Book) LIMITS? PLZ HLP!!!

Post by Ivo Sluganovic » Wed Nov 03, 2004 9:48 pm

Can someone who got AC tell me what limits did he use for
Number of people and Maximum length of their names, adresses...

I keep on getting SIGSEGV no matter what limits I use.

Is it OK if I sort people using the implemented Qsort in C?

jhonny_yang
New poster
Posts: 22
Joined: Fri Jan 17, 2003 8:24 am

450 Grazy

Post by jhonny_yang » Thu Dec 16, 2004 5:23 pm

I almost get grazy about this easy problem

[c]
#include <stdio.h>
#include <string.h>

typedef struct{
char name[80];
char country[80];
char department[80];
char homephone[80];
char workphone[80];
char campusbox[80];
}DataStruct;

void Swap(DataStruct *a, DataStruct *b)
{
DataStruct temp;
strcpy(temp.campusbox,a->campusbox);
strcpy(temp.country,a->country);
strcpy(temp.department,a->department);
strcpy(temp.homephone,a->homephone);
strcpy(temp.name,a->name);
strcpy(temp.workphone,a->workphone);

strcpy(a->campusbox,b->campusbox);
strcpy(a->country,b->country);
strcpy(a->department,b->department);
strcpy(a->homephone,b->homephone);
strcpy(a->name,b->name);
strcpy(a->workphone,b->workphone);

strcpy(b->campusbox,temp.campusbox);
strcpy(b->country,temp.country);
strcpy(b->department,temp.department);
strcpy(b->homephone,temp.homephone);
strcpy(b->name,temp.name);
strcpy(b->workphone,temp.workphone);
}

int partition(DataStruct *s, int l, int h)
{
int i;
int p;
int firsthigh;

p = h;
firsthigh = l;
for (i=l; i<h; i++)
if (strcmp(s.name,s[p].name)<0){
Swap(&s,&s[firsthigh]);
firsthigh ++;
}
Swap(&s[p],&s[firsthigh]);

return(firsthigh);
}

void qsort(DataStruct *s, int l, int h)
{
int p;

if ((h-l)>0) {
p = partition(s,l,h);
qsort(s,l,p-1);
qsort(s,p+1,h);
}
}

int main()
{
int n,i,j,k;
DataStruct Buffer[80];
char buff[4200],*temp,department[4000];

scanf("%d\n",&n);

k=0;

while (gets(buff)){
strcpy(department,buff);

while (temp=gets(buff)){
if (strlen(buff)==0)break;
strcpy(Buffer[k].department,department);
i=0;j=0;
while (buff!=','){
Buffer[k].name[j++]=buff[i++];
}
Buffer[k].name[j++]=' ';++i;

while (buff!=','){
Buffer[k].name[j++]=buff[i++];
}
Buffer[k].name[j++]=' ';++i;

while (buff!=','){
Buffer[k].name[j++]=buff[i++];
}
Buffer[k].name[j++]=0;++i;

j=0;
while (buff!=','){
Buffer[k].country[j++]=buff[i++];
}
Buffer[k].country[j++]=0;++i;

j=0;
while (buff!=','){
Buffer[k].homephone[j++]=buff[i++];
}
Buffer[k].homephone[j++]=0;++i;

j=0;
while (buff!=','){
Buffer[k].workphone[j++]=buff[i++];
}
Buffer[k].workphone[j++]=0;++i;

j=0;
while (buff){
Buffer[k].campusbox[j++]=buff[i++];
}
Buffer[k].campusbox[j++]=0;++i;
++k;
}
if (temp==0)break;
}

qsort(Buffer,0,k-1);

for (i=0;i<k;i++){
printf("----------------------------------------\n");
printf("%s\n",Buffer.name);
printf("%s\n",Buffer[i].country);
printf("Department: %s\n",Buffer[i].department);
printf("Home Phone: %s\n",Buffer[i].homephone);
printf("Work Phone: %s\n",Buffer[i].workphone);
printf("Campus Box: %s\n",Buffer[i].campusbox);
}

return 0;
}
[/c]

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry » Thu Dec 16, 2004 6:12 pm

Why did you write your own qsort?

Not saying it's wrong, but more chances to be wrong..

Post Reply

Return to “Volume 4 (400-499)”