zoj 2250 - Grandpa is Famous

来源:互联网 发布:javascript 清空数组 编辑:程序博客网 时间:2024/05/18 02:58

题目:统计排名第二的人。

分析:计数排序+统计。

说明:大黄都说题目木有问题。他怎么会放在DP分类里啊。(2011-11-01 15:19)

#include <iostream>#include <cstdlib>#include <cstring>#include <stdio.h>usingnamespace std;int V[ 10005 ];int C[ 10005 ];int cmp( constvoid* a, constvoid* b ){    return *(int *)b - *(int *)a;}int main(){    int N,M,I;    while ( cin >> N >> M && (N||M) ) {        memset( V, 0, sizeof( V ) );        memset( C, 0, sizeof( C ) );        for ( int i = 1 ; i <= N ; ++ i ) {            for ( int j = 1 ; j <= M ; ++ j ) {                scanf("%d",&I);                ++ C[ I ];                ++ V[ I ];            }        }        qsort( C, 10001, sizeof( int ), cmp );        int v = 0;        for ( int i = 1 ; ; ++ i ) {            if ( C[ i ] != C[ i-1 ] ) {                v = C[ i ];                break;            }        }        if ( !v ) continue;        for ( int i = 1 ; i <= 10000 ; ++ i ) {            if ( V[ i ] == v ) {                printf("%d ",i);            }        }        printf("\n");    }    return 0;}

0 0
原创粉丝点击