Pagini recente » Cod sursa (job #333273) | Cod sursa (job #579248) | Cod sursa (job #3004260) | Cod sursa (job #1807243) | Cod sursa (job #3270125)
#include <fstream>
#include <iostream>
#include <climits>
#include <cmath>
#include <iomanip>
struct koord{
int x, y;
koord(){
x = 0;
y = 0;
}
koord(int a, int b){
x = a;
y = b;
}
int tavolsag(koord masik){
return ((masik.x - x) * (masik.x - x) + (masik.y - y) * (masik.y - y));
}
};
std::istream & operator>>(std::istream & bem, koord & bemenet){
bem >> bemenet.x >> bemenet.y;
return bem;
}
std::ostream & operator<<(std::ostream & kim, koord & bemenet){
kim << bemenet.x << ' ' << bemenet.y;
return kim;
}
void merge(koord tomb[], int bal, int kozep, int jobb){
int *temp = new int[jobb - bal + 1];
int indexBal = bal, indexJobb = kozep + 1, indexTemp = 0;
while(indexBal <= kozep && indexJobb <= jobb){
if(tomb[indexBal].y <= tomb[indexJobb].y)
temp[indexTemp++] = tomb[indexBal++].y;
else
temp[indexTemp++] = tomb[indexJobb++].y;
}
while(indexBal <= kozep)
temp[indexTemp++] = tomb[indexBal++].y;
while(indexJobb <= jobb)
temp[indexTemp++] = tomb[indexJobb++].y;
for(int i = 0; i < indexTemp; i++)
tomb[bal + i].y = temp[i];
delete [] temp;
return;
}
void sort(koord tomb[], int bal, int jobb, int &minTav){
if(bal >= jobb)
return;
int kozep = (bal + jobb) / 2;
sort(tomb, bal, kozep, minTav);
sort(tomb, kozep + 1, jobb, minTav);
merge(tomb, bal, kozep, jobb);
int tav = tomb[kozep].tavolsag(tomb[kozep + 1]);
if(tav < minTav)
minTav = tav;
return;
}
int main(){
std::ifstream bem("cmap.in");
int n, minTav = INT_MAX;
bem >> n;
koord *tomb = new koord[n];
for(int i = 0; i < n; i++)
bem >> tomb[i];
bem.close();
sort(tomb, 0, n-1, minTav);
std::ofstream kim("cmap.out");
kim << std::fixed << std::setprecision(6) << sqrt(minTav) << '\n';
kim.close();
delete [] tomb;
}