## 10933 - Volleyball

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

polone
New poster
Posts: 43
Joined: Sun May 08, 2005 2:31 am
Location: Taiwan

### 10933 - Volleyball

now in a long wa list ..

could someone offer some I/O?

thanks

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Its tough to generate critical I/O from this problem. However, did you consider I/O like the following..

Input:

Code: Select all

``````3
Team1
Team2
Team 3
3
Team1-Team2: 25-19 25-20 25-23
Team1-Team 3: 1-25 2-25 3-25
Team2-Team 3: 25-21 31-29 29-31 29-31 33-35

3
c
b
a
6
a-b: 25-19 25-20 25-23
b-a: 25-19 25-20 25-23
b-c: 25-19 25-20 25-23
c-a: 25-19 25-20 25-23
a-c: 25-19 25-20 25-23
c-b: 25-19 25-20 25-23

0``````
Output:

Code: Select all

``````Team 3                  2    4       222
Team1                   1    0        81
Team2                   0   -4       209

a                       2    0       274
b                       2    0       274
c                       2    0       274``````
Hope it helps...
Ami ekhono shopno dekhi...
HomePage

polone
New poster
Posts: 43
Joined: Sun May 08, 2005 2:31 am
Location: Taiwan
yes I've considered that

but still..

how did you determin which team to win?

I used score 1 > score 2

not knowing if it'll be right

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
A team win a match if it has won 3 sets. There will at most 5 sets per match. There are no draws. A team wins a set if it has made 25 or more points and the other team is at least two points behind.
I dont understand what u meant by score. However there are some test cases below...

Input:

Code: Select all

``````3
Team1
Team2
Team 3
3
Team1-Team2: 25-23 24-20 22-25 10-30 12-90
Team1-Team 3: 1-25 2-25 3-25
Team2-Team 3: 25-21 31-29 29-31 29-31 33-35

3
c
b
a
6
a-b: 24-19 25-24 37-23 40-11 42-12
b-a: 25-19 25-20 25-24 11-25 11-29
b-c: 25-24 25-20 25-23 25-12 25-11
c-a: 25-26 25-27 27-23 30-11 35-12
a-c: 25-19 25-20 25-23
c-b: 25-19 25-20 25-23

0
``````
Output:

Code: Select all

``````Team 3                  2    4       222
Team2                   1    1       335
Team1                   0   -5        99

a                       2    4       459
c                       2   -2       369
b                       1   -2       373``````
If your code returns same, you can post your code.
Ami ekhono shopno dekhi...
HomePage

polone
New poster
Posts: 43
Joined: Sun May 08, 2005 2:31 am
Location: Taiwan
thanks for your reply

but I still getting wa

here's my code

my hobbit is so bad~

Code: Select all

``````solved :)
``````
Last edited by polone on Sun Oct 16, 2005 4:17 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Just revise your code and you will get the error!! Ok I m telling it.

This is your cmp function

Code: Select all

``````int cmp(const void *a,const void *b)
{
ttt aa=*(ttt*)a,bb=*(ttt*)b;
if(aa.wm!=bb.wm)
return bb.wm-aa.wm;
if(aa.wp!=bb.wp)
return bb.wp-aa.wp;
if(aa.wm!=bb.wm)   // got it!!! should be (aa.ws!=bb.ws)
return bb.ws-aa.ws;
return strcmp(aa.name,bb.name);
} ``````
I think the rest are correct. Good luck.
Ami ekhono shopno dekhi...
HomePage

polone
New poster
Posts: 43
Joined: Sun May 08, 2005 2:31 am
Location: Taiwan
oh!!

thanks for your reply~

I think that I should make more efforts last time

thank you

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
You are welcome. Select the edit option and remove your code.
Ami ekhono shopno dekhi...
HomePage

Bj
New poster
Posts: 24
Joined: Mon Oct 17, 2005 1:39 am
Location: Sweden
Anyone have some more test cases? My program handles all the examples in this thread and some mangled ones, such as:

Code: Select all

``````
3

Team1
Team2
Team 3
3
Team1-Team2   :    25-23	24-20 22-25 10-30 12-90
Team1-Team 3: 1-25 2-25 3-25
Team2-Team 3: 25-21 31-29 29-31 29-31 33-35

3

c
b
a

6

a - b   : 24  - 19   25-  24   37-23 40-11 42-12
b-a  : 25-19 25-20 25-24 11-25 11-29
b-c : 25-24 25-20 25-23 25-12 25-11
c-a:25-26 25-27 27-23 30-11 35-12
a-c:25-19 25-20 25-23
c-b:25-19 25-20 25-23

0
``````
Thanks!
[url=http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:12139]My profile.[url] (Registered later than July 2005).

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
There are no inputs like you given above. I think the problem is else where. You can post your code.
Ami ekhono shopno dekhi...
HomePage

Bj
New poster
Posts: 24
Joined: Mon Oct 17, 2005 1:39 am
Location: Sweden

Code: Select all

``````
/*
* safe input parsing. will always return the next integer from stdin if there is one.
* will disregard newlines, empty lines, spaces, tabs etc.
**/
int getinteger()
{
char row[10240];
do
{
gets(row);
char *p = row;
char foundint = 0;
while(*p != NULL)
{
if(*p >= '0' && *p <= '9')
{
foundint = 1;
break;
}
p++;
}

if(foundint == 1)
{
int d;
sscanf(row, "%d", &d);
return d;
}
} while(1);
}

/*
* safe input parsing. will always return the next line from stdin if there is one.
* will disregard newlines, empty lines, spaces, tabs etc.
**/
void getstring(char *t)
{
char row[10240];
do
{
gets(row);
char *p = row;
char foundstring = 0;
while(*p != NULL)
{
if((*p != ' ') && (*p != '\t') && (*p != '\n') && (*p != '\r'))
{
foundstring = 1;
break;
}
p++;
}
if(foundstring == 1)
{
strcpy(t, row);
return;
}
} while(1);
}

/*
* safe sscanf-style parsing of unsigned integers from a c-string
**/
void getintegers(char *row, int *nums, int &count)
{
count = 0;
int num1 = 0;
char hasnum = 0;
char *p = row;
while(*p != NULL)
{
if(*p >= '0' && *p <= '9')
num1 *= 10, num1 += (*p - '0'), hasnum = 1;
else {
if(hasnum == 1)	{
//cout << num1 << endl;
nums[count++] = num1;
hasnum = 0;
}
num1 = 0;
}
p++;
}
if(hasnum == 1)	{
//cout << num1 << endl;
nums[count++] = num1;
hasnum = 0;
}
}

/*
* safe white-space pruning. will remove spaces, tabs and newlines/carriage returns
* from the beginning and end of a c-string.
**/
void prunews(char *s)
{
char *i = s;
char *f = s;
char *p = s;
while(*p != NULL)
if((*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n'))
p++;
else
break;
while(*p != NULL)
*f++ = *p++;
*f = 0;
while(f != i)
if((*f == ' ') || (*f == '\t') || (*f == '\r') || (*f == '\n') || (*f == 0))
*f-- = 0;
else
break;
}

struct match {
int wins;
int loses;
int points;
int realwins;
int temp;
string name;
};

class comp
{
public:
int operator()(match a, match b)
{
if((a.realwins==b.realwins) && ((a.wins-a.loses)==(b.wins-b.loses)) && (a.points==b.points))
return strcmp(a.name.c_str(), b.name.c_str());
if((a.realwins==b.realwins) && ((a.wins-a.loses)==(b.wins-b.loses)))
return (a.points > b.points);
if(a.realwins==b.realwins)
return ((a.wins-a.loses) > (b.wins-b.loses));
return (a.realwins > b.realwins);
}
};

int main()
{
char row[10240];
int integers[5000];
match clear;
char printlinebreak = 0;

while(1)
{
clear.wins=clear.loses=clear.points=clear.realwins=clear.temp=0;

map<string,int> indexes;
vector<match> teams2;

int n = getinteger();
if(n == 0)
break;

// only print newline _between_ data sets.
if(printlinebreak == 1)
printf("\n");
printlinebreak = 1;

// parse teams
int t = n;
while(t--)
{
char team[64];
getstring(team);
prunews(team);

clear.name = team;
indexes[clear.name] = (int)teams2.size();
teams2.insert(teams2.end(), clear);
}
int x = getinteger();
int xn = x;

// parse results
while(xn--)
{
getstring(row);
char *p = row;
char team1[40], team2[40];
char *t;
t = team1; while(*p != '-') *t++ = *p++; p++; *t = 0;
t = team2; while(*p != ':') *t++ = *p++; p++; *t = 0;

prunews(team1);
prunews(team2);

int c = 0;
getintegers(p, integers, c);

int t1s = indexes[string(team1)];
int t2s = indexes[string(team2)];
for(int q = 0; q < c; q += 2)
{
int sa = integers[q], sb = integers[q+1];
//cout << sa << "-" << sb << endl;

teams2[t1s].points += sa;
teams2[t2s].points += sb;
if((sa >= 25) && (sb <= (sa - 2)))
{
teams2[t1s].wins++;
teams2[t1s].temp++;
teams2[t2s].loses++;
}
if((sb >= 25) && (sa <= (sb - 2)))
{
teams2[t2s].wins++;
teams2[t2s].temp++;
teams2[t1s].loses++;
//cout << teams2[t2s].temp << endl;
}
}
if(teams2[t1s].temp >= 3)
{
teams2[t1s].realwins++;
//teams2[t1s].temp = 0;
//teams2[t2s].temp = 0;
}
if(teams2[t2s].temp >= 3)
{
teams2[t2s].realwins++;
//teams2[t2s].temp = 0;
//teams2[t1s].temp = 0;
}

teams2[t1s].temp = 0;
teams2[t2s].temp = 0;
}

sort(teams2.begin(), teams2.end(), comp());

for(int i = 0; i < teams2.size(); i++)
printf("%-20s%5d%5d%10d\n", teams2[i].name.c_str(), teams2[i].realwins,
(teams2[i].wins - teams2[i].loses),
teams2[i].points);
}
return 0;
}

``````
[url=http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:12139]My profile.[url] (Registered later than July 2005).

Pier
New poster
Posts: 38
Joined: Thu Mar 27, 2003 9:12 pm
Location: Aguascalientes, Mexico
Contact:
After several WA I discovered some thing that might be helpful:

There are no inputs like the above

Code: Select all

``````3
c
b
a
6
a-b: 24-19 25-24 37-23 40-11 42-12
b-a: 25-19 25-20 25-24 11-25 11-29
b-c: 25-24 25-20 25-23 25-12 25-11
c-a: 25-26 25-27 27-23 30-11 35-12
a-c: 25-19 25-20 25-23
c-b: 25-19 25-20 25-23

0
``````
First because one of the teams will have 25 points or more (unlike 24-19) and the point difference will be more than one (unlike 25-24). Also, there are no draws (unlike match b-a).

The problem I had with the input (and other Pascal users might have as well) is that there might be trailing spaces. Example (change '_' for spaces):

Code: Select all

``````c-b: 25-19 25-20 25-23________
``````
There are 10 kind of people on this world: those who understand binary and those who don't!

windows2k
Experienced poster
Posts: 136
Joined: Sat Apr 05, 2003 3:29 pm
Location: Taiwan
Hello
I got WA in the problem all the time.
But I can't found any bug in my code.
Could someone give more input/output?
Thx

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

"%-20s%5d%5d%10d\n"

but I get PE - now that it matters, how do I get AC instead? Thanks!

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Larry wrote:I use this for formatting:
"%-20s%5d%5d%10d\n"
Your formation is correct. Did you consider this?
Output a blank line after each cup result
Hope it helps.
Ami ekhono shopno dekhi...
HomePage