code jam: 2014 round 2 A solved.

This commit is contained in:
2014-11-12 19:55:32 +04:00
parent 28848c342f
commit 0d36c4d0f9
4 changed files with 582 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
3
3 100
10 20 70
4 100
30 40 60 70
5 100
10 20 30 40 60

View File

@@ -0,0 +1,201 @@
100
8 66
54 27 13 46 23 40 21 44
10 161
160 35 102 13 113 6 67 6 28 103
10 280
39 182 150 211 140 76 242 170 144 153
5 678
486 540 481 515 510
6 144
77 74 70 5 139 67
10 407
148 345 227 353 248 369 344 319 75 78
3 277
127 164 237
6 606
387 387 482 387 482 53
8 273
7 266 151 103 170 235 38 122
6 220
215 69 5 95 125 151
7 417
345 337 162 213 213 162 162
6 388
242 274 82 274 242 82
10 438
42 299 253 295 383 126 252 344 275 368
6 125
13 20 76 52 116 23
10 700
1 1 1 1 1 1 1 1 1 1
10 278
180 90 194 179 227 218 119 138 245 113
8 357
236 332 28 81 352 152 318 138
7 424
198 299 200 200 198 200 200
10 13
1 9 7 4 5 9 8 13 9 13
1 497
323
4 425
393 249 206 288
9 553
275 448 537 520 476 402 461 293 527
4 512
234 347 197 392
6 236
104 7 38 199 133 230
8 592
258 463 463 258 463 174 146 492
7 330
198 188 185 172 306 280 207
10 432
116 121 41 44 286 159 313 213 339 202
10 680
521 418 270 222 531 177 427 291 506 55
7 33
25 11 28 26 12 24 24
5 383
177 283 160 285 218
10 161
152 64 107 112 43 134 17 16 30 6
4 198
64 52 120 49
8 321
289 129 10 302 32 192 311 19
6 670
362 505 413 650 585 491
5 687
431 260 455 506 412
6 600
575 345 427 345 345 345
10 223
172 135 203 18 98 29 161 161 49 113
9 211
71 78 80 160 186 92 128 129 6
10 560
37 38 65 369 460 338 293 94 188 220
10 172
50 113 100 99 92 83 15 113 38 138
8 26
6 1 11 26 21 11 3 13
10 495
479 38 456 69 472 338 326 427 460 419
8 457
230 371 243 415 15 95 172 38
6 564
464 348 538 348 348 464
10 482
118 74 262 49 45 403 23 247 112 172
10 677
551 261 353 573 243 624 482 527 325 504
6 645
309 383 441 550 236 534
4 195
172 115 3 80
10 90
40 88 10 24 1 86 35 2 46 57
9 462
405 362 442 302 313 279 405 389 249
5 241
137 59 218 76 206
7 503
321 248 240 252 172 168 328
5 660
452 641 641 452 641
10 24
15 12 2 11 14 15 22 13 11 20
10 1
1 1 1 1 1 1 1 1 1 1
10 22
15 12 22 15 2 6 8 7 17 6
10 489
476 108 177 230 149 398 240 332 468 158
1 98
75
6 571
428 143 492 79 199 372
10 443
66 228 99 276 411 365 431 399 368 3
6 667
241 298 530 277 416 371
5 287
30 81 261 86 24
10 377
179 364 145 261 338 345 204 334 193 160
10 420
119 57 275 112 321 286 201 370 56 207
6 670
388 28 517 153 282 642
8 626
451 615 11 113 9 513 617 175
10 441
125 146 202 217 215 240 339 10 75 191
10 317
254 287 285 54 201 211 76 62 131 184
7 236
151 114 204 140 150 151 185
3 328
33 202 207
8 441
250 222 250 357 357 357 278 278
10 45
17 17 7 10 10 33 23 9 22 32
10 577
294 514 51 350 315 383 491 375 18 529
2 325
126 320
7 344
294 242 287 235 326 259 237
5 342
229 299 274 230 309
10 296
82 31 30 53 17 6 214 79 276 117
5 167
152 37 116 85 48
7 461
367 322 331 204 207 393 302
6 108
91 17 8 7 100 101
6 545
527 492 342 456 466 198
10 116
102 3 34 68 19 82 15 98 90 64
10 637
31 151 399 40 351 406 220 373 488 592
6 452
421 58 394 149 31 303
7 491
397 241 216 269 454 210 165
10 92
63 20 82 11 61 43 48 25 23 63
10 273
137 204 219 254 253 109 155 119 217 130
10 18
16 3 12 9 17 5 14 10 2 7
10 459
283 55 154 370 199 164 426 162 387 284
10 569
43 228 204 28 199 387 502 330 443 430
10 280
69 237 110 203 263 19 64 5 204 166
2 428
253 365
9 236
138 218 100 162 229 225 115 232 86
10 83
47 24 39 22 4 33 23 14 20 36
8 277
142 224 50 85 247 103 226 80
9 366
350 291 322 286 217 280 131 336 223
10 237
127 221 190 49 225 73 214 10 129 184
6 56
14 26 42 16 30 40
8 664
230 230 245 270 274 274 274 557
8 225
186 207 43 24 81 207 36 34

View File

@@ -0,0 +1,173 @@
/*
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
*/
#include <assert.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <exception>
#include <stdexcept>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <string>
#include <memory>
#include <functional>
#include <algorithm>
#include <utility>
#include <limits>
#include <math.h>
typedef long long ll;
typedef std::vector<ll> vec;
void check( bool b ) { if ( !b ) std::cerr << "error" << std::endl; }
#define FOR(i,l) for ( ll i =0, ie = ll(l); i<ie; ++i )
/*
Read n values into v
*/
template <class V>
void readv( V& v, int n )
{
v.reserve(n);
for ( int i = 0; i < n; ++i )
{
typename V::value_type e;
std::cin >> e;
check( !std::cin.fail() );
v.push_back(e);
}
}
/*
Problem
Adam, being a well-organized man, has always been keenly interested in
organizing all his stuff. In particular, he fondly remembers the many hours
of his youth that were spent moving files from his computer onto Compact Discs.
There were two very important rules involved in this procedure. First, in order
to ensure that all discs could be labeled clearly, Adam would never place more
than two files on the same disc. Second, he would never divide a single file
over multiple discs. Happily, the discs he was using were always large enough
to make this possible.
Thinking back, Adam is now wondering whether he arranged his files in the best
way, or whether he ended up wasting some Compact Discs. He will provide you with
the capacity of the discs he used (all his discs had the same capacity) as well
as a list of the sizes of the files that he stored. Please help Adam out by
determining the minimum number of discs needed to store all his files—following
the two very important rules, of course.
Input
The first line of the input gives the number of test cases, T. T test cases
follow. Each test case begins with a line containing two integers: the number
of files to be stored N, and the capacity of the discs to be used X (in MBs).
The next line contains the N integers representing the sizes of the files Si
(in MBs), separated by single spaces.
Output
For each test case, output one line containing "Case #x: y", where x is the case
number (starting from 1) and y is the minimum number of discs needed to store
the given files.
Limits
1 ≤ T ≤ 100.
1 ≤ X ≤ 700.
1 ≤ Si ≤ X.
Small dataset
1 ≤ N ≤ 10.
Large dataset
1 ≤ N ≤ 104
Sample
Input
3
3 100
10 20 70
4 100
30 40 60 70
5 100
10 20 30 40 60
Output
Case #1: 2
Case #2: 2
Case #3: 3
*/
int solve_puzzle()
{
ll n, c;
std::cin >> n >> c;
vec v;
readv(v,n);
std::sort( v.begin(), v.end(), std::greater<ll>() );
int max_count = 0;
for ( int i = 0; i < v.size(); ++i )
{
if ( v[i] <= 0 )
continue;
max_count++;
ll r = c - v[i];
for ( int j = i+1; j < v.size(); ++j )
{
if ( v[j] > 0 && v[j] <= r )
{
v[j] = -1;
break;
}
}
}
return max_count;
}
int main ( void )
{try{
srand((unsigned)time(NULL));
int puzzle_count;
std::cin >> puzzle_count;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
for ( int i = 1; i <= puzzle_count; i++ )
{
std::cout << "Case #" << i << ": ";
auto r = solve_puzzle();
std::cout << r << std::endl;
}
return 0;
}
catch ( const std::exception& e )
{
std::cerr << std::endl
<< "std::exception(\"" << e.what() << "\")." << std::endl;
return 2;
}
catch ( ... )
{
std::cerr << std::endl
<< "unknown exception." << std::endl;
return 1;
}}