HDOJ2428(Stars)
Stars
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 433 Accepted Submission(s): 156
Problem Description
    Lucy loves stars very much. There are N (1 <= N <= 1000) stars in the sky. Assume the sky is a flat plane. All of the stars lie on it with a location (x, y), -10000 <= x, y <= 10000. Now, Lucy wants you to tell her how many squares with each of four vertices formed by these stars, and the edges of the squares should parallel to the coordinate axes.
Input
    The first line of input is the number of test case.
The first line of each test case contains an integer N. The following N lines each contains two integers x, y, meaning the coordinates of the stars. All the coordinates are different.
The first line of each test case contains an integer N. The following N lines each contains two integers x, y, meaning the coordinates of the stars. All the coordinates are different.
Output
    For each test case, output the number of squares in a single line.
Sample Input
2 1 1 2 4 0 0 1 0 1 1 0 1
Sample Output
0 1
 /*
/* 2009-05-13 16:53:20 Accepted 2428 31MS 264K 1174 B C++
    2009-05-13 16:53:20 Accepted 2428 31MS 264K 1174 B C++  */
*/ #include <iostream>
#include <iostream> #include <set>
#include <set> #include <algorithm>
#include <algorithm> using namespace std;
using namespace std;
 const int N = 1003;
const int N = 1003;
 typedef struct node
typedef struct node {
{ int x, y;
    int x, y; bool operator <(const node tmp) const
    bool operator <(const node tmp) const {
    { if(x != tmp.x)
        if(x != tmp.x) return x < tmp.x;
            return x < tmp.x; else
        else return y < tmp.y;
            return y < tmp.y; }
    } };
};
 node px[N];
node px[N];
 int main()
int main() {
{ 
     int T, n, i, j, k, t;
    int T, n, i, j, k, t; bool flag;
    bool flag; int cntx, cnty;
    int cntx, cnty; node c1, c2;
    node c1, c2; set<node> vv;
    set<node> vv;
 scanf("%d", &T);
    scanf("%d", &T); while(T--)
    while(T--) {
    { vv.clear();
        vv.clear(); scanf("%d", &n);
        scanf("%d", &n); for(i = 0; i < n; i++)
        for(i = 0; i < n; i++) {
        { scanf("%d%d", &px[i].x, &px[i].y);
            scanf("%d%d", &px[i].x, &px[i].y); vv.insert(px[i]);
            vv.insert(px[i]); }
        }
 sort(px, px + n);
        sort(px, px + n);
 i = 0;cntx = 0;
        i = 0;cntx = 0; for(i = 0; i < n;)
        for(i = 0; i < n;) {
        { flag = false;
            flag = false; j = i;
            j = i; while((i + 1) < n && px[i].x == px[i + 1].x)
            while((i + 1) < n && px[i].x == px[i + 1].x) {
            { if(px[i].y != px[i + 1].y)
                if(px[i].y != px[i + 1].y) flag = true;
                    flag = true; i++;
                i++; }
            } if(flag)
            if(flag) {
            { for(k = j ; k <= i; k++)
                for(k = j ; k <= i; k++) for(t = j + 1; t <= i; t++)
                    for(t = j + 1; t <= i; t++) if(px[t].y > px[k].y)
                        if(px[t].y > px[k].y) {
                        { c1 = px[k];
                            c1 = px[k]; c1.x += px[t].y - px[k].y;
                            c1.x += px[t].y - px[k].y;
 c2 = px[t];
                            c2 = px[t]; c2.x += px[t].y - px[k].y;
                            c2.x += px[t].y - px[k].y; 
                             if(vv.find(c1) != vv.end() && vv.find(c2) != vv.end())
                            if(vv.find(c1) != vv.end() && vv.find(c2) != vv.end()) cntx++;
                                cntx++; }
                        } }
            } i++;
            i++; }
        } printf("%d\n", cntx);
        printf("%d\n", cntx); }
    } return 0;
    return 0; }
}

 
                    
                     
                    
                 
                    
                

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号 
