网站建设 中企动力泉州,网站制作资讯,wordpress+登录+api接口,推广团队题干#xff1a;
描述 给你一个数组#xff0c;输出里面出现超过1/2的元素。保证有且只有一个解。
输入
第一行是一个整数#xff0c;表示测试数据的组数 n#xff0c;n 1000万 之后每一行都是一个整数。
输出
输出出现超过1/2的那个数字。
输入样例 1
5
1
1
…题干
描述 给你一个数组输出里面出现超过1/2的元素。保证有且只有一个解。
输入
第一行是一个整数表示测试数据的组数 nn 1000万 之后每一行都是一个整数。
输出
输出出现超过1/2的那个数字。
输入样例 1
5
1
1
1
2
3
输出样例 1
1
提示
不要使用 cin测试数据很大。
将时间复杂度降到 O(n)
解题报告 AC代码三种
#includecstdio
#includequeue
#includecstring
#includecmath
#includemap
#includeiostream
#includealgorithm
#define ll long long
#pragma GCC optimize(2)
const ll mod 1e97;
using namespace std;
int n;
ll a[10000000 5];
int main()
{int n,res;ll tmp;scanf(%d,n);res n/21;for(int i 1; in; i) {scanf(%lld,a[i]);}sort(a1,an1);printf(%lld,a[res]);return 0 ;
}
//#includecstdio
//#includequeue
//#includecstring
//#includecmath
//#includemap
//#includeiostream
//#includealgorithm
//#define ll long long
//const ll mod 1e97;
//using namespace std;
//int n;
//ll a[10000000 5];
//mapll,int mp;
//int main()
//{
// int n,res;
// ll tmp;
// scanf(%d,n);
// res n/21;
// for(int i 1; in; i) {
// scanf(%lld,tmp);
// mp[tmp];
// }
// mapll,int :: iterator it;
// for(it mp.begin(); it!mp.end(); it) {
// if(it-second res) printf(%lld\n,it-first);
// }
//
// return 0 ;
//}
//
//#includebits/stdc.h
//using namespace std;
//int main()
//{
// int n;
// scanf(%d,n);
// int temp,time0,a;
// for(int i0;in;i)
// {
// scanf(%d,a);
// if(time0)
// {
// time1;
// tempa;
// }
// else if(tempa)
// {
// time;
// }
// else
// {
// time--;
// }
// }
// printf(%d\n,temp);
//}