反思:思考问题一定要全面
易错数据:
输入样例: 3 4
输出样例: y
#include<bits/stdc++.h>
using namespace std;
int main()
{
double s, x; cin >> s >> x;
int i = 0;
double len = 0;
if (s <= x&&fabs(s - x) > 1e-6)//一定要注意特殊情况,即开始时已进入监视区
{
if (s + x >= 7)cout << "y";else cout << "n";
}
else
{
while (1)
{
len += 7.0 * pow(0.98, i++);
if (len >= s - x&&fabs(s - x - len) > 1e-6)//浮点数不能直接比较大小 如果进入监视区
{
len += 7 * pow(0.98, i++);
if (len > s + x&&fabs(s + x - len) > 1e-6)cout << "n";else cout << "y";
exit(0);
}
}
}
return 0;
}