CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • May Cook-Off
    • May Long 2012
    • April Cook-Off
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » April Long Contest » Rectangles Counting

Rectangles Counting

Problem code: RECTCNT

  • All Submissions

All submissions for this problem are available.

Given N separate integer points on the Cartesian plane satisfying: there is no any three of them sharing a same X-coordinate. Your task is to count the number of rectangles (whose edges parrallel to the axes) created from any four of given points.

Input

There are several test cases (ten at most), each formed as follows:

  • The first line contains a positive integer N (N ≤ 105).
  • N lines follow, each containing a pair of integers (each having an absolute value of 109 at most) describing coordinates of a given point.
The input is ended with N = 0.

Output

For each test case, output on a line an integer which is the respective number of rectangles found.

Example

Input:
6
7 1
3 5
3 1
1 5
1 1
7 5
0

Output:
3

Date: 2011-03-08
Time limit: 1s
Source limit: 50000
Languages: TCL PERL6 CLOJ GO PYTH 3.1.2 F# C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK TEXT JS


  • Submit

Comments

  • Login or Register to post a comment.

Are all points different ? I

mkagenius @ 2 Apr 2011 08:43 PM

Are all points different ?

I doubt that.

I hope it is not against the

coders1122 @ 3 Apr 2011 11:57 AM

I hope it is not against the rules to clarify that my accepted solution treats (1,0) (1,0) (2,0) (2,0) as a rectangle.

@admin

I think the input set should have had N distinct points.

how is the answer for test

aseem_pandey @ 3 Apr 2011 01:12 PM

how is the answer for test case 3 ?

i can see only one rectangle (7,1),(7,5),(3,5),(3,1).

(7,1),(7,5),(1,1),(1,5)  is

mkagenius @ 3 Apr 2011 01:15 PM

(7,1),(7,5),(1,1),(1,5)  is another one.

ohh.sorry.... got confused...

aseem_pandey @ 3 Apr 2011 01:23 PM

ohh.sorry....

got confused...

Do we really need to end

AnoopNarang @ 3 Apr 2011 11:32 PM

Do we really need to end input with 0?

oops sorry got it several

AnoopNarang @ 3 Apr 2011 11:32 PM

oops sorry got it several test cases!!

@Admins: Please Correct the

SITZ @ 5 Apr 2011 05:30 PM

@Admins: Please Correct the test cases: (1,0) (1,0) (2,0) (2,0) this kind of points are definitely not rectangles :|

@admin plz ans above

rijin @ 6 Apr 2011 03:47 AM

@admin

plz ans above questions asked.

The first five words of the

triplem @ 6 Apr 2011 07:18 AM

The first five words of the problem statement are:

Given N separate integer points

@Stephen , Thats why everyone

mkagenius @ 6 Apr 2011 09:44 AM

@Stephen , Thats why everyone is puzzled.

The statement does not match with actual data.(As far as I think.)

why isnt O(nlogn) sloution

karan_saxena @ 6 Apr 2011 11:30 AM

why isnt O(nlogn) sloution passing? Its getting timed out. Is there a more efficient way to solve this problem? Need help on this one please.

@  stephen:::can answer be

ritesh_gupta @ 6 Apr 2011 11:32 AM

@  stephen:::can answer be zero also??...suppose if the coordinates are (2,0),(3,1),(4,1),(1,5)  no rectangle are formed ...that means answer will be null...so plz reply...i m vry close

Yes the answer can be zero

karan_saxena @ 6 Apr 2011 11:33 AM

Yes the answer can be zero ...

My solution is giving TLE

manoharsingh23 @ 6 Apr 2011 02:14 PM

My solution is giving TLE just for reading the inputs. If time limits are so strict then how to process the points and get answer.I wonder how  so many correct answers came for this problem??

Will be interesting to see solutions after contest is over.

Is (1,0) (1,0) (2,0) (2,0)

pc_phobia @ 6 Apr 2011 03:43 PM

Is (1,0) (1,0) (2,0) (2,0) case still valid as a rectangle? My program counts it as a good answer at the moment. My program gives good answer on example input. Maybe I have an error somewhere else, but first I need to know if this case if valid or not?

what does source limit 50000

nitin_garg @ 6 Apr 2011 07:05 PM

what does source limit 50000 means? Is it a memory restriction in bytes?

what does source limit 50000

nitin_garg @ 6 Apr 2011 07:05 PM

what does source limit 50000 means? Is it a memory restriction in bytes?

I agree to Manohar Singh... I

linuxfreak @ 6 Apr 2011 11:37 PM

I agree to Manohar Singh... I too just tried reading the input!! and it gives me TLE ... :-o ... time limits always frustrates me on Codechef... :-(

can anyone give me a sample

nitin_garg @ 7 Apr 2011 12:09 AM

can anyone give me a sample input for 1 test cases?

IS

6
7 1
3 5
3 1
1 5
1 1
7 5
0
4
1 1
1 2
0 1
0 2
0

a valid input?

@Nitin .. it's mentioned.. N

linuxfreak @ 7 Apr 2011 12:30 AM

@Nitin .. it's mentioned.. N lines follow, each containing a pair of integers!!! so.. it can be...

Why are the solutions being

pratikmoona @ 7 Apr 2011 05:28 PM

Why are the solutions being rejudged?

There were some test cases

rajiv_adm @ 7 Apr 2011 09:07 PM

There were some test cases that were not matching the problem statement. We modified the test and thus solutions are being rejudged.

will you please give us some

saurabhkr.1989 @ 8 Apr 2011 12:22 AM

will you please give us some more test cases to work out!!

does runtime error comes in

saurabhkr.1989 @ 8 Apr 2011 12:43 AM

does runtime error comes in any other way excpet that mentioned in FAQ??

can this be a testcase? 43 43

sameer @ 8 Apr 2011 11:11 AM

can this be a testcase?

4
3 4
3 3
3 4
3 3
0

@cco no man  "there is no any

rijin @ 8 Apr 2011 03:01 PM

@cco

no man  "there is no any three of them sharing a same X-coordinate"

thanks RIJIN

sameer @ 8 Apr 2011 06:30 PM

thanks RIJIN

can a square formed from 4

sameer @ 9 Apr 2011 09:05 AM

can a square formed from 4 points be counted...

or strictly only quadrangles in which length is greater than height(rectangles) needs to be counted.

please reply..

@ccptrain, Square should be

rajiv_adm @ 9 Apr 2011 10:04 AM

@ccptrain, Square should be counted. Squae is also a rectangle.

# admin : what if the input

sandeepkkothari @ 10 Apr 2011 01:46 AM

# admin : what if the input contains 3 points with same x-coordinate shout it stop executoin of the program i.e. exit or should take another set of inputs ?

@Sandip .. if problem

linuxfreak @ 10 Apr 2011 10:02 AM

@Sandip .. if problem statement states that there would be no such case.. then.. believe them.. it won't be there.. :-)

@Above all who concluded ,

AnoopNarang @ 10 Apr 2011 08:12 PM

@Above all who concluded , its giving TLE while taking input

u r wrong!

i m getting time limit

vickysirwani @ 11 Apr 2011 05:03 PM

i m getting time limit exceeding in my O(n^2) algo..............is there any shorter method for this?

TLE for my code plz suggest

clmathuriya @ 12 Apr 2011 02:58 AM

TLE for my code plz suggest what to do..

#include <stdio.h> #include

ispark_65 @ 15 Apr 2011 12:13 PM

#include <stdio.h>

#include <algorithm>

#include <vector>

#include <map>

using namespace std;

#define PB push_back

#define MP make_pair

typedef pair<int,int> PII;

int main()

{

stdio_base::sync_with_stdio(0);

int n;

printf("%d",n);

while(n)

{

vector<PII> tab;

for(int i = 0;i < n;++i)

{

int a, b;cin >> a >> b;

tab.PB(MP(a, b));

}

if(n < 4) cout << "0n";

else

{

sort(tab.begin(), tab.end());

vector<PII> nowe;

if(tab[0].first == tab[1].first) nowe.PB(tab[0]);

for(int i = 1;i < n - 1;++i)

{

if(tab[i].first == tab[i - 1].first || tab[i].first == tab[i + 1].first) nowe.PB(tab[i]);

}

if(tab[n - 1].first == tab[n - 2].first) nowe.PB(tab[n - 1]);

map<PII,int> m;

for(unsigned int i = 0;i < nowe.size();i += 2)

{

int y1 = min(nowe[i].second, nowe[i + 1].second);

int y2 = max(nowe[i].second, nowe[i + 1].second);

++m[MP(y1, y2)];

}

map<PII,int>::iterator it;

unsigned long long int w = 0;

for(it = m.begin();it != m.end();++it)

{

int x = (*it).second;

w += ((long long)x * (x - 1)) / 2;

}

printf("%d ",w /n);

}

printf("%d",n);

}

return 0;

}

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com