方法一:    直接进行排序,输出第(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…
此题无法用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…
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是dp[i][i].那么dp[i][j]=dp[i][j-1]+dp[i-j][i-j],dp[i][j-1]是累加1到j-1的结果,dp[i-j][i-j]表示的就是最大为j,然后i-j有多少种表达方式啦.因为i-j可能大于j,这与我们定义的j为最大值矛盾,所以要去掉大于j的那些值 /*******…
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 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 题目大意:给定数字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 链接: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): 27227    Accepted Submission(s): 11562 Problem Description "OK, you are not too bad, em... But you can never pass the…
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…
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…
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…
#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+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…
kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #inclu…
#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) { ; ; ;…
"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…
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…
#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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 题目大意: 多组数据,每组数据先给一个n,然后给n各数字,找出n各数字中出现了至少(n+1)/2次的数字并输出(保证n为奇数) 看到这题被分类进了dp我还是有点懵逼,我不知道我这算不算dp做法. 我是用的桶排序思想, 由于数据范围如此,直接进行遍历桶是会炸时间的, 所以多开一个数组记录下出现过的数字就行. 题不难 #include<cstdio> #include<cstring>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 思路分析:该问题要求求出某个整数能够被划分为多少个整数之和(如 4 = 2 + 2, 4 = 2 + 1 + 1),且划分的序列 2, 2 或者 2, 1, 1为单调非递增序列: 使用动态规划解法:假设dp[i][j]表示整数i被划分的序列中最大值不超过j的所有的可能,则使用类似于0-1背包的思考方法: (1)如果i == j,则dp[i][j] = dp[i][j-1] + 1: (2)如果…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = 3 + 1"和"4 = 1 + 3"视为同一种方案.(加数是无序的) 题解1(dp): 表示状态: dp[n][m] = num of methods 表示用均不超过m的元素组成n的方法数. 如何转移: 假设当前状态为dp[n][m]. 对于等于m的元素,有两种决策.要么不用,…
<题目链接> 题目大意:给你一段序列,问你在这个序列中出现次数至少为 (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个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个数组都扫一遍, 看哪一个最大就可以了. #include<cstdio> #include<cstring> ]; int main() { int N,d; while(scanf("%d",&N)!=EOF) { memset(times,,sizeof…
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("…