每天一学习,记录一下

原题


链接: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 
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; icin >> a[i];
        mp[a[i]]++;
    }
    int b,c,tt;
    for(int i=0; ifor(int j=0; jif(mp[tt]) 
            {
                cout << "YES" <return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

/*
如果数字不是可以重复使用的呢?
重不重复,判断abc的所表示的下标即可。
此次map存a[i] 的下标。
for(int i=0; i

你可能感兴趣的:(数论)