hdu2574(一个数的不同的质数因子个数)
来源:互联网 发布:网络推手的盈利模式 编辑:程序博客网 时间:2024/06/15 14:57
Hdu Girls' Day
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1045 Accepted Submission(s): 333
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.
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
23Kate 56Lily 45Amanda 84Sara 55Ella 42Cristina 210Cozzi 2
Sample Output
KateCristina
Source
HDU 2009-5 Programming Contest
//效率还可以,java用时984ms,由于题目没看清一个附加条件(如果因字数相同且 字典顺序最小的名字)
import java.util.*;public class hdu2574 {public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int n=sc.nextInt(); String s,ss = "ZZZZZZZZZZZZZZZZZZZZ"; int a; int max =0; for(int i=1;i<=n;i++){ s=sc.next(); a=sc.nextInt(); int p=prime(a);//数的不同的素数因子个数 if(max<p||max==p&&ss.compareTo(s)>0){ max=p; ss=s; } }System.out.println(ss); } }private static int prime(int m) { int i=2,count=0; while(m>=i){ if(m%i==0){ count++; while(m%i==0) m/=i; } i++; }return count;}}
- hdu2574(一个数的不同的质数因子个数)
- 统计一个数分解质因数中不同因子的个数
- 求一个数的因子的个数
- 求一个数的因子个数
- 一个数的因子个数(包括1和自身)
- 求一个数因子的个数cf_146_div2_B_…
- 找出一个合数的最大质数因子
- 输出一个整数的质数因子
- 求一个正整数的所有质数因子
- 数论之数的因子个数
- HDU 2521 求数的因子个数
- 输入一个数,1~2^24, 输出它的最大质因子和不同质因子的个数。
- 写出一个小程序,求出100-200之间的质数的个数并输出这些数
- 求一个正整数的因子个数
- hdu 6108 小C的倍数问题【一个数的因子个数】
- Java输出一个数的所有因子并但返回个数的算法
- 题目3:找出一个合数的最大质数因子
- 按小到大顺序输出一个正整数的所有质数因子
- 选择图形,计算面积
- UIWebView的一些总结
- 一个普普通通的计算机研究生找工作的感悟
- ios下获取所有实体/虚拟网卡的信息,并以此判断设备所处的网络状态
- msvcp100d.dll
- hdu2574(一个数的不同的质数因子个数)
- POJ 3469 - Dual Core CPU(Dinic最大流)
- 黑马程序员_线程
- Linux下NC扫描TCP,UDP端口
- (考前水题)LA2191 裸树状数组
- 奇数和偶数
- 数据上报分析
- socket状态变化图
- LIRe 源代码分析 6:检索(ImageSearcher)[以颜色布局为例]