Sample Output
1 2
题目说一把扫帚。高的可以教低的。做他的老师。低的当然是学生。问最少需要多少把扫帚。看同一个级别的最多有多少个。同一级别最多的就是需要扫帚的个数。典型的可以用hash做。。但是我不是。。
#include#include #include #include #include #include using namespace std; const int maxn = 30000 + 50; int n; int a[maxn]; int ans; int main() { while(scanf("%d", &n) == 1 ) { memset(a, 0, sizeof(a)); int b; ans = -0x3f3f3f3f; int t = 1; int temp = 1; for(int i=1; i<=n; i++)scanf("%d", &a[i]); sort(a+1, a+n+1); if( n==1 ) printf("1\n"); else { for(int i=2; i<=n; i++) { if( a[i] == a[i-1] ){t++;temp = t;} else t = 1; if( temp>ans ){ans = temp;temp = 1;} } printf("%d\n", ans); } } return 0; }