codeforce Good Bye 2017 C. New Year and Curling 暴力

题目链接
题意:
n个半径为r的球依次落下,给出每个球从高处落下的横坐标,球碰到x轴 或者 碰到之前已经落下的球就会停止运动,要你求出每个球静止时的圆心位置。
解题思路:
落下的横坐标都是整数,然后区间范围只有1000,n^2 的复杂度完全可以接受,想到暴力枚举每个点的状态,然后求出最大值即可。
有个坑点是,不是求出已经静止的球的最高点y,而是要求max(y+dy)。

#include<iostream>
#include<math.h>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define x first
#define y second
using namespace std;
const int MAX=1100;
const int MOD=1e9+7;
class Point {
public:
    double x,y;
};
Point point[MAX];
double hight[MAX];
int thex[MAX];
bool vis[MAX];
int main() {
    int n,rs;
    scanf("%d %d",&n,&rs);
    int dis;
    for(int i=0; i<n; i++) {
        scanf("%d",&dis);
        int l=max(1,dis-rs);
        int r=min(dis+rs,1050);
        double maxs=-1;
        int nowx=0;
        double nowh=rs;
        bool flag=0;
        for(int i=l; i<=r; i++) {
            if(vis[i])
                flag=1;
            maxs=hight[i];
            nowx=thex[i];
            nowh=max(nowh,maxs+sqrt(4*rs*rs-(nowx-dis)*(nowx-dis)));
        }              
        if(flag==0)
            nowh=rs;
        for(int i=l; i<=r; i++) {
            vis[i]=1;
            hight[i]=nowh;
            thex[i]=dis;
        }
        printf("%.6lf ",nowh);
    }
}

猜你喜欢

转载自blog.csdn.net/lifelikes/article/details/78936012
今日推荐