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
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.
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
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1584 Accepted Submission(s): 471
Problem Description
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
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;
}