Răspuns :
Prima problemă este una foarte, dar foarte, grea și are o rezolvare stufoasă. Numai câțiva elevi știu rezolvarea aceasta. Ai aici sursa:
# include <iostream>
# include <vector>
# include <cmath>
# include <algorithm>
using namespace std;
# define infinity 10000000
struct point {
double x, y;
};
bool cmpX( point a, point b ) {
return a.x < b.x;
}
bool cmpY( point a, point b ) {
return a.y < b.y;
}
double dist( point a, point b ) {
double deltaX = ( a.x - b.x );
double deltaY = ( a.y - b.y );
return sqrt( deltaX * deltaX + deltaY * deltaY );
}
double stripClosest( vector<point> strip, int n, double d ) {
double m = d;
int i, j;
for ( i = 0; i < n; i ++ )
for ( j = i + 1; j < n && ( strip[j].y - strip[i].y) < m; j ++ )
m = min( m, dist( strip[i], strip[j] ) );
return m;
}
double closestUtil( point * px, vector<point> py, int n ) {
if ( n == 1 )
return infinity;
if ( n == 2 )
return dist( px[0], px[1] );
int m = n / 2;
point mid = px[m];
vector<point> pyl, pyr;
pyl.reserve( m + 1 );
pyr.reserve( n - m - 1 );
int i;
for ( i = 0; i < n; i ++ )
if ( py[i].x <= mid.x )
pyl.push_back( py[i] );
else
pyr.push_back( py[i] );
double dl, dr, d;
dl = closestUtil( px, pyl, m );
dr = closestUtil( px + m + 1, pyr, n - m - 1 );
d = min( dr, dl );
vector<point> strip;
for ( i = 0; i < n; i ++ )
if ( abs( py[i].x - mid.x ) < d )
strip.push_back( py[i] );
return min( d, stripClosest( strip, strip.size(), d ) );
}
double closest( point * p, int n ) {
point px[n];
vector<point> py;
py.reserve( n );
int i;
for ( i = 0; i < n; i ++ ) {
p[i].x += 0.000001 * i;
p[i].y += 0.000001 * i;
px[i] = p[i];
py.push_back( p[i] );
}
sort( px, px + n, cmpX );
sort( py.begin(), py.end(), cmpY );
return closestUtil( px, py, n );
}
int main() {
int n, i;
cin >> n;
point p[n];
for ( i = 0; i < n; i ++ ) {
cin >> p[i].x >> p[i].y;
}
double r = closest( p, n );
cout << round( r * 100 + 0.5 ) / 100;
return 0;
}
A doua problema este foarte simplă, ai aici rezolvarea:
# include <iostream>
using namespace std;
int gcd( int a, int b ) {
int r;
while ( b > 0 ) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << gcd( a, gcd( b, c ) );
return 0;
}
# include <iostream>
# include <vector>
# include <cmath>
# include <algorithm>
using namespace std;
# define infinity 10000000
struct point {
double x, y;
};
bool cmpX( point a, point b ) {
return a.x < b.x;
}
bool cmpY( point a, point b ) {
return a.y < b.y;
}
double dist( point a, point b ) {
double deltaX = ( a.x - b.x );
double deltaY = ( a.y - b.y );
return sqrt( deltaX * deltaX + deltaY * deltaY );
}
double stripClosest( vector<point> strip, int n, double d ) {
double m = d;
int i, j;
for ( i = 0; i < n; i ++ )
for ( j = i + 1; j < n && ( strip[j].y - strip[i].y) < m; j ++ )
m = min( m, dist( strip[i], strip[j] ) );
return m;
}
double closestUtil( point * px, vector<point> py, int n ) {
if ( n == 1 )
return infinity;
if ( n == 2 )
return dist( px[0], px[1] );
int m = n / 2;
point mid = px[m];
vector<point> pyl, pyr;
pyl.reserve( m + 1 );
pyr.reserve( n - m - 1 );
int i;
for ( i = 0; i < n; i ++ )
if ( py[i].x <= mid.x )
pyl.push_back( py[i] );
else
pyr.push_back( py[i] );
double dl, dr, d;
dl = closestUtil( px, pyl, m );
dr = closestUtil( px + m + 1, pyr, n - m - 1 );
d = min( dr, dl );
vector<point> strip;
for ( i = 0; i < n; i ++ )
if ( abs( py[i].x - mid.x ) < d )
strip.push_back( py[i] );
return min( d, stripClosest( strip, strip.size(), d ) );
}
double closest( point * p, int n ) {
point px[n];
vector<point> py;
py.reserve( n );
int i;
for ( i = 0; i < n; i ++ ) {
p[i].x += 0.000001 * i;
p[i].y += 0.000001 * i;
px[i] = p[i];
py.push_back( p[i] );
}
sort( px, px + n, cmpX );
sort( py.begin(), py.end(), cmpY );
return closestUtil( px, py, n );
}
int main() {
int n, i;
cin >> n;
point p[n];
for ( i = 0; i < n; i ++ ) {
cin >> p[i].x >> p[i].y;
}
double r = closest( p, n );
cout << round( r * 100 + 0.5 ) / 100;
return 0;
}
A doua problema este foarte simplă, ai aici rezolvarea:
# include <iostream>
using namespace std;
int gcd( int a, int b ) {
int r;
while ( b > 0 ) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << gcd( a, gcd( b, c ) );
return 0;
}
Vă mulțumim pentru vizita pe site-ul nostru dedicat Informatică. Ne dorim ca informațiile furnizate să vă fi fost utile. Dacă aveți întrebări sau aveți nevoie de suport suplimentar, nu ezitați să ne contactați. Revenirea dumneavoastră ne bucură, iar pentru acces rapid, adăugați-ne la favorite!