zoukankan      html  css  js  c++  java
  • 杭电1425 sort

    Problem Description
    给你n个整数。请按从大到小的顺序输出当中前m大的数。
     

    Input
    每组測试数据有两行,第一行有两个数n,m(0<n,m<1000000)。第二行包括n个各不同样,且都处于区间[-500000,500000]的整数。


     

    Output
    对每组測试数据按从大到小的顺序输出前m大的数。
     

    Sample Input
    5 3 3 -35 92 213 -644
     

    Sample Output
    213 92 3
    Hint
    Hint
    请用VC/VC++提交
     


    /*//sort
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    
    int Num[1000010];
    
    int main()
    {
        int N,M,d;
        while(~scanf("%d%d",&N,&M))
        {
            memset(Num,0,sizeof(Num));
            for(int i = 0; i < N; ++i)
            {
                scanf("%d",&d);
                Num[d+500000]++;
            }
            int Cnt = 0;
            for(int i = 1000000; i >= 0; --i)
            {
                while(Num[i])
                {
                    Num[i]--;
                    Cnt++;
                    if(Cnt != M)
                        printf("%d ",i-500000);
                    else
                    {
                        printf("%d
    ",i-500000);
                    }
                }
                if(Cnt == M)
                    break;
            }
        }
    
        return 0;
    }


    //自己写的qsort

    /*//sort
    #include<stdio.h>
    void quick_sort(int *a,int left,int right)//数组一定得从1開始 
    {
    	
    	if(left<right) 
    	//这个if语句是避免别人调用错误使数组的值变化 
    	//就是有可能再次调用的时候会出现不满足条件的。直接不执行即可了 
    	{
    		int low=left,high=right;
    			
    		a[0]=a[left] ;		
    		while(low<high)
    		{
    			while(low<high&&a[high]>=a[0])
    			{
    				high--;
    			}
    			a[low]=a[high];
    			while(low<high&&a[low]<=a[0])
    			{
    				low++;
    			}
    			a[high]=a[low];
    		}
    		a[low]=a[0];//在这里low和high都一样。由于不满足条件时low是等于high的
    		//然后把左边和右边用相同的方法。所以选择递归
    		quick_sort(a,left,low-1);
    		quick_sort(a,low+1,right);
    	}
    	
    }
    int a[1000100];
    int main()
    {
    	int n,m,i;
    	
    	while(~scanf("%d%d",&m,&n))
    	{
    		for(i=1;i<=m;++i)
    		{
    			scanf("%d",a+i);
    		}
    		quick_sort(a,1,m);
    		for(i=m;i>m-n+1;--i)
    		{
    			printf("%d ",a[i]);
    		}
    		printf("%d
    ",a[i]);
    	}
    	return 0;
    }
    */

    /*sort
    #include<stdio.h>
    #include<stdlib.h>
    int cmp(const void *b, const void *c)
    {
         return(*(int *)b<*(int *)c);
    }
    int a[1000100];
    int main()
    {
    	int n,m,i;
    	
    	while(~scanf("%d%d",&m,&n))
    	{
    		for(i=0;i<m;++i)
    		{
    			scanf("%d",a+i);
    		}
    		qsort(a,m,sizeof(a[0]),cmp);
    		for(i=0;i<n-1;++i)
    		{
    			printf("%d ",a[i]);
    		}
    		printf("%d
    ",a[i]);
    	}
    	return 0;
    }
    
    */


    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int main()
    {
    	int n,i;
    	double a[1000];
    	while(~scanf("%d",&n))
    	{
    		for(i=0;i<n;++i)
    		{
    			scanf("%lf",a+i);
    		}
    		sort(a,a+n);
    		double s=0;
    		for(i=1;i<n-1;++i)
    		{
    			s+=a[i];
    		}
    		printf("%.2lf
    ",s/(n-2));
    	}
    	return 0;
    }


  • 相关阅读:
    luogu P1833 樱花 看成混合背包
    luogu P1077 摆花 基础记数dp
    luogu P1095 守望者的逃离 经典dp
    Even Subset Sum Problem CodeForces
    Maximum White Subtree CodeForces
    Sleeping Schedule CodeForces
    Bombs CodeForces
    病毒侵袭持续中 HDU
    病毒侵袭 HDU
    Educational Codeforces Round 35 (Rated for Div. 2)
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7039994.html
Copyright © 2011-2022 走看看