Commit c7a1154c authored by 龚平's avatar 龚平

add testcases

parent ffd7a245
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
const int MAX_WIDTH = 1024, MAX_HEIGHT = 1024;
int image[MAX_WIDTH * MAX_HEIGHT], width, height;
const float PI = 3.14159265359, TWO_PI = 6.28318530718, EPSILON = 1e-6;
float my_fabs(float x) {
if (x > 0) return x;
return -x;
}
float p(float x) { return 3 * x - 4 * x * x * x; }
float my_sin_impl(float x) {
if (my_fabs(x) <= EPSILON) return x;
return p(my_sin_impl(x / 3.0));
}
float my_sin(float x) {
if (x > TWO_PI || x < -TWO_PI) {
int xx = x / TWO_PI;
x = x - xx * TWO_PI;
}
if (x > PI) x = x - TWO_PI;
if (x < -PI) x = x + TWO_PI;
return my_sin_impl(x);
}
float my_cos(float x) { return my_sin(x + PI / 2); }
int read_image() {
if (getch() != 80 || getch() != 50) return -1;
width = getint();
height = getint();
if (width > MAX_WIDTH || height > MAX_HEIGHT || getint() != 255) return -1;
int y = 0;
while (y < height) {
int x = 0;
while (x < width) {
image[y * width + x] = getint();
x = x + 1;
}
y = y + 1;
}
return 0;
}
int rotate(int x, int y, float rad) {
float sinma = my_sin(rad), cosma = my_cos(rad);
int hwidth = width / 2, hheight = height / 2;
int xt = x - hwidth, yt = y - hheight;
int src_x = xt * cosma - yt * sinma + hwidth,
src_y = xt * sinma + yt * cosma + hheight;
if (src_x < 0 || src_x >= width || src_y < 0 || src_y >= height) return 0;
return image[src_y * width + src_x];
}
void write_pgm(float rad) {
putch(80); putch(50); putch(10); // P2
putint(width); putch(32); putint(height); putch(32); // width height
putint(255); putch(10); // 255
int y = 0;
while (y < height) {
int x = 0;
while (x < width) {
putint(rotate(x, y, rad));
putch(32);
x = x + 1;
}
putch(10);
y = y + 1;
}
}
int main() {
float rad = getfloat();
getch();
if (read_image() < 0) return -1;
write_pgm(rad);
return 0;
}
int MAX(int a, int b)
{
if (a == b)
return a;
else if (a > b)
return a;
else
return b;
}
int max_sum_nonadjacent(int arr[], int n)
{
int temp[16] = {};
temp[0] = arr[0];
temp[1] = MAX(arr[0], arr[1]);
int i = 2;
while (i < n) {
temp[i] = MAX(temp[i - 2] + arr[i], temp[i - 1]);
i = i + 1;
}
return temp[n - 1];
}
int longest_common_subseq(int arr1[], int len1,
int arr2[], int len2)
{
int p[16][16] = {};
int i, j;
i = 1;
while (i <= len1) {
j = 1;
while (j <= len2) {
if (arr1[i - 1] == arr2[j - 1]) {
p[i][j] = p[i - 1][j - 1] + 1;
} else {
p[i][j] = MAX(p[i - 1][j], p[i][j - 1]);
}
j = j + 1;
}
i = i + 1;
}
return p[len1][len2];
}
int main()
{
int A[15] = {8, 7, 4, 1, 2, 7, 0, 1, 9, 3, 4, 8, 3, 7, 0};
int B[13] = {3, 9, 7, 1, 4, 2, 4, 3, 6, 8, 0, 1, 5};
int An, Bn;
putint(max_sum_nonadjacent(A, 15));
putch(10);
putint(longest_common_subseq(A, 15, B, 13));
putch(10);
return 0;
}
1
4 2
5
8 4
9
12 8
13
16 16
24 16
29 16
29
int a = -1, b = 1;
int inc_a()
{
int b = a;
b = b + 1;
a = b;
return a;
}
int main()
{
int k = 5;
while (k >= 0) {
if (inc_a() && inc_a() && inc_a()) {
putint(a); putch(32); putint(b); putch(10);
}
if (inc_a() < 14 || inc_a() && inc_a() - inc_a() + 1) {
putint(a); putch(10);
b = b * 2;
} else {
inc_a();
}
k = k - 1;
}
putint(a); putch(32); putint(b); putch(10);
return a;
}
17
13
80
55
81
91
95
58
13
5
63
19
54
45
67
63
void sort(int arr[], int len) {
int i = 0;
while (i < len - 1) {
int j = i + 1;
while (j < len) {
if (arr[i] < arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
j = j + 1;
}
i = i + 1;
}
}
// attempt to fool the inliner
int param32_rec(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8,
int a9, int a10, int a11, int a12, int a13, int a14, int a15,
int a16, int a17, int a18, int a19, int a20, int a21, int a22,
int a23, int a24, int a25, int a26, int a27, int a28, int a29,
int a30, int a31, int a32) {
if (a1 == 0) {
return a2;
}
else {
return param32_rec(a1 - 1, (a2 + a3) % 998244353, a4, a5, a6, a7, a8, a9,
a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20,
a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31,
a32, 0);
}
}
int param32_arr(int a1[], int a2[], int a3[], int a4[], int a5[], int a6[],
int a7[], int a8[], int a9[], int a10[], int a11[], int a12[],
int a13[], int a14[], int a15[], int a16[], int a17[],
int a18[], int a19[], int a20[], int a21[], int a22[],
int a23[], int a24[], int a25[], int a26[], int a27[],
int a28[], int a29[], int a30[], int a31[], int a32[]) {
int sum = a1[0] + a1[1];
sum = sum + a2[0] + a2[1];
sum = sum + a3[0] + a3[1];
sum = sum + a4[0] + a4[1];
sum = sum + a5[0] + a5[1];
sum = sum + a6[0] + a6[1];
sum = sum + a7[0] + a7[1];
sum = sum + a8[0] + a8[1];
sum = sum + a9[0] + a9[1];
sum = sum + a10[0] + a10[1];
sum = sum + a11[0] + a11[1];
sum = sum + a12[0] + a12[1];
sum = sum + a13[0] + a13[1];
sum = sum + a14[0] + a14[1];
sum = sum + a15[0] + a15[1];
sum = sum + a16[0] + a16[1];
sum = sum + a17[0] + a17[1];
sum = sum + a18[0] + a18[1];
sum = sum + a19[0] + a19[1];
sum = sum + a20[0] + a20[1];
sum = sum + a21[0] + a21[1];
sum = sum + a22[0] + a22[1];
sum = sum + a23[0] + a23[1];
sum = sum + a24[0] + a24[1];
sum = sum + a25[0] + a25[1];
sum = sum + a26[0] + a26[1];
sum = sum + a27[0] + a27[1];
sum = sum + a28[0] + a28[1];
sum = sum + a29[0] + a29[1];
sum = sum + a30[0] + a30[1];
sum = sum + a31[0] + a31[1];
sum = sum + a32[0] + a32[1];
return sum;
}
int param16(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8,
int a9, int a10, int a11, int a12, int a13, int a14, int a15,
int a16) {
int arr[16] = {a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16};
sort(arr, 16);
return param32_rec(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6],
arr[7], arr[8], arr[9], arr[10], arr[11], arr[12], arr[13],
arr[14], arr[15], a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15, a16);
}
int main() {
int arr[32][2] = {{param16(getint(), getint(), getint(), getint(), getint(),
getint(), getint(), getint(), getint(), getint(),
getint(), getint(), getint(), getint(), getint(),
getint()),
8848}},
i = 1;
while (i < 32) {
arr[i][0] = arr[i - 1][1] - 1;
arr[i][1] = arr[i - 1][0] - 2;
i = i + 1;
}
putint(param32_arr(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6],
arr[7], arr[8], arr[9], arr[10], arr[11], arr[12], arr[13],
arr[14], arr[15], arr[16], arr[17], arr[18], arr[19],
arr[20], arr[21], arr[22], arr[23], arr[24], arr[25],
arr[26], arr[27], arr[28], arr[29], arr[30], arr[31]));
putch(10);
return 0;
}
// Call a func with many params.
int a0;
int a1;
int a2;
int a3;
int a4;
int a5;
int a6;
int a7;
int a8;
int a9;
int a10;
int a11;
int a12;
int a13;
int a14;
int a15;
int a16;
int a17;
int a18;
int a19;
int a20;
int a21;
int a22;
int a23;
int a24;
int a25;
int a26;
int a27;
int a28;
int a29;
int a30;
int a31;
int a32;
int a33;
int a34;
int a35;
int a36;
int a37;
int a38;
int a39;
int testParam8(int a0, int a1, int a2, int a3,
int a4, int a5, int a6, int a7) {
return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7;
}
int testParam16(int a0, int a1, int a2, int a3,
int a4, int a5, int a6, int a7,
int a8, int a9, int a10, int a11,
int a12, int a13, int a14, int a15) {
return a0 + a1 + a2 - a3 - a4 - a5 - a6 - a7 +
a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15;
}
int testParam32(int a0, int a1, int a2, int a3,
int a4, int a5, int a6, int a7,
int a8, int a9, int a10, int a11,
int a12, int a13, int a14, int a15,
int a16, int a17, int a18, int a19,
int a20, int a21, int a22, int a23,
int a24, int a25, int a26, int a27,
int a28, int a29, int a30, int a31) {
return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 +
a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 +
a16 + a17 - a18 - a19 - a20 - a21 - a22 + a23 +
a24 + a25 + a26 + a27 + a28 + a29 + a30 + a31;
}
int main() {
a0 = 0;
a1 = 1;
a2 = 2;
a3 = 3;
a4 = 4;
a5 = 5;
a6 = 6;
a7 = 7;
a8 = 8;
a9 = 9;
a10 = 0;
a11 = 1;
a12 = 2;
a13 = 3;
a14 = 4;
a15 = 5;
a16 = 6;
a17 = 7;
a18 = 8;
a19 = 9;
a20 = 0;
a21 = 1;
a22 = 2;
a23 = 3;
a24 = 4;
a25 = 5;
a26 = 6;
a27 = 7;
a28 = 8;
a29 = 9;
a30 = 0;
a31 = 1;
a32 = 4;
a33 = 5;
a34 = 6;
a35 = 7;
a36 = 8;
a37 = 9;
a38 = 0;
a39 = 1;
a0 = testParam8(a0, a1, a2, a3, a4, a5, a6, a7);
putint(a0);
a0 = testParam16(a32, a33, a34, a35,
a36, a37, a38, a39,
a8, a9, a10, a11,
a12, a13, a14, a15);
putint(a0);
a0 = testParam32(a0, a1, a2, a3,
a4, a5, a6, a7,
a8, a9, a10, a11,
a12, a13, a14, a15,
a16, a17, a18, a19,
a20, a21, a22, a23,
a24, a25, a26, a27,
a28, a29, a30, a31);
putint(a0);
return 0;
}
int foo()
{
int arr[16] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3};
int a = 3, b = 7, c = 5, d = 6, e = 1, f = 0, g = 3, h = 5,
i = 4, j = 2, k = 7, l = 9, m = 8, n = 1, o = 4, p = 6;
int sum1 = a + b + c + d + e + f + g + h;
int sum2 = i + j + k + l + m + n + o + p;
return sum1 + sum2 + arr[a];
}
int main()
{
int a = 3, b = 7, c = 5, d = 6, e = 1, f = 0, g = 3, h = 5,
i = 4, j = 2, k = 7, l = 9, m = 8, n = 1, o = 4, p = 6;
int sum1 = a + b + c + d + e + f + g + h;
int sum2 = i + j + k + l + m + n + o + p;
sum1 = sum1 + foo();
int q = 4, r = 7, s = 2, t = 5, u = 8, v = 0, w = 6, x = 3;
sum2 = sum2 + foo();
a = i; b = j; c = k; d = l;
e = m; f = n; g = o; h = p;
int sum3 = q + r + s + t + u + v + w + x;
int sum = sum1 + sum2 + sum3;
putint(sum);
putch(10);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment