题意理解
这就是无脑模拟一下,注意的是,每秒一开始的时候,就要检测。也就是说,第0秒的开始,就要检测一波。
代码
#include <cstring>
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
void read(int &x) {
x = 0;
int f = 1;
char ch = getchar();
while(ch > '9'||ch < '0') {
if(ch == '-') {
f = -1;
}
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = x * 10 + (int)(ch - 48);
ch = getchar();
}
x = x * f;
}
int main() {
int s, x;
read(s);
read(x);
int left = s - x;
int right = s + x;
double distance = 7;
double total = 0;
int cnt = 0;
int times = 0;
while(true) {
times++;
if(times > 200) {
break;
}
if(left <= total && total <= right) {
cnt++;
}
total += distance;
distance *= 0.98;
}
if(cnt >= 2) {
printf("y");
} else {
printf("n");
}
return 0;
}
欢迎加入“不会算法一群菜鸟”,群号是⑥⑥①⑨②2025,这是我设置的一道很低的门槛用来阻止广告的。入群的验证暗号是:我爱编译原理