Ignatius and the Princess IV 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 借鉴链接:https://blog.csdn.net/tigerisland45/article/details/52146154 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 4…
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 51503    Accepted Submission(s): 23178 Problem Description "OK, you are not too bad, em... But you can never pass the…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 就是给你n(n是奇数)个数找出个数大于(n+1)/ 2 的那个数: n的取值范围是 n(1<=n<=999999) 这是很久之前做的一道题了,当时就是用sort排序,输出a[(n+1)/2]就行了,在这道题上很容易就过了,但是如果说n很大的大到无法开数组呢,所以有搜了一下别人的题解: 我们可以知道结果的那个数的个数一定大于总个数的一半(关键),所以我们可以线性的做,当cnt=0的时候更新an…
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 43629    Accepted Submission(s): 19213 Problem Description "OK, you are not too bad, em... But you can never pass the…
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among t…
Ignatius and the Princess IV  先搬中文 Descriptions:   给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行为N个用空格隔开的整数. Output 对于每组数据,输出一行,表示要求找到的那个数 Sample Input 5 1 3 2 3 3 11 1 1 1 1 1 5 5…
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 27227    Accepted Submission(s): 11562 Problem Description "OK, you are not too bad, em... But you can never pass the…
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出现的次数, 若次数一旦达到(n+1)/2,即输出a[i] 注意能出现(n+1)/2次数的最多只有一个 /* HDU 1029 *Ignatius and the Princess IV --- dp */ #include <cstdio> #include <cstring> #in…
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 13294    Accepted Submission(s): 5362 Problem Description "OK, you are not too bad, em... But you can never pass the…
B - Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d & %I64u Submit Status Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell y…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 42359    Accepted Submission(s): 18467 Problem Description "OK, y…
Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. 用map做出映射,然后迭代器检查是否满足输出条件,是的话输出即可. 代码总览 /* Title:HDOJ.1029 Author:pengwill Date:2016-11-21 */ #include <iostream> #include <stdio.h> #include &l…
Ignatius and the Princess IV Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32767K (Java/Other) Total Submission(s) : 7   Accepted Submission(s) : 3 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description "OK, you a…
#include<stdio.h> #include<string.h> #include<math.h> int main() { _int64 n,a; while(scanf("%I64d",&n)!=EOF) { _int64 b=,c; while(n--) { scanf("%I64d",&a); ) { c=a; b++; } else { if(c==a) b++; else b--; } } pr…
<题目链接> 题目大意:给你一段序列,问你在这个序列中出现次数至少为 (n+1)/2 的数是哪个. 解题分析: 本题是一道水题,如果用map来做的话,就非常简单,但是另一个做法还比较巧妙. 解法一: #include <cstdio> int main() { int n,t,cnt,result; while(scanf("%d",&n)!=EOF){ cnt=; ;i<n;i++){ scanf("%d",&t);…
给你n个数字,请你找出出现至少(n+1)/2次的数字. 输入 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行为N个用空格隔开的整数. 输出 对于每组数据,输出一行,表示要求找到的那个数 样例输入 5 1 3 2 3 3 11 1 1 1 1 1 5 5 5 5 5 5 7 1 1 1 1 1 1 1 样例输出 3 5 1 思路:第一种思路是将数组排序,由于其出现(n+1)/2   次,故中位数一定是要找的那个数.时…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 题目大意: 多组数据,每组数据先给一个n,然后给n各数字,找出n各数字中出现了至少(n+1)/2次的数字并输出(保证n为奇数) 看到这题被分类进了dp我还是有点懵逼,我不知道我这算不算dp做法. 我是用的桶排序思想, 由于数据范围如此,直接进行遍历桶是会炸时间的, 所以多开一个数组记录下出现过的数字就行. 题不难 #include<cstdio> #include<cstring>…
此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among them, you hav…
Description         "OK, you are not too bad, em... But you can never pass the next test." feng5166 says.         "I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which i…
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.  "I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one a…
#include<iostream> #include<vector> using namespace std; ]; int main() { int time,n,limit; vector<int> been; while(cin>>time) { ; memset(cnt,,sizeof(cnt)); limit = (time+)/; while(time--) { cin>>n; cnt[n]++; if(cnt[n]>=lim…
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个数组都扫一遍, 看哪一个最大就可以了. #include<cstdio> #include<cstring> ]; int main() { int N,d; while(scanf("%d",&N)!=EOF) { memset(times,,sizeof…
kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #inclu…
http://www.cnblogs.com/joeylee97/p/6616039.html 引入一个cnt,输入元素与上一个元素相同,cnt增加,否则cnt减少,当cnt为零时记录输入元素,因为所求数字至少出现(N+1)/2次,所以最后记录元素就是所求元素 #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #includ…
题目大意是找出数组中出现次数超过一半的数. 基本思想:每遇到两个不同的数就消掉,设一个计数器就行了.   存出现次数最大的那个数的出现次数. 当下一个数与当前的数不同时,计数器减一,相同,则加一. 实现代码: #include <iostream> #include <stdio.h> using namespace std; int main() { int n,x,m_max,cnt; // while(cin>>n) while(scanf("%d&qu…
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",&n)){ int x,ans,cnt = 0; while(n--){ scanf("%d",&x); if(cnt == 0){ ans = x; cnt++; }else{ if(x == ans) cnt++; else cnt--; } } printf("…
题意:求出现次数>=(N+1)/2的数 思路:排序后,输出第(N+1)/2个数 #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; ]; int main(){ int n,i; while(~scanf("%d",&n)){ ;i<n;++i) scanf("%d",&a[i]); sort(a,a…
方法一:    直接进行排序,输出第(n+1)/2位置上的数即可. (容易超时,关闭同步后勉强卡过) #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int n; ]; int main() { ios::sync_with_stdio(false); while(cin&g…
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> #include<algorithm> #include<stack> #include<queue> using namespace std; ; int a[N]; int main() { int n; while(cin>>n&&n) { ; ; ;…
题目大意: n个数字,找出其中至少出现(n+1)/2次的数字,并且保证n是奇数. 题解:这道题数组是不能用的,因为题目没有明确输入的数据范围,比如输入了一个1e9,数组肯定开不了这么大.所以要用map来记录每个数字出现的次数,边输入边记录,然后找到满足题意的数即可. code: #include<bits/stdc++.h> using namespace std; map<int,int>mp; int main(){ int n; while(scanf("%d&qu…