zoukankan      html  css  js  c++  java
  • 1979 第K个数

    1979 第K个数

     

    时间限制: 1 s
    空间限制: 1000 KB
    题目等级 : 黄金 Gold
     
     
     
     
    题目描述 Description

    给定一个长度为N(0<n<=10000)的序列,保证每一个序列中的数字a[i]是小于maxlongint的非负整数 ,编程要求求出整个序列中第k大的数字减去第k小的数字的值m,并判断m是否为质数。(0<k<=n)

    输入描述 Input Description

    第一行为2个数n,k(含义如上题)
    第二行为n个数,表示这个序列

    输出描述 Output Description

    如果m为质数则
    第一行为'YES'(没有引号)
    第二行为这个数m
    否则 
    第一行为'NO'
    第二行为这个数m

    样例输入 Sample Input
    5 2
    1 2 3 4 5
    样例输出 Sample Output
    YES
    2
    数据范围及提示 Data Size & Hint

    20%数据满足0<n<=10
    50%数据满足0<n<=5000
    100%数据满足0<n<=10000

    分类标签 Tags

    sort大法好!
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #define lli long long int
     6 using namespace std;
     7 const int MAXN=100001;
     8 lli a[MAXN];
     9 int comp(const int & a,const int & b)
    10 {
    11     return a>b;
    12 }
    13 int pd(int n)
    14 {
    15     if(n<0)
    16     {
    17         return 0;
    18     }
    19     for(int i=2;i<=sqrt(n);i++)
    20     {
    21         if(n%i==0)
    22         return 0;
    23     }
    24     return 1;
    25 }
    26 int main()
    27 {
    28     lli n,m;
    29     //scanf("%lld%lld",&n,&m);
    30     cin>>n>>m;
    31     for(int i=1;i<=n;i++)
    32     {
    33         scanf("%lld",&a[i]);
    34     }
    35     sort(a+1,a+n+1,comp);
    36     lli maxn=a[m];
    37     sort(a+1,a+n+1);
    38     lli minn=a[m];
    39     lli ans=maxn-minn;
    40     if(pd(ans)==1)
    41     {
    42         printf("YES
    %lld",ans);
    43     }
    44     else
    45     {
    46         printf("NO
    %lld",ans);
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    小量程称重传感器
    一个苹果证书怎么多次使用——导出p12文件
    ios申请真机调试( xcode 5)详细解析
    iOS Developer:真机测试
    mac使用技巧
    How to Create a Provisioning Profile for iPhone
    ios申请真机调试( xcode 5)详细解析
    ui develop
    google ip address
    remove xcode recent projects from dock menu 移除xcode dock菜单显示的项目列表
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/6744339.html
Copyright © 2011-2022 走看看