思路:本质是判断一个数组内是否存在三个相同的数。哈希秒了。
难度:力扣简单题。
#include<bits/stdc++.h>
using namespace std;intmain(){int n;
cin>>n;
vector<int>a(n,0);for(int i =0;i<n;i++){
cin>>a[i];}
unordered_map<int,int> mp;for(int i =0;i<n;i++){
mp[a[i]]++;}for(auto it : mp){if(it.second >=3){
cout<<"YES";return0;}}
cout<<"NO";return0;}
B题
排序 + 一堆if判断
#include<bits/stdc++.h>
using namespace std;intmain(){int n;
cin>>n;
vector<int>a(n,0);for(int i =0;i<n;i++){
cin>>a[i];}sort(a.begin(), a.end());if(a[0]>0){
cout<<"YES";return0;}if(a[n-1]<0){
cout<<"YES";return0;}if(a[0]==0){
cout<<"NO";return0;}if(a[0]<0&& a[n-1]>=0){
cout<<"NO";return0;}return0;}
C
问题代码
#include<bits/stdc++.h>
using namespace std;intmain(){int n;int x;
cin>>n;
cin>>x;// 看x是谁的平方数int i =1;int temp =1;while(temp < x){
temp = i * i;if(temp == x){break;}if(temp > x){
i--;break;}
i++;}//cout<<"I: "<<i<<endl;// longlong a =1;for(int k =1;k<=n;k++){
a = a * k;}//cout<<"a: "<<a<<endl;longlong b =1;for(int k =0;k<n;k++){
b = b *(i-k);}//cout<<"b: "<<b<<endl;
cout<<b / a %1000000007;return0;}