Skip to content

Instantly share code, notes, and snippets.

@FooBarrior
Created October 23, 2011 16:44
Show Gist options
  • Save FooBarrior/1307569 to your computer and use it in GitHub Desktop.
Save FooBarrior/1307569 to your computer and use it in GitHub Desktop.
south-2011:C. Doesn't work.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
struct Line{
int x1, y1, x2, y2;
bool operator<(const Line &l){
return x1 == x2 ? y1 < l.y1 : x1 < l.x1;
}
Line(istream& is){
is >> x1 >> y1 >> x2 >> y2;
if(x1 > x2) swap(x1, x2);
if(y1 > y2) swap(y1, y2);
}
};
struct Pt{
int h, v, x, y;
int hpos, vpos;
Pt(int h, int v, int hp, int vp, int x, int y):h(h), v(v),hpos(hp), vpos(vp), x(x), y(y){}
friend ostream& operator<<(ostream &os, Pt &p){
return os << p.x << ":" << p.y << " ";
}
};
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n;
cin >> n;
vector<Line> h, v;
for(int i = 0; i < n; i++){
Line l(cin);
(l.y1 == l.y2 ? h : v).push_back(l);
}
sort(h.begin(), h.end());
sort(v.begin(), v.end());
vector<vector<Pt> > hp(h.size()), vp(v.size());
for(int i = 0; i < h.size(); i++){
for(int j = 0; j < v.size(); j++){
Line &hl = h[i], &vl = v[j];
if(hl.x1 <= vl.x1 && hl.x2 >= vl.x2 && vl.y1 <= hl.y1 && vl.y2 >= hl.y2){
Pt p(i, j, hp[i].size(), vp[j].size(), vl.x1, hl.y1);
hp[i].push_back(p);
vp[j].push_back(p);
}
}
}
int cnt = 0;
for(int i = 0; i < hp.size(); i++){
vector<Pt> &hh = hp[i];
for(int j = 0; j < hh.size(); j++){
Pt &p = hh[j];
for(int k = p.hpos + 1; k < hh.size(); k++){
Pt &ph1 = hh[k];
vector<Pt> &vv = vp[ph1.v];
for(int l = ph1.vpos + 1; l < vv.size(); l++){
Pt &pv1 = vv[l];
vector<Pt> &hh2 = hp[pv1.h];
for(int m = 0; m < pv1.hpos; m++){
Pt &ph2 = hh[m];
if(ph2.v == p.v){
cnt++;
//cout << p << ph1 << pv1 << ph2 << endl;
break;
}
}
}
}
}
}
cout << cnt;
return 0;
}
@FooBarrior
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment