forked from Ouditchya/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VPL0_B.cpp
96 lines (74 loc) · 1.58 KB
/
VPL0_B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// AC, Algo : Adhoc.
/* Some Helpful Links :
http://www.cplusplus.com/reference/algorithm/
http://www.cplusplus.com/reference/climits/
http://www.cplusplus.com/reference/queue/queue/
http://www.cplusplus.com/reference/vector/vector/
*/
// For any clarifications, contact me at : [email protected]
#include<cstdio>
#include<climits>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std ;
inline int num_dgt( int n )
{
int c = 0 ;
if( n == 0 )
return 1 ;
while( n )
{
n /= 10 ;
c++ ;
}
return c ;
}
int main( )
{
int t , cs , n , u , i , j , M , m , up , d ;
for( scanf("%d",&t) , cs = 1 ; cs <= t ; cs++ )
{
scanf("%d %d",&n,&u) ;
int a[n] ;
for( i = 0 , M = INT_MIN , m = INT_MAX ; i < n ; i++ )
{
scanf("%d",&a[i]) ;
if( a[i] > M )
M = a[i] ;
if( a[i] < m )
m = a[i] ;
}
up = M / u ;
m /= u ;
d = num_dgt( up ) ;
// printf("M = %d m = %d up = %d\n",M,m,up) ;
vector< int > vec[up+1] ;
int arr[up+1] ;
memset( arr , 0 , sizeof( arr ) ) ;
for( i = 0 ; i < n ; i++ )
{
M = a[i] / u ;
// printf("M = %d\n",M) ;
// printf("j = %d val = %d\n",j,a[i]%u) ;
vec[M].push_back( a[i] % u ) ;
arr[M]++ ;
}
printf("Scenario #%d:\n",cs) ;
for( i = m ; i <= up ; i++ )
{
if( !arr[i] )
continue ;
M = num_dgt( i ) ;
for( j = 1 ; j <= d - M ; j++ )
printf(" ") ;
printf("%d | ",i) ;
M = vec[i].end( ) - vec[i].begin( ) ;
sort( vec[i].begin( ) , vec[i].end( ) ) ;
for( j = 0 ; j < M ; j++ )
printf("%d ",vec[i][j]) ;
printf("\n") ;
}
}
return 0 ;
}