题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值
#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; const int MAXN = 1007; const double EPS = 1e-9; struct Point { double x, y, time; }; double Dist(Point a, Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int main() { int T; scanf("%d", &T); while(T--) { int i, N; double ans = 0; Point p[MAXN]; scanf("%d", &N); for(i=0; i<N; i++) { scanf("%lf%lf%lf", &p[i].time, &p[i].x, &p[i].y); if(i == 1) ans = Dist(p[i], p[i-1]) / (p[i].time-p[i-1].time); else if(i > 1) ans = max(ans, Dist(p[i], p[i-1]) / (p[i].time-p[i-1].time)); } printf("%.10f ", ans); } return 0; }
E - Hatsune Miku -
#include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> using namespace std; const int MAXN = 107; const int oo = 1e9+7; int main() { int T; scanf("%d", &T); while(T--) { int i, j, k, N, M; int dp[MAXN][MAXN], a[MAXN], val[MAXN][MAXN]; memset(dp, 0, sizeof(dp)); scanf("%d%d", &N, &M); for(i=1; i<=M; i++) for(j=1; j<=M; j++) scanf("%d", &val[i][j]); for(i=1; i<=N; i++) scanf("%d", &a[i]); for(i=N-1; i>0; i--) { if(a[i] == -1 && a[i+1] == -1) { for(j=1; j<=M; j++) for(k=1; k<=M; k++) dp[i][j] = max(dp[i][j], val[j][k]+dp[i+1][k]); } else if(a[i] == -1) { for(j=1; j<=M; j++) dp[i][j] = max(dp[i][j], val[j][a[i+1]]+dp[i+1][a[i+1]]); } else if(a[i+1] == -1) { for(j=1; j<=M; j++) dp[i][a[i]] = max(dp[i][a[i]], val[a[i]][j]+dp[i+1][j]); } else dp[i][a[i]] = val[a[i]][a[i+1]] + dp[i+1][a[i+1]]; } int ans = 0; for(i=1; i<=M; i++) ans = max(ans, dp[1][i]); printf("%d ", ans); } return 0; }
#include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> using namespace std; const int MAXN = 1e5+7; const int oo = 1e9+7; double loc[MAXN]; int main() { int T; scanf("%d", &T); while(T--) { int i, N, M, K; scanf("%d%d", &N, &K); for(i=0; i<N; i++) scanf("%lf", &loc[i]); sort(loc, loc+N); if(K + 1 >= N) { printf("0 "); continue; } M = N - K; double cnt=0, ans, sum=0; for(i=0; i<M; i++) { cnt += loc[i]; sum += loc[i]*loc[i]; } ans = sum - cnt*cnt/M; for(i=M; i<N; i++) { sum = sum + loc[i]*loc[i] - loc[i-M]*loc[i-M]; cnt = cnt + loc[i] - loc[i-M]; ans = min(ans, sum-cnt*cnt/M); } printf("%.10f ", ans); } return 0; }