hdu--2523--读懂题意....

这题 感觉很容易读错题意的~~

      touch  me

这题 要是 数据再大点 就不那么容易做了 用hash才2000的数组 太轻松了要是弄个10^9....就要换方法了

一开始 我一直担心 O(n^2)的去预处理数组 会不会导致超时 ...还好n就1000

这里的第K大 让我WA了3 4发...  这一定要仔细看清.. =-=

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 int abs(int n)
 6 {
 7     return n>=0?n:-n;
 8 }
 9 const int size = 2010;
10 int val[size];
11 int arr[1010];
12 
13 int main()
14 {
15     cin.sync_with_stdio(false);
16     int n , k , t , cnt;
17     while( cin >> t )
18     {
19         while( t-- )
20         {
21             cin >> n >> k;
22             cnt = 0;
23             memset( val , 0 , sizeof(val) );
24             for( int i = 0 ; i<n ; i++ )
25             {
26                 cin >> arr[i];
27                 for( int j = 0 ; j<i ; j++ )
28                 {
29                     val[ abs( arr[i]-arr[j] ) ] = 1;
30                 }
31             }
32             for( int i = 0 ; i<=size ; i++ )
33             {
34                 if( val[i]==1 )
35                 {
36                     cnt++;
37                 }
38                 if( cnt==k )
39                 {
40                     cout << i << endl;
41                     break;
42                 }
43             }
44         }
45     }
46     return 0;
47 }
View Code

today:

  网站到期了 什么都会过期 是吗?

  总有一些是时光冲不走的!

just follow your heart
原文地址:https://www.cnblogs.com/radical/p/3870662.html