Skip to content

Commit 50b014f

Browse files
committed
fb hackercup 2013 r1
1 parent 68394a3 commit 50b014f

14 files changed

Lines changed: 504 additions & 0 deletions
File renamed without changes.

HackerCup/2013/R1/card_game.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
#include <cstdio>
5+
using namespace std;
6+
7+
#define REP(i,n) for(int i=0;i<(n);++i)
8+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
9+
#define INF 1000000000
10+
#define MOD 1000000007
11+
typedef long long LL;
12+
13+
int a[10005];
14+
LL mm[10005][10005];
15+
16+
void init() {
17+
FOR(i,0,10000) mm[i][0] = mm[i][i] = 1;
18+
FOR(m,1,10000) {
19+
FOR(n,1,m-1) {
20+
mm[m][n] = (mm[m - 1][n] + mm[m - 1][n - 1]) % MOD;
21+
}
22+
}
23+
}
24+
25+
void run() {
26+
int n, k;
27+
scanf("%d %d", &n, &k);
28+
REP(i,n) scanf("%d", &a[i]);
29+
sort(a, a + n);
30+
31+
LL res = 0;
32+
FOR(i,k-1,n-1) {
33+
res = (res + mm[i][k - 1] * a[i]) % MOD;
34+
}
35+
printf("%d\n", res);
36+
}
37+
38+
int main() {
39+
init();
40+
int m;
41+
scanf("%d", &m);
42+
FOR(i,1,m) {
43+
printf("Case #%d: ", i);
44+
run();
45+
}
46+
return 0;
47+
}

HackerCup/2013/R1/card_game.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Case #1: 180665000
2+
Case #2: 610605848
3+
Case #3: 624738998
4+
Case #4: 832615581
5+
Case #5: 526863429
6+
Case #6: 313254333
7+
Case #7: 705325059
8+
Case #8: 999929
9+
Case #9: 712376460
10+
Case #10: 408515
11+
Case #11: 283588254
12+
Case #12: 1122
13+
Case #13: 915868532
14+
Case #14: 514894931
15+
Case #15: 400
16+
Case #16: 40755786
17+
Case #17: 530567225
18+
Case #18: 855587163
19+
Case #19: 221309511
20+
Case #20: 947249559

HackerCup/2013/R1/card_game.txt

Lines changed: 41 additions & 0 deletions
Large diffs are not rendered by default.

HackerCup/2013/R1/dead_pixels.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
using namespace std;
5+
6+
#define REP(i,n) for(int i=0;i<(n);++i)
7+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
8+
#define INF 1000000000
9+
typedef long long LL;
10+
11+
class hline {
12+
public:
13+
hline(int lt, int rt, int yt, int tt) : left(lt), right(rt), y(yt), type(tt) {}
14+
int left, right, y, type;
15+
bool operator<(const hline& rhs) const {
16+
if (y != rhs.y) return y < rhs.y;
17+
return left < rhs.left;
18+
}
19+
};
20+
21+
int W, H, P, Q, N, X, Y, a, b, c, d;
22+
23+
void run() {
24+
cin >> W >> H >> P >> Q >> N >> X >> Y >> a >> b >> c >> d;
25+
vector<pair<int, int> > mm;
26+
int xx = X, yy = Y;
27+
mm.push_back(make_pair(xx, yy));
28+
FOR(i,1,N-1) {
29+
int tx = (xx * a + yy * b + 1) % W;
30+
int ty = (xx * c + yy * d + 1) % H;
31+
mm.push_back(make_pair(tx, ty));
32+
xx = tx, yy = ty;
33+
}
34+
35+
sort(mm.begin(), mm.end());
36+
mm.erase(unique(mm.begin(), mm.end()), mm.end());
37+
38+
vector<hline> hh;
39+
vector<int> vv;
40+
41+
REP(i,mm.size()) {
42+
xx = mm[i].first, yy = mm[i].second;
43+
int left = max(0, xx - (P - 1));
44+
int top = max(0, yy - (Q - 1));
45+
int right = xx + 1;
46+
int bottom = yy + 1;
47+
48+
hh.push_back(hline(left, right, top, 0));
49+
hh.push_back(hline(left, right, bottom, 1));
50+
51+
vv.push_back(left);
52+
vv.push_back(right);
53+
}
54+
55+
hh.push_back(hline(0, W, H - Q + 1, 0));
56+
hh.push_back(hline(0, W, H, 1));
57+
vv.push_back(0);
58+
vv.push_back(W);
59+
60+
hh.push_back(hline(W - P + 1, W, 0, 0));
61+
hh.push_back(hline(W - P + 1, W, H, 1));
62+
vv.push_back(W - P + 1);
63+
64+
sort(hh.begin(), hh.end());
65+
sort(vv.begin(), vv.end());
66+
vv.erase(unique(vv.begin(), vv.end()), vv.end());
67+
68+
int nv = vv.size(), nh = hh.size();
69+
70+
int area = 0, cnt = 0, top, bot;
71+
FOR(i,0,nv-2) {
72+
int lt = vv[i], rt = vv[i + 1], d = rt - lt;
73+
REP(j,nh) {
74+
if (hh[j].left <= lt && hh[j].right >= rt) {
75+
bot = hh[j].y;
76+
if (cnt > 0) {
77+
area += d * (bot - top);
78+
}
79+
if (hh[j].type == 1) --cnt;
80+
else ++cnt;
81+
top = bot;
82+
}
83+
}
84+
}
85+
86+
int total = W * H;
87+
cout << total - area << endl;
88+
}
89+
90+
int main() {
91+
int m;
92+
cin >> m;
93+
FOR(i,1,m) {
94+
cout << "Case #" << i << ": ";
95+
run();
96+
}
97+
return 0;
98+
}

HackerCup/2013/R1/dead_pixels.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Case #1: 63069325
2+
Case #2: 0
3+
Case #3: 187837304
4+
Case #4: 16
5+
Case #5: 18323862
6+
Case #6: 174
7+
Case #7: 35640189
8+
Case #8: 1436707606
9+
Case #9: 1321395055
10+
Case #10: 51269087
11+
Case #11: 15
12+
Case #12: 0
13+
Case #13: 32
14+
Case #14: 1498870465
15+
Case #15: 0
16+
Case #16: 7117142
17+
Case #17: 8231724
18+
Case #18: 1341788941
19+
Case #19: 7
20+
Case #20: 1435268809

HackerCup/2013/R1/dead_pixels.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
20
2+
24576 30148 1171 1922 740 19787 13047 34 74 34 11
3+
5134 2621 141 183 1000000 2309 282 36 56 66 26
4+
39843 39881 20522 20114 3 11897 5279 74 89 96 58
5+
14 15 12 4 4 3 5 84 74 53 68
6+
9883 7515 100 76 1000000 9567 1921 35 86 77 52
7+
192 223 29 170 28 25 108 89 74 40 51
8+
28557 13495 1138 1991 385 23252 10801 56 19 77 36
9+
38850 37146 6 132 1443 28733 35729 1 38 55 58
10+
37637 35252 131 4 1326 1844 2265 72 38 3 79
11+
35510 11125 1346 1407 395 35248 9485 18 91 26 9
12+
4 4 1 1 3 1 1 2 2 2 2
13+
196 827 117 730 108 131 477 41 72 11 66
14+
6 10 3 2 2 0 0 5 4 3 2
15+
38095 39579 180 6 1507 11485 32227 86 32 39 26
16+
8497 2343 94 193 1000000 5999 1852 70 15 92 16
17+
4886 4367 95 87 1000000 3493 4363 2 66 19 64
18+
39527 38179 294 327 1000000 12899 20050 56 52 99 46
19+
35277 38250 2 199 1349 28136 16549 49 90 40 96
20+
4 4 2 2 1 0 2 1 2 3 4
21+
36478 39536 170 1 1442 22516 31242 4 70 37 6

0 commit comments

Comments
 (0)