Pagini recente » Cod sursa (job #2770083) | Cod sursa (job #2126277) | Cod sursa (job #2976257) | Cod sursa (job #2691368) | Cod sursa (job #2872787)
#include <fstream>
#include <cmath>
#include <set>
using namespace std;
ifstream in("patrate3.in");
ofstream out("patrate3.out");
int const NMAX = 1000;
pair <int, int> point[1 + NMAX];
set <pair <int, int> > isPoint;
bool isUpperSquare(pair <int, int> a, pair <int, int> b) {
if(a.second == b.second) {
int lat = abs(a.first - b.first);
auto c = isPoint.find({a.first, a.second + lat});
auto d = isPoint.find({b.first, b.second + lat});
if(c != isPoint.end() && d != isPoint.end()){
return true;
}
}else {
int flat = (b.first - a.first), slat = abs(b.second - a.second);
auto c = isPoint.find({a.first + slat, a.second + flat});
auto d = isPoint.find({b.first + slat, b.second + flat});
if(c != isPoint.end() && d != isPoint.end()){
return true;
}
}
return false;
}
int readNumber() {
int ans = 0;
char ch;
while(in >> ch && ch != '.'){
ans = ans * 10 + ch - '0';
}
for(int i = 0;i < 4;i++){
in >> ch;
ans = ans * 10 + ch - '0';
}
return ans;
}
int main() {
int n;
in >> n;
for(int i = 1;i <= n;i++) {
point[i].first = readNumber();
point[i].second = readNumber();
isPoint.insert(point[i]);
}
int ans = 0;
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++){
if(point[i].first < point[j].first && (point[j].second - point[i].second) / (point[j].first - point[i].first) <= 0 && isUpperSquare(point[i], point[j])){
ans++;
}
}
}
out << ans;
return 0;
}