1、找和为K的两个元素
在一个长度为n(n < 1000)的整数序列中,判断是否存在某两个元素之和为k。
时间限制:1000
内存限制:65536
输入
第一行输入序列的长度n和k,用空格分开。 第二行输入序列中的n个整数,用空格分开。
输出
如果存在某两个元素的和为k,则输出yes,否则输出no。
样例输入
9 10
1 2 3 4 5 6 7 8 9
样例输出
yes
//解法1
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;cin>>a>>b;
int s[a];
for(int i=0;i<a;i++){
cin>>s[i];
}
for(int i=0;i<a;i++){
for(int j=0;j<a;j++){
if(s[i]+s[j]==b && s[i]!=s[j]){
cout<<"yes";
return 0;
}
}
}
cout<<"no";
return 0;
}
//解法2 数据量比较小暴力即可
#include<bits/stdc++.h>
using namespace std;
int a[1002];
int main(i