638 - Finding Rectangles
Moderator: Board moderators
638 - Finding Rectangles
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?!
Code with sorting this labels gives AC, but without WA.
Maybe BUG or I something not understand?!
638 wa
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]
[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]
Yes there is a trick
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 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
638 Why WA?
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
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
-
- New poster
- Posts: 20
- Joined: Tue Sep 20, 2005 9:20 am
- Location: Daejeon, Korea
Re: 638 why?
You are right.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?!
I finally got AC after I sorted the input. Thanx..
I think the description should be fixed.
-
- New poster
- Posts: 20
- Joined: Tue Sep 20, 2005 9:20 am
- Location: Daejeon, Korea
Re: Yes there is a trick
I think above explanation is FALSE.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 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.
Re: 638 why?
Sorry, but I don't understand what it means.DongJoo Kim wrote: I finally got AC after I sorted the input. Thanx..
Can anyone explain it more?
Thanks.
Re: help
The sentence means that the labels will be given in alphabetical order.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.
Code: Select all
3
A 1 1
B 2 1
C 3 1
Code: Select all
3
B 1 1
A 2 1
C 3 1
If your code gets wa then check it again carefully.
Ami ekhono shopno dekhi...
HomePage
HomePage
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
HomePage
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 638 - Finding Rectangles
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?