Codeforces Round 428 div2 A-C
来源:互联网 发布:seo主管岗位职责 编辑:程序博客网 时间:2024/06/08 00:50
A - Arya and Bran(by Arpa)
Let t be number of her candies. At i-th day , we increase t by ai ,then we give Bran min(8, t) . So we decrease k from this value. We will print the answer once k becomes smaller or equal to 0 . Or we will print - 1 if it does’n happen after n days.
#include <bits/stdc++.h>// by VonSditeusing namespace std;const int SIZE = 105;int candy[SIZE];int main(int argc, char const *argv[]){ int n, k; while (~scanf("%d %d", &n, &k)) { memset(candy, 0, sizeof(candy)); int sum = 0; for (int i = 0; i < n; ++i) { scanf("%d", &candy[i]); sum += candy[i]; } if(sum < k) printf("-1\n"); else { int ans = 0; for (int i = 0; i < n; ++i) { if(candy[i] > 8) { k -= 8; candy[i+1] += candy[i] - 8; } else { k -= candy[i]; } ++ans; if(k <= 0) break; } if(k > 0) printf("-1\n"); else printf("%d\n", ans); } } return 0;}B - Game of the Rows (by Arpa)
Use greedy solution. Consider a group with x ≥ 4 members, put 4 of them in seats [3, 6] of some row, and throw the row. Now we have x - 4 members in this group now. Continue till all of the seats in the range [3, 6] become full, continue with [1, 2] and [7, 8]. Now handle groups with size ≤ 3.
For groups with size = 3, allocate 4 seats in range [3, 6] or 4 seats in range [1, 2] or [7, 8].
For groups with size = 2, allocate 2 seats in range [1, 2] or [7, 8] or 3 seats in range [3, 6]. If no seat found, divide this group and make it two groups with size 1.
Fill the other parts with groups with groups with size = 1.
If in any part we ran out of seat, the answer is NO, YES otherwise.
#include <bits/stdc++.h>// by VonSditeusing namespace std;const int SIZE = 105;int candy[SIZE];int main(int argc, char const *argv[]){ int n, k; while (~scanf("%d %d", &n, &k)) { memset(candy, 0, sizeof(candy)); int sum = 0; for (int i = 0; i < n; ++i) { scanf("%d", &candy[i]); sum += candy[i]; } if(sum < k) printf("-1\n"); else { int ans = 0; for (int i = 0; i < n; ++i) { if(candy[i] > 8) { k -= 8; candy[i+1] += candy[i] - 8; } else { k -= candy[i]; } ++ans; if(k <= 0) break; } if(k > 0) printf("-1\n"); else printf("%d\n", ans); } } return 0;}C - Journey (by Arpa)
Let the cities be vertices and roads be edges of a tree and vertex 1 be the root of the tree.
Let ans[i] be the answer for the i-th vertex (the expected value if they start their journey from that vertex and the horse doesn't go to it's parent). Now we can calculate ans[i] by knowing the answer for it’s children. Let v1, v2, …., vk be the children of i-th vertex , then . Because when we are at i-th vertex , we have k choices with equal probabilities and + 1for going to one of them (length of the edge between i-th vertex and it’s children).
So if we know the answer of some vertex’s children, we can calculate its expected value and we can do it by a simple DFS (note that the answer for a leave is 0).
#include <bits/stdc++.h> // by VonSditeusing namespace std;const int SIZE = 105;int candy[SIZE];int main(int argc, char const *argv[]){ int n, k; while (~scanf("%d %d", &n, &k)) { memset(candy, 0, sizeof(candy)); int sum = 0; for (int i = 0; i < n; ++i) { scanf("%d", &candy[i]); sum += candy[i]; } if(sum < k) printf("-1\n"); else { int ans = 0; for (int i = 0; i < n; ++i) { if(candy[i] > 8) { k -= 8; candy[i+1] += candy[i] - 8; } else { k -= candy[i]; } ++ans; if(k <= 0) break; } if(k > 0) printf("-1\n"); else printf("%d\n", ans); } } return 0;}
- Codeforces Round 428 div2 A-C
- Codeforces Round #278(Div2) A B C
- Codeforces Round #432 div2 A+B+C
- codeforces div2 round#231 A
- codeforces div2 round#230 A
- codeforces Round 411 div2 A
- Codeforces Round #376A (div2)
- Codeforces Round#229 DIV2 A,B,C,D
- Codeforces Round#258 div2 A B C (Problemset 451)
- codeforces round # 273 div2 A, B, C题题解
- codeforces Round #377 div2 A B C(数学推导)
- Codeforces Round #434 div2 A, B , C,D 题 题解
- Codeforces round 181 div2 C
- codeforces div2 round#231 C
- codeforces div2 round#230 C
- Codeforces - Round.313.Div2.C
- codeforces Round #352 div2 C
- Codeforces Round #409 div2 C
- RCNN学习笔记(6):Faster R-CNN 英文论文翻译笔记
- postman测试
- Memcached (参数说明)--学习笔记(二)
- 解题报告:Codeforces Round #142 (Div. 1) C. Triangles (思维好题)
- JS获取当前年份月
- Codeforces Round 428 div2 A-C
- python中 正则表达式匹配一个反斜杠 ‘\’
- 拒接电话流程分析
- hdoj 1197
- hadoop 完全分布式环境搭建
- 大明A+B HDU
- OSI7层模型与TCP/IP协议栈4层
- java Math类
- 文件I/O与标准I/O