原题


链接:https://www.nowcoder.com/acm/contest/35/A
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
给出n个整数和x,请问这n个整数中是否存在三个数a,b,c使得ax2+bx+c=0,数字可以重复使用。
输入描述:
第一行两个整数n,x
第二行n个整数a[i]表示可以用的数
1 <= n <= 1000, -1000 <= a[i], x <= 1000
输出描述:
YES表示可以
NO表示不可以
示例1
输入

复制
2 1
1 -2
输出

复制
YES


解法


/*
数据量1000,双重循环+hash

*/

代码


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n,x;
int a[maxn];
map<int,int> mp;
int main() {
    ios::sync_with_stdio(false);
    cin >> n >> x;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    int b,c,tt;
    for(int i=0; i<n; i++)
    {
        b = a[i];
        for(int j=0; j<n; j++)
        {
            c = a[j];
            tt = -(b*x*x+c*x);
            if(mp[tt]) 
            {
                cout << "YES" <<endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

/* 如果数字不是可以重复使用的呢? 重不重复,判断abc的所表示的下标即可。 此次map存a[i] 的下标。 for(int i=0; i<n; i++) { for(int j=0; j<n; j++) if(j!=i){ 就这样。 } } */