zoukankan      html  css  js  c++  java
  • HDOJ 2574 Hdu Girls' Day

    Hdu Girls' Day

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


    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
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 int prime[1000000] = {0};
     5 
     6 int main()
     7 {
     8     int T,i,j,n,num,max,k;
     9     char name[100],s[100];
    10     prime[0]=prime[1]=1;
    11     for(i = 2; i <1000; i++)
    12         for(j = i * i; j <1000000; j+= i)
    13             prime[j] = 1;
    14     scanf("%d",&T);
    15     while(T--)
    16     {
    17         max=-1;
    18         scanf("%d",&n);
    19         while(n--)
    20         {
    21             k=0;
    22             scanf("%s%d",name,&num);
    23             for(i=2;i<=num;++i)
    24             {
    25                 if(prime[i])
    26                     continue;
    27                 if(num%i==0)
    28                 {
    29                     ++k;
    30                     num/=i;
    31                 }
    32             }
    33             if(max<k)
    34             {
    35                 max=k;
    36                 strcpy(s,name);
    37             }
    38             else if(max&&max==k)
    39             {
    40                 if(strcmp(s,name)>0)
    41                     strcpy(s,name);
    42             }
    43         }
    44         printf("%s\n",s);
    45     }
    46     return 0;
    47 }
    功不成,身已退
  • 相关阅读:
    JSP的作用域与COOKIE
    jsp数据交互
    JSP基本使用方式
    分层架构的初步理解
    JDBC的基本应用
    HTML5新标签
    弹性布局
    解决js获取兄弟节点的兼容问题
    js去重函数(封装函数)
    封装日期函数
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2636920.html
Copyright © 2011-2022 走看看