Hdu Girls' Day

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

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
感慨:啊啊啊,不知道合数可以被分解成质因数相乘,还有快排返回值。WA了好久啊!
收获:1.正整数可以分为1,合数,质数 。其中每个合数都可以写成几个质数相乘的形式。
   2.strcmp函数:设这两个字符串为str1,str2,

          若str1==str2,则返回零;
          若str1>str2,则返回正数;
          若str1<str2,则返回负数。
   3.求解质因数两种算法
    第一个:用于每次只能求出一个数的质因子,适用于题目中给的n的个数不是很多,但是n又特别大的;(http://www.cnblogs.com/jiangjing/archive/2013/06/03/3115399.html)第二个:一次求出1~n的所有数的质因子,适用于题目中给的n个数比较多的,但是n不是很大的。(http://www.cnblogs.com/jiangjing/archive/2013/06/01/3112035.html)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 500
int a[] = {, , , , , , , , , };
struct Node
{
int num;
int cnt;
char s[];
}node[];
int cmp(Node a, Node b)
{
if(a.cnt == b.cnt)
{
if(strcmp(a.s,b.s)<)
return true;
else
return false;
}
return a.cnt > b.cnt;
}
int main()
{
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = ; i < n; i++)
{
scanf("%s%d", node[i].s, &node[i].num);
if(node[i].num == )
{
node[i].cnt = ;
continue;
}
node[i].cnt = ;
for(int j = ; a[j]<= node[i].num; j++)
{
if(j >= )
break;
if(node[i].num%a[j] == )
{
node[i].cnt++;
while(node[i].num%a[j]==)
node[i].num = node[i].num/a[j];
}
}
if(node[i].num != )
node[i].cnt++;
} sort(node, node + n, cmp);
printf("%s\n", node[].s);
}
return ;
}
 

hdu2574 Hdu Girls' Day (分解质因数)的更多相关文章

  1. hdu 5428 The Factor 分解质因数

    The Factor  Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest ...

  2. HDU 5428 分解质因数

                                                                                                   The F ...

  3. java分解质因数

      package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...

  4. 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)

    1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...

  5. 【python】将一个正整数分解质因数

    def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...

  6. light oj 1236 分解质因数

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...

  7. 【基础数学】质数,约数,分解质因数,GCD,LCM

    1.质数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能整除以其他自然数(质数),换句话说就是该数除了1和它本身以外不再有其他的因数. 2.约数: 如 ...

  8. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m

    给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后 ...

  9. cdoj 1246 每周一题 拆拆拆~ 分解质因数

    拆拆拆~ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1246 Descri ...

随机推荐

  1. HttpApplication处理对象与HttpModule处理模块 (第三篇)

    一.HttpApplication对象简述 在HttpRuntime创建了HttpContext对象之后,HttpRuntime将随后创建一个用于处理请求的对象,这个对象的类型为HttpApplica ...

  2. VC断点不可用的问题

    文章一 今天我笔记本的VC编译器莫名其妙的就进入不了断点了,而台式机确是好的,问题是一进入调试,断点就自动被取消了,郁闷了一下午,无法进入断点的原因很多,都有想重装VC编译器的打算了,晚上回来查查资料 ...

  3. 《Java web 开发实战经典》读书笔记

    去年年末,也就是大四上学期快要结束的时候,当时保研的事情确定了下来,终于有了一些空闲的时间可以学点实用的技术. 之前做数据库课程设计的时候,也接触过java web的知识,当时做了一个卖二手书籍的网站 ...

  4. c#将输入的人民币数字金额转换成小写

    //// <summary> /// 人民币大小写金额转换 /// </summary> class RMBCapitalization { private const str ...

  5. SVN:冲突解决 合并别人的修改

    在项目中,基本不可避免多个人同时参与一个项目,因此就可能会出现多个人同时修改一个文件的情况,就不可避免的会出现冲突.svn已经很聪明了,如 果你和别人对于同一个文件的修改之间不存在重叠(比如你在文件最 ...

  6. ISO9126 质量模型

    功能性 适合性:当软件在指定条件下使用,其满足明确和隐含要求功能的能力. 准确性:软件提供给用户功能的精确度是否符合目标. 互操作性:软件与其它系统进行交互的能力. 安全性:软件保护信息和数据的安全能 ...

  7. CentOS7安装mysql5.6.23 -(转)

    一.下载glibc版本的Mysql mysql-advanced-5.6.23-linux-glibc2.5-x86_64.zip 解压后,得到 mysql-advanced-5.6.23-linux ...

  8. 判断Table表中是否含有某一列

    if (row.Table.Columns.Contains("DealRecord_GiftCost")) {     if (row["DealRecord_Gift ...

  9. ThinkPHP使用Memcached缓存数据

    ThinkPHP默认使用文件缓存数据,支持Memcache等其他缓存方式,有两个PHP扩展:Memcache和Memcached,Memcahe官方有说明,主要说一下Memcached. 相对于PHP ...

  10. Linux下 输入 env 而得到的环境变量解读

    HOSTNAME=Master.Hadoop MAHOUT_HOME=/usr/hadoop/mahout-distribution-0.8 TERM=linux SHELL=/bin/bash HA ...