HDU 2574

Hdu Girls' Day


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1584    Accepted Submission(s): 471


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.


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
Kate

Cristina

题目没细看就做了,太粗心了。。这题求的是最大的素数因子个数例如210 = 2 *3 * 5*7 , 12 = 2*2*3. 这里210有4个,12只有2个 重复的不算

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
using namespace std;
set <int>s;
bool prime(int b)
{
    for(int i=2;i*i<=b;i++)
    {
        if(b%i==0)
            return false;
    }
    return true;
}
int fun(int a)
{
    for(int i=2;i*i<=a;i++)
    {
        if(a%i==0&&prime(i))
        {
            s.insert(i);
            return fun(a/i);
        }
    }
    if(a!=0) //考虑a为0时,貌似这题数据坑
        s.insert(a);
    return s.size();
}
struct da
{
    char str[30];
    int num;
    int num2;
}p[1010];
bool cmp(da a,da b)  //个数相同时按名字的字典顺序
{
    if(a.num2==b.num2)
        return strcmp(a.str,b.str)<0;
    return a.num2>b.num2;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int b;
        scanf("%d",&b);
        for(int i=0;i<b;i++)
        {
            scanf("%s%d",p[i].str,&p[i].num);
            int a=fun(p[i].num);
            p[i].num2=a;
            s.clear();
        }
        sort(p,p+b,cmp);
        printf("%s\n",p[0].str);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值