求调
  • 板块灌水区
  • 楼主_FarmerJohn_
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/3 22:20
  • 上次更新2024/8/4 08:56:18
查看原帖
求调
628365
_FarmerJohn_楼主2024/8/3 22:20

#include <math.h>
#include <algorithm>
using namespace std;

int n, L, w, x, r, cnt;
struct note {
  double x, y;
} a[15010];

bool cmp(note x, note y) {
  return x.x < y.x;
}

void read() {
  int i;
  cnt = 1;
  scanf("%d%d%d", &n, &L, &w);
  
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &r);
		
    if (r > w / 2) {
      a[cnt].x = x - sqrt(r * r - w * w / 4.0);
      a[cnt].y = x + sqrt(r * r - w * w / 4.0);
      cnt++;
    }
  }
}
void solve() {
  double s, t = 0;
  int ans = 0;
  int i = 1;
  
  while (t < L) {
    s = t;
    
    for (; a[i].x <= s && i <= cnt; i++) {
      if (a[i].y > t)
        t = a[i].y;
    }
    
    if (s == t) {
      printf("-1\n");
      break;
    }
    
    ans++;
  }
  
  if (t >= L)
    printf("%d\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  
  while (t--) {
    read();
    sort(a + 1, a + 1 + cnt, cmp);
    solve();
  }
  
  return 0;
}

2024/8/3 22:20
加载中...