需要注意的是最终结果的范围,然后数字可以轮换使用。设置好标志位,当满足条件时跳转出去,执行输出。
#include <iostream>
using namespace std;
int main()
{
int n = 0;
int x = 0;
cin >> n >> x;
int arr[1001];
for (int i = 0;i < n;i++)
{
cin >> arr[i];
}
bool found = false;
for (int i = 0;i < n;i++)
{
for (int j = 0;j < n;j++)
{
for (int m = 0;m < n;m++)
{
long long X = (long long)arr[i] * x * x + (long long)arr[j] * x + (long long)arr[m];
if ( X == 0)
{
found = true;
goto ShuChu;
}
}
}
}
ShuChu:
if (found)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}

京公网安备 11010502036488号