HZAU 1018 Catching Dogs

来源:互联网 发布:mysql ifnull不起作用 编辑:程序博客网 时间:2024/05/19 00:14

题目连接
模拟

#include<iostream> #include<cstdio> #include<cmath> using namespace std; const int maxn = 10 + 10; int n, v0; int v[maxn]; double p[maxn]; void solve() {  double p0 = 0;  double ans = 0;  for(int i = 0; i < n; i++)    scanf("%lf%d", &p[i], &v[i]);  bool flag = true;  for(int i = 0; i < n; i++){    if (v[i] == 0)    {      double t = abs(p0 - p[i])/v0;      ans += t;      p0 = p[i];      for(int j = i + 1; j < n; j++)        p[j] += (v[j] * t);      continue;    }    int s;    if(p[i] == p0) s = 0;    else if((p[i] - p0) * v[i] > 0) s = 1; // zhuiji    else s = 2; //xiangyu    if(s == 1 && abs(v[i]) >= v0) {flag = false; break;}    double t;    if(s == 1)    {      t = abs(p0 - p[i]) / (v0 - abs(v[i]));      p0 += (v[i]/abs(v[i]) * t * v0);    }    else if(s == 2)    {      t = abs(p0 - p[i]) / (v0 + abs(v[i]));      p0 -= (v[i]/abs(v[i]) * t * v0);    }    else t = 0;    ans += t;    for(int j = i + 1; j < n; j++)      p[j] += (v[j] * t);  }  if(flag) printf("%.2lf\n", ans);  else printf("Bad Dog\n"); } int main(){ //freopen("input.txt", "r", stdin);  while(scanf("%d%d", &n, &v0) != EOF)    solve(); }
0 0
原创粉丝点击