Hdu Girls' Day
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1018 Accepted Submission(s): 323
Problem Description
Hdu Girls' Day is a traditional activity in Hdu. Girls in Hdu participate in the activity and show their talent and skill. The girls who win in the activity will become the Hdu's vivid ambassadors(形象大使). There are many students in Hdu concern the activity. Now it's the finally competition to determine who will be the Hdu's vivid ambassadors. The students vote for the girl they prefer. The girl who has the most number of votes will be the first. You as a student representing Hdu Acm team has a chance to vote. Every girl who participates in the activity has an unique No. and name. Because you very like prime number, you will vote for the girl whose No. has the maximum number of unique prime factors.
For example if the girl's No. is 12, and another girl's No. is 210, then you will choose the girl with No. 210. Because 210 = 2 *3 * 5*7 , 12 = 2*2*3. 210 have 4 unique prime factors but 12 just have 2. If there are many results, you will choose the one whose name has minimum lexicographic order.
Input
The first line contain an integer T (1 <= T <= 100).Then T cases followed. Each case begins with an integer n (1 <= n <= 1000) which is the number of girls.And then followed n lines ,each line contain a string and an integer No.(1 <= No. <= 2^31 - 1). The string is the girl's name and No. is the girl's No.The string's length will not longer than 20.
Output
For each case,output the girl's name who you will vote.
Sample Input
2
3
Kate 56
Lily 45
Amanda 8
4
Sara 55
Ella 42
Cristina 210
Cozzi 2
Sample Output
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std;
const int MAX=1000+10;
char s[MAX][25];
int factor(int x){
int num=0;
if(x%2 == 0){
++num;
while(x%2 == 0)x=x/2;
}
for(int i=3;i*i<=x;++i){
if(x%i == 0){
++num;
while(x%i == 0)x=x/i;
}
}
if(x != 1)++num;
return num;
}
int main(){
int t,n,m,num,temp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int num=-1,id=-1;
for(int i=0;i<n;++i){
scanf("%s%d",s[i],&m);
if(!m)temp=0;//这里一定要判断m == 0,因为m=0则求素因子会死循环
else temp=factor(m);
if(temp > num)id=i,num=temp;
else if(temp == num && strcmp(s[id],s[i])>0)id=i;
}
printf("%s\n",s[id]);
}
return 0;
}