码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2574 Hdu Girls' Day

时间:2015-04-20 17:08:13      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:acm算法



Hdu Girls‘ Day

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


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
Kate Cristina
 

Source
 


求出所有素因子然后排个序就好。。
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define LL __int64
#define PI 3.1415926
const int maxn = 1000000;
int a[maxn];
struct node
{
    char name[2222];
    int score;
    int sum;
};
node f[1005];
bool cmp(node aa,node bb)
{
    if(aa.sum==bb.sum)
        return strcmp(aa.name,bb.name)<0;
    else
        return aa.sum>bb.sum;
}
int main()
{

    int t,ans;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        int max;
        max=-1;
        for(i=0; i<n; i++)
        {
            ans=0;
            cin>>f[i].name>>f[i].score;
            for(j=2; j*j<=f[i].score; j++)
            {
                if(f[i].score&&f[i].score%j==0)
                {
                    ans++;
                    while(f[i].score&&f[i].score%j==0)
                        f[i].score/=j;
                }
            }
            if(f[i].score>1)
                ans++;
            f[i].sum=ans;
        }
        sort(f,f+n,cmp);
        cout<<f[0].name<<endl;
    }
    return 0;
}

HDU 2574 Hdu Girls' Day

标签:acm算法

原文地址:http://blog.csdn.net/sky_miange/article/details/45150535

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!