国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

HDU 1029 Ignatius and the Princess IV

2019-11-08 02:15:10
字體:
來源:轉載
供稿:網友
/*水題B - Ignatius and the PRincess IV時間: 2017/02/19題意:在一組數找到出現次數最多的數。題解:1.可以按map容器計數。2.可以排序后,線性計數3.因為最大的哪個數出現次數大于一半,可以如果遇見那個數+1,不是-1,那么剩下的肯定是那個數。*/#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <vector>#include <map>using namespace std;#define LL long long#define INF 0x3f3f3f3f#define PI acos(-1.0)#define E 2.71828#define MOD 1000000007#define N 1000010#define M 10010const double eps=1e-8;map<int,int> mp;int a[N];int main(){    int n;    while(~scanf("%d",&n))    {        mp.clear();        for(int i = 0; i < n; i++)        {            scanf("%d",&a[i]);            mp[a[i]]++;        }        int ans = -INF,res;        for(int i = 0; i < n; i++)        {            if(ans < mp[a[i]])            {                ans = mp[a[i]];                res = a[i];            }        }        printf("%d/n",res);    }}int main(){    int i,n;    while(~scanf("%d",&n))    {        for(i=0;i<n;i++)            scanf("%d",&a[i]);        sort(a,a+n);        int t=1;        for(i=1;i<n;i++)        {            if(a[i]!=a[i-1])                t=1;            else                t++;            if(t==(n+1)/2)            {                printf("%d/n",a[i]);                break;            }        }    }}int main(){    int i,n;    while(~scanf("%d",&n))    {        int a,ans,ci = 0;        for(i=0;i<n;i++)        {            scanf("%d",&a);            if(ci == 0)            {                ci++;                ans = a;            }            else            {                if(a == ans)                    ci++;                else                    ci--;            }        }        printf("%d/n",ans);    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛扎县| 英德市| 东兰县| 弥勒县| 萝北县| 浮梁县| 阿拉善左旗| 桂平市| 宁武县| 通化市| 齐河县| 霍城县| 临西县| 宾川县| 云阳县| 上饶县| 阿拉善左旗| 深州市| 乌拉特前旗| 江西省| SHOW| 新郑市| 固安县| 大冶市| 浪卡子县| 兰溪市| 饶平县| 定南县| 西峡县| 松潘县| 富顺县| 宜昌市| 南皮县| 云安县| 阜南县| 唐海县| 双城市| 济阳县| 济阳县| 兴国县| 唐海县|