Pagini recente » Cod sursa (job #1624641) | Cod sursa (job #316543) | Cod sursa (job #2716991) | Cod sursa (job #705520) | Cod sursa (job #2751075)
use std::fs::File;
use std::io::{*};
use std::collections::HashSet;
fn makes_square(x : &(i32, i32), y : &(i32, i32), set : &HashSet<(i32, i32)>) -> bool {
let xmid = (x.0 + y.0) / 2;
let ymid = (x.1 + y.1) / 2;
let dx = xmid - x.0;
let dy = ymid - x.1;
let a = (xmid - dy, ymid + dx);
let b = (xmid + dy, ymid - dx);
if set.contains(&a) && set.contains(&b) {
return true;
}
return false;
}
fn main() {
let mut set : HashSet<(i32, i32)> = HashSet::new();
let mut input = BufReader::new(File::open("patrate3.in").unwrap());
let mut output = BufWriter::new(File::create("patrate3.out").unwrap());
let mut line = String::new();
input.read_line(&mut line).unwrap();
let n : usize = line.trim().parse().unwrap();
let mut points : Vec<(i32, i32)> = Vec::new();
for _i in 0..n {
let mut line = String::new();
input.read_line(&mut line).unwrap();
let vars : Vec<f64> = line.split(" ").map(|x| x.trim().parse().unwrap()).collect();
let x : i32 = (vars[0] * 10000.0).round() as i32;
let y : i32 = (vars[1] * 10000.0).round() as i32;
points.push((x, y));
}
for pr in &points {
set.insert(*pr);
}
let mut counter : usize = 0;
for i in 0..n {
for j in i+1..n {
if i != j && makes_square(&points[i], &points[j], &set) {
counter = counter + 1;
}
}
}
writeln!(output, "{}", counter / 2).unwrap();
}