L - Hdu Girls' Day

题目:L - Hdu Girls' Day
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.
原题:https://cn.vjudge.net/contest...
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 57 , 12 = 22*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

大意与思路:输入的名字和后面的编号,然后看后边的编号的素数因子的种类!!,种类相同的再找名字长的那个即可,(这里是种类!,所以重复的不用记录,即对于一个素数因子的处理时一直除这个因子直到不能整除为止,所以这种情况时候也无需判断除的是不是素数因子,只要判断能否整除即可);

新技巧:因为这个时间的问题的处理很严,所以对于循环的条件与情况要特别的注意才可以!!!!并且一定要看好是素数因子还是素数的个数,素数的个数其实也可以这样处理,即对于找到一个素数因子之后一直除它,把它的素数因子全除掉,这样就可以节省很多时间;(对于素数因子的处理的新技巧!!)

代码:

#include
#include

char s[1005][25];
int b[1005];
int main()
{
    int n,m,p,q,x,y,xs;
    scanf("%d",&n);
    for(q=0;q0)//这里是找名字长的那个
                    k=p;
            }
        }
        printf("%s\n",s[k]);
    }
    return 0;
}

你可能感兴趣的:(L - Hdu Girls' Day)