Code Jam Round 1A 2018

Waffle Choppers

暴力

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char G[111][111];
 4 int sum[111][111];
 5 
 6 int main(){
 7     int T;
 8     scanf("%d", &T);
 9     for(int kase = 1; kase <= T; ++kase){
10         int R, C, H, V;
11         scanf("%d %d %d %d", &R, &C, &H, &V);
12         for(int i = 1; i <= R; ++i){
13             scanf("%s", G[i] + 1);
14             for(int j = 1; j <= C; ++j) sum[i][j] = (G[i][j] == '@' ? 1 : 0);
15         }
16         for(int i = 1; i <= R; ++i)
17             for(int j = 1; j <= C; ++j)
18                 sum[i][j] += sum[i-1][j];
19         for(int i = 1; i <= R; ++i)
20             for(int j = 1; j <= C; ++j)
21                 sum[i][j] += sum[i][j-1];
22         int ok = 1;
23         if(sum[R][C] % ((H + 1) * (V + 1)) != 0) ok = 0;
24         int t1 = sum[R][C] / (V + 1);
25         int t2 = sum[R][C] / (H + 1);
26         int t3 = t1 / (H + 1);
27         vector<int> v, h;
28         h.push_back(0);
29         v.push_back(0);
30         for(int i = 1; i <= R; ++i){
31             if(sum[i][C] - sum[h[h.size()-1]][C] > t2) {ok = 0; break;}
32             if(sum[i][C] - sum[h[h.size()-1]][C] == t2) h.push_back(i);
33         }
34         for(int i = 1; i <= C; ++i){
35             if(sum[R][i] - sum[R][v[v.size()-1]] > t1) {ok = 0; break;}
36             if(sum[R][i] - sum[R][v[v.size()-1]] == t1) v.push_back(i);
37         }
38 
39         for(int i = 1; i < h.size(); ++i){
40             for(int j = 1; j < v.size(); ++j){
41                 int tmp = sum[h[i]][v[j]];
42                 tmp -= sum[h[i-1]][v[j]];
43                 tmp -= sum[h[i]][v[j-1]];
44                 tmp += sum[h[i-1]][v[j-1]];
45                 if(tmp != t3) ok = 0;
46             }
47         }
48 
49         printf("Case #%d: %s\n", kase, ok ? "POSSIBLE" : "IMPOSSIBLE");
50     }
51     return 0;
52 }
Aguin

 

Bit Party

二分

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 LL M[1111], S[1111], P[1111];
 5 
 6 bool cmp(LL i, LL j){
 7     return i > j;
 8 }
 9 
10 int main(){
11     int T;
12     scanf("%d", &T);
13     for(int kase = 1; kase <= T; ++kase){
14         LL R, B, C;
15         scanf("%lld %lld %lld", &R, &B, &C);
16         for(int i = 1; i <= C; ++i) scanf("%lld %lld %lld", M + i, S + i, P + i);
17         LL l = 0, r = 5e18;
18         while(l < r){
19             LL mid = l + (r - l) / 2;
20             vector<LL> tmp;
21             for(int i = 1; i <= C; ++i){
22                 if(mid >= P[i]) tmp.push_back(min(M[i], (mid - P[i]) / S[i]));
23             }
24             sort(tmp.begin(), tmp.end(), cmp);
25             LL sum = 0;
26             for(int i = 0; i < min(R, (LL)tmp.size()); ++i) sum += tmp[i];
27             if(sum >= B) r = mid;
28             else l = mid + 1;
29         }
30         printf("Case #%d: %lld\n", kase, r);
31     }
32     return 0;
33 }
Aguin

 

Edgy Baking

dp

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, double> pii;
 4 double dp[111*255];
 5 vector<pii> v;
 6 
 7 int main(){
 8     int T;
 9     scanf("%d", &T);
10     for(int kase = 1; kase <= T; ++kase){
11         int N, P, sum = 0;
12         scanf("%d %d", &N, &P);
13         v.clear();
14         for(int i = 1; i <= N; ++i){
15             int w, h;
16             scanf("%d %d", &w, &h);
17             int m = min(w, h);
18             sum += w + h + w + h;
19             v.push_back(pii(m , 2 * sqrt(w * w + h * h)));
20         }
21         memset(dp, 0, sizeof(dp));
22         int up = min((P - sum) / 2, 250 * 100);
23         for(int i = 0; i < v.size(); ++i)
24             for(int j = up - v[i].first; j >= 0; --j)
25                 dp[j+v[i].first] = max(dp[j+v[i].first], dp[j] + v[i].second);
26         double ans = 0;
27         for(int j = 0; j <= up; ++j) ans = max(ans, dp[j]);
28         printf("Case #%d: %.10f\n", kase, min((double)P, ans + sum));
29     }
30     return 0;
31 }
Aguin

 

posted @ 2018-05-05 16:14  Aguin  阅读(237)  评论(0编辑  收藏  举报