HDOJ1425 sort【Hash】

简介:

Problem : 1425 ( sort )     Judge Status : Accepted
RunId : 7412949    Language : C    Author : qq1203456195
Code Render Status : Rendered By HDOJ C Code Render Version 0.01 Beta

 

复制代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define N 1000100
#define M 500000
int arr[1000100];
int main()
{
    int m,n,i,tmp,max;
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        memset(arr,0x3f3f3f3f,sizeof(arr));
        max = -1*N;
        for (i = 0; i < m; i++)
        {
            scanf("%d",&tmp);
            arr[tmp+M] = tmp;
            max = max>(tmp+M)?max:(tmp+M);
        }
        for(i = max;i>=0 && n!=0;i--)
        {
            if(n!=0 && arr[i]!=0x3f3f3f3f)
            {                
                printf("%d",arr[i]);
                n--;
                if(n == 0)    printf("\n");
                else        printf(" ");
            }
        }
    }
    return 0;
}
复制代码

 



本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/archive/2012/12/18/2824032.html,如需转载请自行联系原作者

相关文章
LeetCode 88. Merge Sorted Array
题意是给定了两个排好序的数组,让把这两个数组合并,不要使用额外的空间,把第二个数组放到第一个数组之中.
75 0
LeetCode 88. Merge Sorted Array
|
人工智能 C++ Python
LeetCode 905. Sort Array By Parity
LeetCode 905. Sort Array By Parity
88 0
|
机器学习/深度学习 存储 人工智能
[LeetCode]--34. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not
1093 0
|
Python
[LeetCode]--303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -&gt; 1 sumRange(2, 5) -&
1015 0
|
算法
[LeetCode]--26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in p
964 0
[LeetCode]--21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 这里sorted说的是从小到大。 /** * Definition for singly
1292 0
LeetCode - 34. Search for a Range
34. Search for a Range  Problem's Link  ---------------------------------------------------------------------------- Mean:  给定一个有序数组和一个数k,求k在这个数组中的起始下标和结束下标.
889 0