sort Time Limit : 6000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33461    Accepted Submission(s): 9968 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数.   In…
解法一:计数排序:统计0,1,2 的个数 时间复杂度:O(n) 空间复杂度:O(k)    k为元素的取值范围, 此题为O(1) class Solution { public: void sortColors(vector<int>& nums) { ] = {}; //存放0,1,2三个元素的频率 ;i<nums.size();i++){ assert(nums[i] >= && nums[i]<=); //若不符合条件则报错 count[nums…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6281 题意: 根据已给出的式子,进行排序,然后输出排完序后原先的下表. 题解:用结构体保存,在用结构体排序,利用stable_sort()稳定排序.因为会爆long long ,所以对式子进行转换. 代码: #include<bits/stdc++.h> using namespace std; struct node{ int n; long long a,b,c; friend bool op…
#include<stdio.h> #include<malloc.h> #define LEN sizeof(struct Student) struct Student //结构体声明 { long num; int score; struct Student* next; }; int n; struct Student* creat() //创建单向链表 { struct Student *head=NULL, *p_before, *p_later; p_before =…
传送门 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 1.使用内建sort函数 #include<iostream>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 常规的方法是对输入的数从大到小进行排序(可以用sort或qsort),然后输出前m大的数. 不过此题实质上是hash的入门题.建立一个比较大的数组,然后把这些数通过hash函数计算映射到这个数组里面(这里hash函数是 tmp + 500000,tmp是输入的n个数中任意的一个数),考虑到这些数是各不相同的,因此不需要考虑冲突问题. #include <iostream> #include…
http://acm.hdu.edu.cn/showproblem.php?pid=1425 题目大意: 给你n个整数,请按从大到小的顺序输出其中前m大的数. 其中n和m都是位于[-500000,500000]. 你说sort?嗯,速度太慢! 是的,水题. sort可以直接过.但是时间不忍直视!500+MS 那么用hash做呗.因为数范围有限且唯一,直接开个bool的数组就好了. 值得一提的是我看别人的代码里面的输入,用自己写的函数,从300+MS到156MS ,当输入大的时候果然输入会成为瓶颈…
题意:给出n个数,输出前m大的数 和上一题一样,将输入的数加上一个极大地值作为地址 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<algorithm> using namespace std; typedef long long LL; ; +]; int main() { int n,m,i,j; while(scanf("…
选择出数列中前k个最大的数. 这里由于数据特殊.所以能够使用hash表的方法: #include <cstdio> #include <algorithm> #include <stdlib.h> #include <limits> using namespace std; const int SIZE = 1000005; const int SMALL = -500000; bool arr[SIZE]; int main() { int n, m, a…