hdu 1800 - Flying to the Mars
2015-04-26 21:01
337 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800
题意:
有n个士兵每个人有一个能力值d,现在士兵要去学习如何飞到火星。规定如下,能力值大的可以教能力值小的,
每个人只能够教一个人。规定一起学习的人的书本是一样的,问最少需要几本书?
思路:
根据题目的意思是我们可以知道最终要求的就是有几个递减的序列,也就是找到最多重复的值。比如2 3 4 3 4 就是两个递减序列4 3 2 和 4 3。重复的数有3,4;即输出2个。
这道题就变成寻找一组数中重复出现的数的个数。
题意:
有n个士兵每个人有一个能力值d,现在士兵要去学习如何飞到火星。规定如下,能力值大的可以教能力值小的,
每个人只能够教一个人。规定一起学习的人的书本是一样的,问最少需要几本书?
思路:
根据题目的意思是我们可以知道最终要求的就是有几个递减的序列,也就是找到最多重复的值。比如2 3 4 3 4 就是两个递减序列4 3 2 和 4 3。重复的数有3,4;即输出2个。
这道题就变成寻找一组数中重复出现的数的个数。
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include<stack> using namespace std; int a[3010]; int main() { int n; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); int i,j; for(i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n); int count=1; int MAX=1; for(i=1;i<n;i++) { if(a[i]>a[i-1]) { count=1; } else { count++; if(count>MAX) { MAX=count; } } } printf("%d\n",MAX); } return 0; }
相关文章推荐
- HDU 1800——Flying to the Mars——————【字符串哈希】
- HDU 1800 Flying to the Mars(Trie字典树 upper_bound)
- hdu 1800 Flying to the Mars
- hdu 1800 Flying to the Mars
- HDU 1800 Flying to the Mars (哈希表)
- HDU 1800 Flying to the Mars
- hdu 1800 Flying to the Mars 详细题解 哈希
- hdu1800 Flying to the Mars(字典树)
- hdu 1800 Flying to the Mars 水题
- HDU 1800 Flying to the Mars
- HDU 1800 Flying to the Mars
- HDU-1800 - Flying to the Mars
- HDU - 1800 Flying to the Mars(桶排|sort|哈希|map)
- hdu 1800 Flying to the Mars
- hdu 1800 Flying to the Mars(字典树)
- hdu 1800 Flying to the Mars
- HDU 1800:Flying to the Mars
- HDU 1800 Flying to the Mars(字典树水题)
- F - Flying to the Mars HDU - 1800
- [字典树、map] HDU 1800 - Flying to the Mars