hdu2574 Hdu Girls' Day (分解质因数)
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
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.
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.
3
Kate 56
Lily 45
Amanda 8
4
Sara 55
Ella 42
Cristina 210
Cozzi 2
Cristina
#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 (分解质因数)的更多相关文章
- hdu 5428 The Factor 分解质因数
The Factor Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest ...
- HDU 5428 分解质因数
The F ...
- java分解质因数
package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...
- 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)
1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...
- 【python】将一个正整数分解质因数
def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...
- light oj 1236 分解质因数
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...
- 【基础数学】质数,约数,分解质因数,GCD,LCM
1.质数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能整除以其他自然数(质数),换句话说就是该数除了1和它本身以外不再有其他的因数. 2.约数: 如 ...
- 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m
给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后 ...
- cdoj 1246 每周一题 拆拆拆~ 分解质因数
拆拆拆~ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1246 Descri ...
随机推荐
- Fragment与Activity相互传递数据:
Activity向Fragment传递数据:在Activity中创建Bundle数据包,并调用Fragment的setArguments(Bundle bundle)方法即可将Bundle数据包传给F ...
- Safari HTML5 Canvas Guide: Creating Charts and Graphs
Safari HTML5 Canvas Guide: Creating Charts and Graphs Bar graphs are similar to data plots, but each ...
- java中的TreeMap如何顺序按照插入顺序排序
java中的TreeMap如何顺序按照插入顺序排序 你可以使用LinkedHashMap 这个是可以记住插入顺序的. 用LinkedHashMap吧.它内部有一个链表,保持插入的顺序.迭代的时候,也 ...
- Java核心技术,让计算机"一芯多用"的多线程技术
我们在使用计算的时候会感受到计算机好像在同时执行很多任务,这也是我最初接触计算机给我留下的印象,而我们普通人在同一时刻大脑只能思考一件事情(当然不排除一些异能者能够做到一心二用),而且我们在思考完一件 ...
- Linux 文件操作——系统调用和标准I/O库
一.什么是文件 在讲述文件操作之前,我们首先要知道什么是文件.看到这个问题你可能会感觉到可笑,因为对于用过计算机的人来说,文件是最简单不过的概念了,例如一个文本是一个文件,一个work文档是一个文件等 ...
- Jackson的Json转换
public class JacksonJsonUtil { private static ObjectMapper mapper; /** * 获取ObjectMapper实例 * @param c ...
- 解决在Linux下安装Oracle时的中文乱码问题
本帖最后由 TsengYia 于 2012-2-22 17:06 编辑 解决在Linux下安装Oracle时的中文乱码问题 操作系统:Red Hat Enterprise Linux 6.1数据库:O ...
- NDK下 将Platinum SDK 编译成so库 (android - upnp)
Platinum UPnP SDK 是一个跨平台的C++库,利用该库,可以很容易就构建出DLNA/UPnP控制点(DLNA/UPnP Control Point)和DLNA/UPnP设备(DLNA/U ...
- 关于asp.net简单的下载问题
关于asp.net的下载,只需将打开相应的文件路径就能在浏览器上实现下载功能,比如项目的同级目录上有一个文件 苍老师.zip<a href="苍老师.zip">< ...
- 使用html5中video自定义播放器必备知识点总结以及JS全屏API介绍
一.video的js知识点: controls(控制器).autoplay(自动播放).loop(循环)==video默认的: 自定义播放器中一些JS中提供的方法和属性的记录: 1.play()控制视 ...