638 - Finding Rectangles

All about problems in Volume 6. 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
Denis
New poster
Posts: 2
Joined: Tue Jul 23, 2002 2:07 am
Location: Russia

638 - Finding Rectangles

Post by Denis »

In problem said: "Within each set, points labels occur in alphabetical order".
Code with sorting this labels gives AC, but without WA.

Maybe BUG or I something not understand?!
lowai
New poster
Posts: 48
Joined: Mon Apr 29, 2002 1:26 pm

638 wa

Post by lowai »

any trick there?

[cpp]
#include <fstream.h>

struct Point {
int x, y;
char label;
};

const int MAXSIZE = 26;
const int PERLINE = 10;

int main() {

int caseno = 0, nRect, nPoints, tl, tr, bl, br;

Point pt[MAXSIZE];

cin >> nPoints;
while (nPoints > 0) {
for(int i=0; i < nPoints; i++)
cin >> ws >> pt.label >> pt.x >> pt.y;

caseno++;

cout << "Point set " << caseno <<':';

nRect = 0;

for(tl = 0; tl < nPoints; tl++)
for(tr = 0; tr < nPoints; tr++)
if (pt[tr].y == pt[tl].y && pt[tr].x > pt[tl].x)
for(br = 0; br < nPoints; br++)
if (pt[tr].x == pt[br].x && pt[br].y < pt[tr].y)
for(bl = 0; bl < nPoints; bl++)
if (pt[bl].x == pt[tl].x && pt[bl].y == pt[br].y) {
if (nRect % PERLINE == 0) cout << endl;
nRect++;
cout << ' ' << pt[tl].label << pt[tr].label <<
pt[br].label << pt[bl].label;
}
if (nRect == 0) cout << " No rectangles";
cout << endl;

cin >> nPoints;
}
return 0;
}

[/cpp]
ec3_limz
Learning poster
Posts: 79
Joined: Thu May 23, 2002 3:30 pm
Location: Singapore

Yes there is a trick

Post by ec3_limz »

Hi lowai,

I recently found out that there may be a trick in this problem. I cannot, however, confirm that what I say is correct.

The problem did NOT state that all rectangles must be parallel to the axes. This means that rectangles can be in any "direction", e.g. diamonds.

For example.

SAMPLE INPUT
4
A 0 1
B 1 0
C 2 3
D 3 2

SAMPLE OUTPUT
Point Set 1:
CDBA
Maddas
New poster
Posts: 11
Joined: Sat Apr 03, 2004 1:45 am

638 Why WA?

Post by Maddas »

Hi, my program works fine for the sample input and produces correct output for many random input files I generated (I gave it to a friend who has a program that gives the right answer and his output was the same as my output)

Are there any really tricky test cases? Can points be on top of each other?

Does anybody have any input file to test with and output that I can compare with?

I really don't know where the problem is, any help greatly appreciated,

Maddas
Maddas
New poster
Posts: 11
Joined: Sat Apr 03, 2004 1:45 am

Post by Maddas »

I found the mistake, I don't understand why it didn't work before but it works now. :)
DongJoo Kim
New poster
Posts: 20
Joined: Tue Sep 20, 2005 9:20 am
Location: Daejeon, Korea

Re: 638 why?

Post by DongJoo Kim »

Denis wrote:In problem said: "Within each set, points labels occur in alphabetical order".
Code with sorting this labels gives AC, but without WA.

Maybe BUG or I something not understand?!
You are right.

I finally got AC after I sorted the input. Thanx..

I think the description should be fixed.
DongJoo Kim
New poster
Posts: 20
Joined: Tue Sep 20, 2005 9:20 am
Location: Daejeon, Korea

Re: Yes there is a trick

Post by DongJoo Kim »

ec3_limz wrote:Hi lowai,

I recently found out that there may be a trick in this problem. I cannot, however, confirm that what I say is correct.

The problem did NOT state that all rectangles must be parallel to the axes. This means that rectangles can be in any "direction", e.g. diamonds.

For example.

SAMPLE INPUT
4
A 0 1
B 1 0
C 2 3
D 3 2

SAMPLE OUTPUT
Point Set 1:
CDBA
I think above explanation is FALSE.
I followed your explanation of rectangle. However, what I've got was 10+ WAs. After changing to normal rectangle( rectangle with parallel to X-axis or Y-Axis) I got AC.

In short, in this problem, side of rectangle is always parallel to the X-axis or Y-axis.
lyh91208
New poster
Posts: 4
Joined: Mon Mar 20, 2006 1:26 pm
Location: Taipei

Re: 638 why?

Post by lyh91208 »

DongJoo Kim wrote: I finally got AC after I sorted the input. Thanx..
Sorry, but I don't understand what it means.

Can anyone explain it more?

Thanks.
rezaeeEE
New poster
Posts: 25
Joined: Fri May 11, 2007 3:45 pm

help

Post by rezaeeEE »

i cnat understand this sentence:

"Within each set, points labels occur in alphabetical order"

can any body explain this with a example?

i get wa and i dont know which part of my program is wrong.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: help

Post by Jan »

rezaeeEE wrote:i cnat understand this sentence:

"Within each set, points labels occur in alphabetical order"

can any body explain this with a example?

i get wa and i dont know which part of my program is wrong.
The sentence means that the labels will be given in alphabetical order.

Code: Select all

3
A 1 1
B 2 1
C 3 1
Its a vaid input. but

Code: Select all

3
B 1 1
A 2 1
C 3 1
its not valid, since the label 'B' appears before 'A'.

If your code gets wa then check it again carefully.
Ami ekhono shopno dekhi...
HomePage
rezaeeEE
New poster
Posts: 25
Joined: Fri May 11, 2007 3:45 pm

help

Post by rezaeeEE »

thank u very much mr jan.

for this input:
4
B 1 1
A 0 0
C 1 0
D 0 1

the output must be : No rectangles ??

can u give me some tricky inputs.thanks.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

As I said earlier the input is not valid. So, this type of inputs will not appear in the input file. Its tough to generate cases for this problem. However, you can post your code. Then it would be easier to find the error.
Ami ekhono shopno dekhi...
HomePage
rezaeeEE
New poster
Posts: 25
Joined: Fri May 11, 2007 3:45 pm

help

Post by rezaeeEE »

very very silly mistake.

my program cout << endl 11 perline.

thanks mr jane.
i got accept.
DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 638 - Finding Rectangles

Post by DD »

In this problem, be aware that don't print a extra '\n' when the number of rectangles are times of 10.
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.
Post Reply

Return to “Volume 6 (600-699)”