HDOJ-1280-前m大数(暴力)
2017-12-02 20:07
316 查看
前m大的数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20482 Accepted Submission(s): 6979
Problem Description
还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大的M个数告诉她就可以了。
给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=1000)并按从大到小的顺序排列。
Input
输入可能包含多组数据,其中每组数据包括两行:
第一行两个数N和M,
第二行N个数,表示该序列。
Output
对于输入的每组数据,输出M个数,表示结果。输出应当按照从大到小的顺序排列。
Sample Input
4 4
1 2 3 4
4 5
5 3 6 4
Sample Output
7 6 5 5
11 10 9 9 8
暴力就这样过了。。注意:数组要开大些
code:
#include<cstdio> #include<algorithm> #define maxn 70000000 using namespace std; int a[maxn],b[maxn]; bool cmp(int a,int b) { return a>b; } int main() { int n,m; while(~scanf("%d %d",&n,&m)){ for(int i=0;i<n;i++) scanf("%d",&a[i]); int t=0; for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) b[t++]=a[i]+a[j]; sort(b,b+t,cmp); printf("%d",b[0]); for(int i=1;i<m;i++) printf(" %d",b[i]); printf("\n"); } return 0; }
相关文章推荐
- hdoj 前m大的数 1280 (技巧&暴力)
- hdoj1280前m大的数
- HDOJ 5206 Four Inages Strategy 暴力+几何
- hdoj 整数对 1271 (数列&暴力)
- hdoj5024【BFS/暴力】
- [HDOJ5878]I Count Two Three(暴力枚举,二分)
- hdoj 1015 暴力dfs
- hdoj.5078 Osu!【暴力】 2015/08/04
- HDOJ 1339 A Simple Task(简单数学题,暴力)
- HDOJ(HDU) 1407 测试你是否和LTC水平一样高(暴力)
- HDOJ4432 Sum of divisors(暴力)
- hdoj 4932 Miaomiao's Geometry 【暴力枚举】
- HDOJ 3682 To Be an Dream Architect 暴力
- HDOJ 1280 前m大的数(sort)
- HDOJ 5616 Jam's balance (暴力)
- hdoj 1004 Let the Balloon Rise 【STL or 暴力】
- hdoj 2141 Can you find it?【二分查找+暴力】
- HDOJ-----5339---Untitled暴力枚举+剪枝
- HDU/HDOJ 1395 ACM浙大月赛 2^x mod n = 1 可暴力 可用欧拉定理
- hdoj 1280 前M大的数