On-site competition in the Anshan division of 2014 ACM/ICPC Asia Region -- reproduction of questions, acmicpc

Source: Internet
Author: User

On-site competition in the Anshan division of 2014 ACM/ICPC Asia Region -- reproduction of questions, acmicpc
On-site competition in the Anshan division of 2014ACM/ICPC Asia Region -- reproduction of questions

Question Link

In five hours, I got five questions: B, C, D, E, and I.
I thought I had to create a table. Unfortunately, it wasn't enough time. I tried to create a table later --
There are also a lot of people with K questions. I feel like a geometric rotation + ploya, but there is no idea about ry.

B: This is a big simulation. You can directly simulate the array and pay attention to the details.

C: similar to the red-blue triangle on the big white question, each number finds a mass and a non-mass number. If we get rid of duplicates, we can divide them by 2 directly, and then subtract the total C (n, 3, the problem is how to deal with a digital and non-transactional nature. In fact, we only need to deal with the non-transactional nature. In this step, we will use the exclusion principle to break down each number into a factor and then count the number of factors, for each number, f (1 qualitative factor)-f (2 qualitative factors) + f (3)-f (4) + ..., then we can calculate the answer.

D: This question is first converted into n numbers and k digits are removed, with the smallest inertia. In fact, the calculation method of the center of gravity is based on the lever principle in the physical system (I think so anyway ), because the quality is 1, so equals to all the distance to accumulate, and then minus 0, in addition to the number is equal to the length of each location to be reduced from the center, then the formula sigma (DIDAverage Value) 2. In fact, this is the variance. The problem is converted to n numbers and k digits are removed to maximize the variance. The more greedy, the better, so it must be n-k consecutive times, so you only need to scan from left to right and continue maintenance.

E: dp, dp [I] [j] indicates the position I. In column j, it is a relatively watery question after recursion.

H: regard a vertical column as a binary number, and each time it is equivalent to selecting two existing binary numbers to construct a new binary number, then I threw this number into the existing array. I didn't expect a good solution. I wrote a brute force Code and asked him to run nine steps (this one minute or more, and it would take a long time to run ten steps ), then we found that there were 6 unsolved questions. If we assigned 10 to all, we went to wa. Then we tried it. The answer to one of them was 11, and then we went through --

I: This is a sign-in question.

K: There are several ways to obtain the geometric rotation, and then solve the ploya theorem.

Code:

B:

#include <cstdio>#include <cstring>#include <map>using namespace std;typedef long long ll;const int N = 5005;int t, n, x;char op[15];int top, a[N], an;map<int, ll> C;void init() {C.clear();top = 0;an = 0;}int find(int u) {for (int i = 0; i < an; i++)if (a[i] == u) return i;}void Add() {scanf("%d", &x);if (C.count(x))printf("same priority.\n");else {C[x] = 0;a[an++] = x;printf("success.\n");}}void Close() {scanf("%d", &x);if (!C.count(x))printf("invalid priority.\n");else {printf("close %d with %I64d.\n", x, C[x]);C.erase(x);int tmp = find(x);an--;for (int i = tmp; i < an; i++)a[i] = a[i + 1];}}void Chat() {scanf("%d", &x);if (an == 0) printf("empty.\n");else {if (top) C[top] += x;else C[a[0]] += x;printf("success.\n");}}void Rotate() {scanf("%d", &x);if (x >= 1 && x <= an) {int tmp = a[x - 1];for (int i = x - 1; i; i--)a[i] = a[i - 1];a[0] = tmp;printf("success.\n");} else printf("out of range.\n");}void Prior() {if (an == 0) printf("empty.\n");else {int Max = 0, Max_v;for (int i = 0; i < an; i++) {if (Max < a[i])Max = a[i], Max_v = i;}int tmp = a[Max_v];for (int i = Max_v; i; i--)a[i] = a[i - 1];a[0] = tmp;printf("success.\n");}}void Choose() {scanf("%d", &x);if (C.count(x)) {int v = find(x);int tmp = a[v];for (int i = v; i; i--)a[i] = a[i - 1];a[0] = tmp;printf("success.\n");} else printf("invalid priority.\n");}void Top() {scanf("%d", &x);if (C.count(x)) {top = x;printf("success.\n");} else printf("invalid priority.\n");}void Untop() {if (top == 0) printf("no such person.\n");else {top = 0;printf("success.\n");}}void gao() {if (top && C[top]) printf("Bye %d: %I64d\n", top, C[top]);for (int i = 0; i < an; i++) {if (a[i] == top) continue;if (C[a[i]] == 0) continue;printf("Bye %d: %I64d\n", a[i], C[a[i]]);}}int main() {scanf("%d", &t);while (t--) {init();scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%s", op);printf("Operation #%d: ", i);if (!strcmp(op, "Add")) Add();if (!strcmp(op, "Close")) Close();if (!strcmp(op, "Chat")) Chat();if (!strcmp(op, "Rotate")) Rotate();if (!strcmp(op, "Prior")) Prior();if (!strcmp(op, "Choose")) Choose();if (!strcmp(op, "Top")) Top();if (!strcmp(op, "Untop")) Untop();}gao();}return 0;}


C:

#include <cstdio>#include <cstring>#include <vector>using namespace std;typedef long long ll;const int N = 100005;int vis[N], prime[N], pn = 0;void getprime() {for (int i = 2; i < N; i++) {if (vis[i]) continue;prime[pn++] = i;for (ll j = (ll)i * i; j < N; j += i)vis[j] = 1;}}int fac[N], fn;void getfac(int n) {fn = 0;if (n == 1) {fac[fn++] = 1;return;}int tmp = n;for (int i = 0; i < pn && prime[i] * prime[i] <= tmp; i++) {if (tmp % prime[i] == 0) {fac[fn++] = prime[i];while (tmp % prime[i] == 0)tmp /= prime[i];}}if (tmp != 1) fac[fn++] = tmp;}vector<int> g[N];int cnt[N];void dfs(int n, int u, int sum, int c) {if (u == fn) {if (c == 0) return;g[n].push_back(sum);cnt[sum] = c;return;}dfs(n, u + 1, sum * fac[u], c + 1);dfs(n, u + 1, sum, c);}void build(int n) {getfac(n);dfs(n, 0, 1, 0);}void init() {getprime();for (int i = 1; i <= 100000; i++)build(i);}int t, n, a[N];int have[N];int main() {init();scanf("%d", &t);while (t--) {scanf("%d", &n);memset(have, 0, sizeof(have));for (int i = 0; i < n; i++) {scanf("%d", &a[i]);for (int j = 0; j < g[a[i]].size(); j++)have[g[a[i]][j]]++;}ll ans = (ll)n * (n - 1) * (n - 2) / 6;ll cao = 0;for (int i = 0; i < n; i++) {ll sb = 0;for (int j = 0; j < g[a[i]].size(); j++) {int facc = g[a[i]][j];if (cnt[facc] % 2) sb += have[facc];else sb -= have[facc];}cao += (sb - 1) * (n - sb);}printf("%I64d\n", ans - cao / 2);}return 0;}


D:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 50005;int t, n, k;double a[N];int main() {scanf("%d", &t);while (t--) {scanf("%d%d", &n, &k);for (int i = 0; i < n; i++) scanf("%lf", &a[i]);if (n == k) {printf("%.10lf\n", 0.0);continue;}sort(a, a + n);k = n - k;double s1 = 0, s2 = 0;for (int i = 0; i < k; i++)s2 += a[i];for (int i = 0; i < k; i++)s1 += a[i] * a[i];double ans = s1 - s2 * s2 / k * 2 + s2  * s2 / k;for (int i = k; i < n; i++) {s1 = s1 - a[i - k] * a[i - k] + a[i] * a[i];s2 = s2 - a[i - k] + a[i];ans = min(ans, s1 - s2 * s2 / k * 2 + s2 * s2 / k);}printf("%.10lf\n", ans);}return 0;}

E:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;const int N = 55;int t, n, m;int g[N][N], dp[N * 2][N], a;int main() {scanf("%d", &t);while (t--) {scanf("%d%d", &n, &m);for (int i = 1; i <= m; i++)for (int j = 1; j <= m; j++)scanf("%d", &g[i][j]);memset(dp, -INF, sizeof(dp));scanf("%d", &a);if (a == -1) for (int i = 1; i <= m; i++) dp[1][i] = 0;else dp[1][a] = 0;int ans = 0;for (int i = 2; i <= n; i++) {scanf("%d", &a);int s, e;if (a == -1) s = 1, e = m;else s = a, e = a;for (int j = s; j <= e; j++) {for (int k = 1; k <= m; k++)dp[i][j] = max(dp[i][j], dp[i - 1][k] + g[k][j]);if (i == n) ans = max(dp[i][j], ans);}}printf("%d\n", ans);}return 0;}

H:

Table playing program:

#include <cstdio>#include <cstring>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int N = 105;int ans[1005];int h[N], hn = 0;int NAND(int a, int b) {return (~(a&b))&((1<<8) - 1);}vector<int> ss;int vis[257];void dfs(int step) {ans[h[hn - 1]] = min(ans[h[hn - 1]], step);if (step == 9) return;int v[257];memset(v, 0, sizeof(v));for (int i = 0; i < hn; i++) {for (int j = i; j < hn ;j++) {int tmp = NAND(h[i], h[j]);if (v[tmp]) continue;v[tmp] = 1;if (vis[tmp]) continue;h[hn++] = tmp;vis[tmp] = 1;dfs(step + 1);vis[tmp] = 0;hn--;}}}int main() {memset(ans, INF, sizeof(ans));vis[240] = vis[204] = vis[170] = vis[255] = vis[0] = 1;h[hn++] = 240; h[hn++] = 204; h[hn++] = 170; h[hn++] = 255; h[hn++] = 0;ans[240] = ans[204] = ans[170] = ans[255] = ans[0] = 1;dfs(1);for (int i = 0; i < 256; i++)printf("sb[%d] = %d;\n", i, ans[i]);return 0;}

Table:

# Include <cstdio> # include <cstring> const int INF = 0x3f3f3f; int t; char str [10]; int sb [300]; int main () {sb [0] = 1; sb [1] = 8; sb [2] = 7; sb [3] = 5; sb [4] = 7; sb [5] = 5; sb [6] = 8; sb [7] = 5; sb [8] = 6; sb [9] = 9; sb [10] = 4; sb [11] = 6; sb [12] = 4; sb [13] = 6; sb [14] = 5; sb [15] = 2; sb [16] = 7; sb [17] = 5; sb [18] = 8; sb [19] = 5; sb [20] = 8; sb [21] = 5; sb [22] = 11; // This is 11--. That is to say, if the optimization is to run 10 steps, in fact, the answer is obvious: sb [23] = 8; sb [24] = 8; sb [25] = 7; sb [26] = 8; sb [27] = 6; sb [28] = 8; sb [29] = 6; sb [30] = 8; sb [31] = 5; sb [32] = 6; sb [33] = 9; sb [34] = 4; sb [35] = 6; sb [36] = 8; sb [37] = 7; sb [38] = 8; sb [39] = 6; sb [40] = 7; sb [41] = 1061109567; sb [42] = 4; sb [43] = 7; sb [44] = 7; sb [45] = 7; sb [46] = 5; sb [47] = 4; sb [48] = 4; sb [49] = 6; sb [50] = 5; sb [51] = 2; sb [52] = 8; sb [53] = 6; sb [54] = 8; sb [55] = 5; sb [56] = 7; sb [57] = 7; sb [58] = 5; sb [59] = 4; sb [60] = 5; sb [61] = 7; sb [62] = 8; sb [63] = 2; sb [64] = 6; sb [65] = 9; sb [66] = 8; sb [67] = 7; sb [68] = 4; sb [69] = 6; sb [70] = 8; sb [71] = 6; sb [72] = 7; sb [75] = 1061109567; sb [74] = 7; sb [75] = 7; sb [76] = 4; sb [77] = 7; sb [78] = 5; sb [79] = 4; sb [80] = 4; sb [81] = 6; sb [82] = 8; sb [83] = 6; sb [84] = 5; sb [85] = 2; sb [86] = 8; sb [87] = 5; sb [88] = 7; sb [89] = 7; sb [90] = 5; sb [91] = 7; sb [92] = 5; sb [93] = 4; sb [94] = 8; sb [95] = 2; sb [96] = 7; sb [97] = 1061109567; sb [98] = 7; sb [99] = 7; sb [100] = 7; sb [101] = 7; sb [102] = 5; sb [103] = 7; sb [104] = 9; sb [105] = 1061109567; sb [106] = 7; sb [107] = 9; sb [108] = 7; sb [109] = 9; sb [110] = 6; sb [111] = 7; sb [112] = 4; sb [113] = 7; sb [114] = 5; sb [115] = 4; sb [116] = 5; sb [117] = 4; sb [118] = 8; sb [119] = 2; sb [120] = 7; sb [121] = 9; sb [122] = 6; sb [123] = 7; sb [124] = 6; sb [125] = 7; sb [126] = 8; sb [127] = 4; sb [128] = 5; sb [129] = 9; sb [130] = 8; sb [131] = 7; sb [132] = 8; sb [133] = 7; sb [134] = 9; sb [135] = 6; sb [136] = 3; sb [137] = 9; sb [138] = 5; sb [139] = 6; sb [140] = 5; sb [141] = 6; sb [142] = 6; sb [143] = 3; sb [144] = 8; sb [145] = 7; sb [146] = 9; sb [147] = 6; sb [148] = 9; sb [149] = 6; sb [150] = 9; sb [151] = 9; sb [152] = 8; sb [153] = 6; sb [154] = 8; sb [155] = 6; sb [156] = 8; sb [157] = 6; sb [158] = 9; sb [159] = 6; sb [160] = 3; sb [161] = 9; sb [162] = 5; sb [163] = 6; sb [164] = 8; sb [165] = 6; sb [166] = 8; sb [167] = 6; sb [168] = 4; sb [169] = 9; sb [170] = 1; sb [171] = 6; sb [172] = 5; sb [173] = 7; sb [174] = 5; sb [175] = 3; sb [176] = 5; sb [177] = 6; sb [178] = 6; sb [179] = 3; sb [180] = 8; sb [181] = 6; sb [182] = 9; sb [183] = 6; sb [184] = 5; sb [185] = 7; sb [186] = 5; sb [187] = 3; sb [188] = 7; sb [189] = 7; sb [190] = 8; sb [191] = 5; sb [192] = 3; sb [193] = 9; sb [194] = 8; sb [195] = 6; sb [196] = 5; sb [197] = 6; sb [198] = 8; sb [199] = 6; sb [200] = 4; sb [201] = 9; sb [202] = 5; sb [203] = 7; sb [204] = 1; sb [205] = 6; sb [206] = 5; sb [207] = 3; sb [208] = 5; sb [209] = 6; sb [210] = 8; sb [211] = 6; sb [212] = 6; sb [213] = 3; sb [214] = 9; sb [215] = 6; sb [216] = 5; sb [217] = 7; sb [218] = 7; sb [219] = 7; sb [220] = 5; sb [221] = 3; sb [222] = 8; sb [223] = 5; sb [224] = 4; sb [225] = 9; sb [226] = 5; sb [227] = 7; sb [228] = 5; sb [229] = 7; sb [230] = 7; sb [231] = 7; sb [232] = 7; sb [233] = 1061109567; sb [234] = 4; sb [235] = 7; sb [236] = 4; sb [237] = 7; sb [238] = 4; sb [239] = 6; sb [240] = 1; sb [241] = 6; sb [242] = 5; sb [243] = 3; sb [244] = 5; sb [245] = 3; sb [246] = 8; sb [247] = 5; sb [248] = 4; sb [249] = 7; sb [250] = 4; sb [251] = 6; sb [252] = 4; sb [253] = 6; sb [254] = 7; sb [255] = 1; scanf ("% d", & t); while (t --) {scanf ("% s", str); int ans = 0; for (int I = 7; I> = 0; I --) ans = ans * 2 + str [I]-'0'; int out = sb [ans]; if (out = INF) out = 10; printf ("% d \ n", out);} return 0 ;}

I:

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int t, n;const int N = 1005;struct Point {double x, y;int t;void read() {scanf("%d%lf%lf", &t, &x, &y);}} p[N];bool cmp(Point a, Point b) {return a.t < b.t;}double dis(Point a, Point b) {double dx = a.x - b.x;double dy = a.y - b.y;return sqrt(dx * dx + dy * dy);}int main() {scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++) {p[i].read();}sort(p, p + n, cmp);double ans = 0;for (int i = 1; i < n; i++) {ans = max(ans, dis(p[i], p[i - 1]) / (p[i].t - p[i - 1].t));}printf("%.10lf\n", ans);}return 0;}

H: post-event completion


ACM/ICPC semi-finals original question + Data/online evaluation

Enter the URL acm.bit.edu.cn.
Open the acm interface of Beijing Institute of Technology, which contains some questions about the competition.
URL: acm.hit.edu.cn open the acm interface of Harbin Institute of Technology, which also contains competition questions.

How many places does ACM/ICPC have in Asia?

The promotion method has changed this year.

5. A major change in slot allocation is the same as solution 2 of coach voting in the second half of last year.
All five divisions in mainland China are lined up by rank, and the first school gets a slot.
And then the second and third... The school does not repeat the calculation.
If the remaining number of places is smaller than the number of schools in the same ranking, it may be decided by Huang jinxiong or the second grade of these schools.
For example, in the 5-site competition, Tsinghua won two champions and handed in two, and Zhongshan won one. In this round, the three schools took three slots.
Then, the second place on each site, Tsinghua 1, one from Fudan, Peking University, and one from E-Science University, won't be handed over to Tsinghua. Fudan, Peking University, each E-University receives one slot;
Calculate the number in sequence until the remaining number of students is not allocated to the same school.
6. Schools in mainland China go to other divisions to earn the championship runner-up and obtain the slot allocated in the slots in mainland China.
7. foreign (regional) schools receive slot discounts in mainland China (Huang jinxiong means the top 15 schools ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.