Created
February 13, 2017 01:13
-
-
Save Ruanxingzhi/9bbdb6daaf5c6ec897c40996efcf817f to your computer and use it in GitHub Desktop.
Challenge 模板程序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #define bool int | |
| #define true 1 | |
| #define false 0 | |
| typedef unsigned int u32; | |
| typedef unsigned long long u64; | |
| inline u32 next_integer(u32 x) { | |
| x ^= x << 13; | |
| x ^= x >> 17; | |
| x ^= x << 5; | |
| return x; | |
| } | |
| bool output_arr(void *a, u32 size) { | |
| if (size % 4) { | |
| return puts("-1"), 0; | |
| } | |
| u32 blocks = size / 4; | |
| u32 *A = (u32 *)a; | |
| u32 ret = size; | |
| u32 x = 23333333; | |
| u32 i; | |
| for (i = 0; i < blocks; i++) { | |
| ret = ret ^ (A[i] + x); | |
| x ^= x << 13; | |
| x ^= x >> 17; | |
| x ^= x << 5; | |
| } | |
| return printf("%u\n", ret), 1; | |
| } | |
| // ===== header ====== | |
| void Sorting_main() { | |
| int n; | |
| u32 seed; | |
| scanf("%d%u", &n, &seed); | |
| u32 *a = malloc(n * sizeof(u32)); | |
| int i; | |
| for (i = 0; i < n; i++) { | |
| seed = next_integer(seed); | |
| a[i] = seed; | |
| } | |
| // sort(a, n); | |
| output_arr(a, n * sizeof(u32)); | |
| } | |
| void Game_main() { | |
| int n, q; | |
| scanf("%d%d", &n, &q); | |
| char *s1 = malloc((n + 1) * sizeof(char)); | |
| char *s2 = malloc((n + 1) * sizeof(char)); | |
| scanf("%s%s", s1, s2); | |
| u32 *anss = malloc(q * sizeof(u32)); | |
| int *q_x = malloc(q * sizeof(int)); | |
| int *q_y = malloc(q * sizeof(int)); | |
| int *q_len = malloc(q * sizeof(int)); | |
| int i; | |
| for (i = 0; i < q; i++) { | |
| scanf("%d%d%d", q_x + i, q_y + i, q_len + i); | |
| } | |
| // solve(n, q, s1, s2, q_x, q_y, q_len, anss); | |
| output_arr(anss, q * sizeof(u32)); | |
| } | |
| void Parentheses_main() { | |
| int n; | |
| scanf("%d", &n); | |
| char *s = malloc((n + 1) * sizeof(char)); | |
| scanf("%s", s); | |
| u32 ans; | |
| // ans = solve(n, s); | |
| printf("%u\n", ans); | |
| } | |
| int main() { | |
| freopen("challenge.in", "r", stdin); | |
| freopen("challenge.out", "w", stdout); | |
| int task_id; | |
| scanf("%d", &task_id); | |
| switch (task_id) { | |
| case 1: | |
| Sorting_main(); | |
| break; | |
| case 2: | |
| Game_main(); | |
| break; | |
| case 3: | |
| Parentheses_main(); | |
| break; | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <algorithm> | |
| typedef unsigned int u32; | |
| typedef unsigned long long u64; | |
| inline u32 next_integer(u32 x) { | |
| x ^= x << 13; | |
| x ^= x >> 17; | |
| x ^= x << 5; | |
| return x; | |
| } | |
| bool output_arr(void *a, u32 size) { | |
| if (size % 4) { | |
| return puts("-1"), 0; | |
| } | |
| u32 blocks = size / 4; | |
| u32 *A = (u32 *)a; | |
| u32 ret = size; | |
| u32 x = 23333333; | |
| for (u32 i = 0; i < blocks; i++) { | |
| ret = ret ^ (A[i] + x); | |
| x ^= x << 13; | |
| x ^= x >> 17; | |
| x ^= x << 5; | |
| } | |
| return printf("%u\n", ret), 1; | |
| } | |
| // ===== header ====== | |
| namespace Sorting { | |
| void init_data(u32 *a, int n, u32 seed) { | |
| for (int i = 0; i < n; i++) { | |
| seed = next_integer(seed); | |
| a[i] = seed; | |
| } | |
| } | |
| void main() { | |
| int n; | |
| u32 seed; | |
| scanf("%d%u", &n, &seed); | |
| u32 *a = new u32[n]; | |
| init_data(a, n, seed); | |
| // sort(a, n); | |
| output_arr(a, n * sizeof(u32)); | |
| } | |
| } | |
| namespace Game { | |
| void main() { | |
| int n, q; | |
| scanf("%d%d", &n, &q); | |
| char *s1 = new char[n + 1]; | |
| char *s2 = new char[n + 1]; | |
| scanf("%s%s", s1, s2); | |
| u32 *anss = new u32[q]; | |
| int *q_x = new int[q]; | |
| int *q_y = new int[q]; | |
| int *q_len = new int[q]; | |
| for (int i = 0; i < q; i++) { | |
| scanf("%d%d%d", q_x + i, q_y + i, q_len + i); | |
| } | |
| // solve(n, q, s1, s2, q_x, q_y, q_len, anss); | |
| output_arr(anss, q * sizeof(u32)); | |
| } | |
| } | |
| namespace Parentheses { | |
| void main() { | |
| int n; | |
| scanf("%d", &n); | |
| char *s = new char[n + 1]; | |
| scanf("%s", s); | |
| u32 ans; | |
| // ans = solve(n, s); | |
| printf("%u\n", ans); | |
| } | |
| } | |
| int main() { | |
| freopen("challenge.in", "r", stdin); | |
| freopen("challenge.out", "w", stdout); | |
| int task_id; | |
| scanf("%d", &task_id); | |
| switch (task_id) { | |
| case 1: | |
| Sorting::main(); | |
| break; | |
| case 2: | |
| Game::main(); | |
| break; | |
| case 3: | |
| Parentheses::main(); | |
| break; | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type | |
| u32 = dword; | |
| u64 = qword; | |
| u32_p = ^u32; | |
| u64_p = ^u64; | |
| longint_p = ^longint; | |
| function next_integer(x : u32) : u32; inline; | |
| begin | |
| x := x xor (x << 13); | |
| x := x xor (x >> 17); | |
| x := x xor (x << 5); | |
| exit(x); | |
| end; | |
| function output_arr(a_in : pointer; size : u32) : boolean; | |
| var | |
| blocks : u32; | |
| a, a_ed : u32_p; | |
| ret, x : u32; | |
| begin | |
| if size mod 4 <> 0 then begin | |
| writeln(-1); | |
| exit(false); | |
| end; | |
| blocks := size div 4; | |
| ret := size; | |
| a := a_in; | |
| a_ed := a + blocks; | |
| x := 23333333; | |
| while a < a_ed do begin | |
| ret := ret xor (a[0] + x); | |
| x := x xor (x << 13); | |
| x := x xor (x >> 17); | |
| x := x xor (x << 5); | |
| inc(a); | |
| end; | |
| writeln(ret); | |
| exit(true); | |
| end; | |
| // ====== header ====== | |
| procedure init_data(a : u32_p; n : longint; seed : u32); | |
| var | |
| a_ed : u32_p; | |
| begin | |
| a_ed := a + n; | |
| while a < a_ed do begin | |
| seed := next_integer(seed); | |
| a[0] := seed; | |
| inc(a); | |
| end; | |
| end; | |
| procedure Sorting_main(); | |
| var | |
| n : longint; | |
| seed : u32; | |
| a : u32_p; | |
| i : u32; | |
| begin | |
| read(n, seed); | |
| a := Getmem(n * sizeof(u32)); | |
| init_data(a, n, seed); | |
| // sort(a, n); | |
| output_arr(a, n * sizeof(u32)); | |
| end; | |
| procedure Game_main(); | |
| var | |
| n, q : longint; | |
| s1, s2 : ansistring; | |
| anss : u32_p; | |
| q_x, q_y, q_len : longint_p; | |
| i : longint; | |
| begin | |
| readln(n, q); | |
| readln(s1); | |
| readln(s2); | |
| anss := Getmem(q * sizeof(u32)); | |
| q_x := Getmem(q * sizeof(longint)); | |
| q_y := Getmem(q * sizeof(longint)); | |
| q_len := Getmem(q * sizeof(longint)); | |
| for i := 0 to q - 1 do begin | |
| read(q_x[i], q_y[i], q_len[i]); | |
| end; | |
| // solve(n, q, s1, s2, q_x, q_y, q_len, anss); | |
| output_arr(anss, q * sizeof(u32)); | |
| end; | |
| procedure Parentheses_main(); | |
| var | |
| n : longint; | |
| s : ansistring; | |
| ans : u32; | |
| begin | |
| read(n); | |
| read(s); | |
| // ans := solve(n, s); | |
| writeln(ans); | |
| end; | |
| var | |
| task_id : longint; | |
| begin | |
| assign(input, 'challenge.in'); reset(input); | |
| assign(output, 'challenge.out'); rewrite(output); | |
| read(task_id); | |
| if task_id = 1 then begin | |
| Sorting_main(); | |
| end else if task_id = 2 then begin | |
| Game_main(); | |
| end else if task_id = 3 then begin | |
| Parentheses_main(); | |
| end; | |
| close(input); close(output); | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment