牛客国庆集训派对Day1 A思维 C暴力 E贪心 L最短路

版权声明:本文为博主原创文章,未经博主允许也可以转载。 https://blog.csdn.net/FrankAx/article/details/82918270

A

Code:

#include <bits/stdc++.h>
using namespace std;
const int AX = 1e6 + 66;
int a[AX] ;
map<int,int>mp; 
int main(){
	int a, b, c, d , e , f ;
	cin >> a >> b >> c >> d >> e >> f ; 
	int res = 0 ;
	res += min( a , e ) ;
	res += min( b , f ) ;
	res += min( c , d ) ;
	cout << res << endl;
	return 0 ; 
}

C

Code:

#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
using namespace std;
LL a , b , c , p1 , p2 ,q1, q2 ;
LL f( LL x , LL y ){
	return p2 * x * x + p1 * x + q2 * y * y + q1 * y ;	
}
int main(){
	ios;
	cin >> a >> b >> c ;
	cin >> p1 >> p2 >> q1 >> q2 ;
	LL x , y ; 
	LL d = __gcd( a , b ) ;
	if( c % d ){
		cout << "Kuon" << endl;
	}else{
		LL res = INF ;
		for( LL x = -100000 ; x <= 100000 ; x ++ ){
			y = c - a * x;
			if( y % b ) continue; 
			y /= b ;
			res = min( res , f(x,y) );
		}
		cout << res << endl;
	}
	return 0 ; 
}

E
思路:排序,遍历,小于m的就合并就行了。
Code:

#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
using namespace std;
const int AX = 1e6 + 66;
int d[AX];
int main(){
	ios;
	int n , m ;
	cin >> n >> m ; 
	for( int i = 0 ; i < n ; i++ ){
		cin >> d[i] ; 
	}
	sort( d , d + n ) ; 
	int ans = 0 ;
	for( int i = 1 ; i < n ; i++ ){
		if( d[i] - d[i-1] <= m ){
			ans ++ ; 
		}
	}
	cout << n - ans << endl;
	return 0 ; 
}

L

思路:因为直线上任意走不耗费体力,所以直线到直线距离可以转化成点到点距离。
求出直线到直线距离,圆到圆距离,直线到圆距离,然后从一条直线(一个点)跑最短路到另一条直线。
Code:

#include <bits/stdc++.h>
#define INF 1000000000000.0
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
using namespace std;
const int AX = 1e3 + 66;
int n ; 
double A , B , c1 , c2  ; 
struct Node{
	double x , y , r ; 
}a[AX];
double w[AX][AX];

double cal( double x1 , double y1 , double x2 , double y2 ){
	return ( sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ) ;
}
bool vis[AX];
double dis[AX];
void djistra( int s ){
	n += 2 ;
	for( int i = 1 ; i <= n ; i ++ ) dis[i] = INF;
	dis[s] = 0.0 ; 
	vis[s] = true;
	int pos = s ; 
	for( int i = 1 ; i < n ; i++ ){
		double minus = INF ;
		for( int j = 1 ; j <= n ; j++ ){
			if( !vis[j] && dis[j] < minus ){
				pos = j ; minus = dis[j] ; 
			} 
		}
		vis[pos] = 1 ;
		for( int j = 1; j <= n ; j++ ){
			if( !vis[j] && dis[j] > dis[pos] + w[pos][j] ){
				dis[j] = dis[pos] + w[pos][j] ; 
			}
		}
	}
}

int main(){
	scanf("%d%lf%lf%lf%lf",&n,&A,&B,&c1,&c2);
	for( int i = 1 ; i <= n ; i++ ){
		scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
	} 
	for( int i = 1 ; i <= n ; i++ ){
		for( int j = i + 1 ; j <= n ; j++ ){
			w[i][j] = w[j][i] = max( 0.0 , cal( a[i].x , a[i].y , a[j].x , a[j].y ) - a[i].r - a[j].r );
		}
	}
	for( int i = 1 ; i <= n ; i++ ){
		w[i][n+1] = w[n+1][i] = max( 0.0 , fabs( A*a[i].x + B*a[i].y + c1 ) / sqrt( A*A + B*B ) - a[i].r ) ; 
		w[i][n+2] = w[n+2][i] = max( 0.0 , fabs( A*a[i].x + B*a[i].y + c2 ) / sqrt( A*A + B*B ) - a[i].r ) ; 
	}
	w[n+1][n+2] = w[n+1][n+2] = fabs( c1 - c2 ) / sqrt( A*A + B*B );
	djistra( n + 1 ) ;
	printf("%.6lf\n",dis[n]);
	return 0 ; 
}

猜你喜欢

转载自blog.csdn.net/FrankAx/article/details/82918270