模拟题。
算法:
没有什么bug.以后少用STL。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream> #include<vector> #include<string> #include<math.h> #include<map> #include<set> #include<algorithm> using namespace std; map<string,int>mp; map<string,int>mnum; map<string,int>fp; char str[10010][100]; int setp[10010]; int f[10010]; int num[10010]; int N; int jugde( int x ) { //先判主题贴 if( setp[x] ) return x; while( !setp[x] ) { x = f[x]; } return x; } struct node { int x; int num; bool operator < (const node &A) const { if( num != A.num ) return num > A.num; else return x < A.x; } }info[10010]; int main( ) { int a, b, c; while( scanf("%d",&N) != EOF ) { int s = 0; memset(num,0,sizeof(num)); fp.clear(); memset(setp,0,sizeof(setp)); for( int i = 1; i <= N; i++) { scanf("%d%s",&a,str[i]); if( a == 0 ) { setp[i] = 1; fp[str[i]] = i; } else { int x = jugde( a ); if( fp[str[i]] != x )//如果第当前ip地址没有对 x 进行投票 { fp[str[i]] = x; num[x]++; } f[i] = x; } } int f = 0, v = 0; for( int i = 1; i <= N; i++) { if( setp[i] ) { info[v].x = i; info[v++].num = num[i]; // printf("i = %d num[i] = %d\n",i,num[i]); } } sort(info, info + v ); for(int i = 0; i < v; i++) { printf("%d\n",info[i].x); f++; if( f > 10 ) break; } } return 0; }
posted on 2012-08-05 21:10 more think, more gains 阅读(185) 评论(0) 编辑 收藏 举报