buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
import java.io.*;
class Main {
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String buf;
int count = 1;
try {
while (!(buf = br.readLine()).equals("0")) {
int n = Integer.parseInt(buf);
int scan[][] = new int[n][n];
int x = 0;
int y = 0;
int p = 1;
boolean flag = true;
for (int i = 0; i < n; i++) {
if (flag) {
x = 0;
y = i;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x++;
y--;
}
flag = false;
} else {
x = i;
y = 0;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x--;
y++;
}
flag = true;
}
}
for (int i = n - 2; i >= 0; i--) {
if (flag) {
x = n - i - 1;
y = n - 1;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x++;
y--;
}
flag = false;
} else {
x = n - 1;
y = n - i - 1;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x--;
y++;
}
flag = true;
}
}
System.out.println("Case " + count + ":");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
System.out.printf("%3d", scan[i][j]);
System.out.println("");
}
count++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
import java.io.*;
class Main {
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String buf;
int count = 1;
try {
while (!(buf = br.readLine()).equals("0")) {
int n = Integer.parseInt(buf);
int scan[][] = new int[n][n];
int x = 0;
int y = 0;
int p = 1;
boolean flag = false;
for (int i = 0; i < n; i++) {
if (flag) {
x = 0;
y = i;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x++;
y--;
}
flag = false;
} else {
x = i;
y = 0;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x--;
y++;
}
flag = true;
}
}
for (int i = n - 2; i >= 0; i--) {
if (flag) {
x = n - i - 1;
y = n - 1;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x++;
y--;
}
flag = false;
} else {
x = n - 1;
y = n - i - 1;
for (int j = 0; j <= i; j++) {
scan[x][y] = p++;
x--;
y++;
}
flag = true;
}
}
System.out.println("Case " + count + ":");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
System.out.printf("%3d", scan[i][j]);
System.out.println("");
}
count++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
[["-", 0, 52, 8, 196, 0, 503, 49, 200, 51, 146], ["+", 0, 52, 8, 196, 0, 503, 49, 200, 51, 147]]
| 3
| 453
|
import java.util.Scanner;
public class Main {
public static int count = 1;
public static int a1[][] = {{1}};
public static int a2[][] = {{1, 2}, {3, 4}};
public static int a3[][] = {
{1, 2, 6},
{3, 5, 7},
{4, 8, 9},
};
public static int a4[][] = {
{1, 2, 6, 7}, {3, 5, 8, 13}, {4, 9, 12, 14}, {10, 11, 15, 16}};
public static int a5[][] = {{1, 2, 6, 7, 15},
{3, 5, 8, 14, 16},
{4, 9, 13, 17, 22},
{10, 12, 18, 21, 23},
{11, 19, 20, 24, 25}};
public static int a6[][] = {
{1, 2, 6, 7, 15, 16}, {3, 5, 8, 14, 17, 26},
{4, 9, 13, 18, 25, 27}, {10, 12, 19, 24, 28, 33},
{11, 20, 23, 29, 32, 34}, {21, 22, 30, 31, 35, 36},
};
public static int a7[][] = {
{1, 2, 6, 7, 15, 16, 28}, {3, 5, 8, 14, 17, 27, 29},
{4, 9, 13, 18, 26, 30, 39}, {10, 12, 19, 25, 31, 38, 40},
{11, 20, 24, 32, 37, 41, 46}, {21, 23, 33, 36, 42, 45, 47},
{22, 34, 35, 43, 44, 48, 49},
};
public static int a8[][] = {
{1, 2, 6, 7, 15, 16, 28, 29}, {3, 5, 8, 14, 17, 27, 30, 43},
{4, 9, 13, 18, 26, 31, 42, 44}, {10, 12, 19, 25, 32, 41, 45, 54},
{11, 20, 24, 33, 40, 46, 53, 55}, {21, 23, 34, 39, 47, 52, 56, 61},
{22, 35, 38, 48, 51, 57, 60, 62}, {36, 37, 49, 50, 58, 59, 63, 64},
};
public static int a9[][] = {
{1, 2, 6, 7, 15, 16, 28, 29, 45},
{3, 5, 8, 14, 17, 27, 30, 44, 46},
{4, 9, 13, 18, 26, 31, 43, 47, 60},
{10, 12, 9, 25, 32, 42, 48, 59, 61},
{11, 20, 24, 33, 41, 49, 58, 62, 71},
{21, 23, 34, 40, 50, 57, 63, 70, 72},
{22, 35, 39, 51, 56, 64, 69, 73, 78},
{36, 38, 52, 55, 65, 68, 74, 77, 79},
{37, 53, 54, 66, 67, 75, 76, 80, 81},
};
public static void zig(int n) {
int i, j;
switch (n) {
case 1:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a1[i][j]);
}
System.out.println();
}
count++;
break;
case 2:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a2[i][j]);
}
System.out.println();
}
count++;
break;
case 3:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a3[i][j]);
}
System.out.println();
}
count++;
break;
case 4:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a4[i][j]);
}
System.out.println();
}
count++;
break;
case 5:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a5[i][j]);
}
System.out.println();
}
count++;
break;
case 6:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a6[i][j]);
}
System.out.println();
}
count++;
break;
case 7:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a7[i][j]);
}
System.out.println();
}
count++;
break;
case 8:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a8[i][j]);
}
System.out.println();
}
count++;
break;
case 9:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a9[i][j]);
}
System.out.println();
}
count++;
break;
default:
break;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
zig(n);
}
}
}
|
import java.util.Scanner;
public class Main {
public static int count = 1;
public static int a1[][] = {{1}};
public static int a2[][] = {{1, 2}, {3, 4}};
public static int a3[][] = {
{1, 2, 6},
{3, 5, 7},
{4, 8, 9},
};
public static int a4[][] = {
{1, 2, 6, 7}, {3, 5, 8, 13}, {4, 9, 12, 14}, {10, 11, 15, 16}};
public static int a5[][] = {{1, 2, 6, 7, 15},
{3, 5, 8, 14, 16},
{4, 9, 13, 17, 22},
{10, 12, 18, 21, 23},
{11, 19, 20, 24, 25}};
public static int a6[][] = {
{1, 2, 6, 7, 15, 16}, {3, 5, 8, 14, 17, 26},
{4, 9, 13, 18, 25, 27}, {10, 12, 19, 24, 28, 33},
{11, 20, 23, 29, 32, 34}, {21, 22, 30, 31, 35, 36},
};
public static int a7[][] = {
{1, 2, 6, 7, 15, 16, 28}, {3, 5, 8, 14, 17, 27, 29},
{4, 9, 13, 18, 26, 30, 39}, {10, 12, 19, 25, 31, 38, 40},
{11, 20, 24, 32, 37, 41, 46}, {21, 23, 33, 36, 42, 45, 47},
{22, 34, 35, 43, 44, 48, 49},
};
public static int a8[][] = {
{1, 2, 6, 7, 15, 16, 28, 29}, {3, 5, 8, 14, 17, 27, 30, 43},
{4, 9, 13, 18, 26, 31, 42, 44}, {10, 12, 19, 25, 32, 41, 45, 54},
{11, 20, 24, 33, 40, 46, 53, 55}, {21, 23, 34, 39, 47, 52, 56, 61},
{22, 35, 38, 48, 51, 57, 60, 62}, {36, 37, 49, 50, 58, 59, 63, 64},
};
public static int a9[][] = {
{1, 2, 6, 7, 15, 16, 28, 29, 45},
{3, 5, 8, 14, 17, 27, 30, 44, 46},
{4, 9, 13, 18, 26, 31, 43, 47, 60},
{10, 12, 19, 25, 32, 42, 48, 59, 61},
{11, 20, 24, 33, 41, 49, 58, 62, 71},
{21, 23, 34, 40, 50, 57, 63, 70, 72},
{22, 35, 39, 51, 56, 64, 69, 73, 78},
{36, 38, 52, 55, 65, 68, 74, 77, 79},
{37, 53, 54, 66, 67, 75, 76, 80, 81},
};
public static void zig(int n) {
int i, j;
switch (n) {
case 1:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a1[i][j]);
}
System.out.println();
}
count++;
break;
case 2:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a2[i][j]);
}
System.out.println();
}
count++;
break;
case 3:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a3[i][j]);
}
System.out.println();
}
count++;
break;
case 4:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a4[i][j]);
}
System.out.println();
}
count++;
break;
case 5:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a5[i][j]);
}
System.out.println();
}
count++;
break;
case 6:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a6[i][j]);
}
System.out.println();
}
count++;
break;
case 7:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a7[i][j]);
}
System.out.println();
}
count++;
break;
case 8:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a8[i][j]);
}
System.out.println();
}
count++;
break;
case 9:
System.out.printf("Case %d:\n", count);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
System.out.printf("%3d", a9[i][j]);
}
System.out.println();
}
count++;
break;
default:
break;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
zig(n);
}
}
}
|
[["-", 0, 124, 49, 200, 51, 518, 0, 518, 0, 499], ["+", 0, 124, 49, 200, 51, 518, 0, 518, 0, 499]]
| 3
| 1,570
|
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String is;
String ia[];
int cc = 1;
while (true) {
int n = Integer.parseInt(in.readLine());
if (n == 0) {
break;
}
int c = 1;
int v[][] = new int[n][n];
for (int i = 0; i <= 2 * (n - 1); ++i) {
int j;
int d;
if (i % 2 == 1) {
d = 1;
j = 0;
if (i >= n) {
j = i - n + 1;
}
} else {
d = -1;
j = i;
if (i >= n) {
j = n - 1;
}
}
int e, s;
if (i < n) {
s = 0;
e = i;
} else {
s = i - n + 1;
e = n - 1;
}
while (s <= j && j <= e) {
v[j][i - j] = c++;
j += d;
}
}
System.out.println("Case " + cc + ":");
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
System.out.printf("%3d", v[i][j]);
}
System.out.printf("\n");
}
}
}
}
|
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String is;
String ia[];
int cc = 1;
while (true) {
int n = Integer.parseInt(in.readLine());
if (n == 0) {
break;
}
int c = 1;
int v[][] = new int[n][n];
for (int i = 0; i <= 2 * (n - 1); ++i) {
int j;
int d;
if (i % 2 == 1) {
d = 1;
j = 0;
if (i >= n) {
j = i - n + 1;
}
} else {
d = -1;
j = i;
if (i >= n) {
j = n - 1;
}
}
int e, s;
if (i < n) {
s = 0;
e = i;
} else {
s = i - n + 1;
e = n - 1;
}
while (s <= j && j <= e) {
v[j][i - j] = c++;
j += d;
}
}
System.out.println("Case " + cc + ":");
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
System.out.printf("%3d", v[i][j]);
}
System.out.printf("\n");
}
++cc;
}
}
}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 27, 0, 29], ["+", 0, 52, 8, 196, 0, 1, 0, 27, 0, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 3
| 346
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
static int matrix[][];
static int n;
static int i, j, m;
static int c;
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int c = 0;
try {
while (true) {
n = Integer.parseInt(br.readLine());
if (n == 0)
return;
c++;
matrix = new int[n][n];
i = 0;
j = 0;
m = 1;
while (i < n - 1 || j < n - 1) {
migiue();
if (j < n - 1) {
j++;
} else {
i++;
}
hidarishita();
if (i < n - 1) {
i++;
} else {
j++;
}
}
matrix[n - 1][n - 1] = m;
print(matrix);
}
} catch (Exception e) {
System.err.println(e);
}
}
static void migiue() {
while (i > 0 && j < n - 1) {
matrix[i][j] = m;
m++;
i--;
j++;
}
matrix[i][j] = m;
m++;
}
static void hidarishita() {
while (j > 0 && i < n - 1) {
matrix[i][j] = m;
m++;
j--;
i++;
}
matrix[i][j] = m;
m++;
}
static void print(int m[][]) {
System.out.println("Case " + c + ":");
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length; j++) {
System.out.print(String.format("%1$3d", m[i][j]));
}
System.out.println();
}
}
}
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
static int matrix[][];
static int n;
static int i, j, m;
static int c;
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
c = 0;
try {
while (true) {
n = Integer.parseInt(br.readLine());
if (n == 0)
return;
c++;
matrix = new int[n][n];
i = 0;
j = 0;
m = 1;
while (i < n - 1 || j < n - 1) {
migiue();
if (j < n - 1) {
j++;
} else {
i++;
}
hidarishita();
if (i < n - 1) {
i++;
} else {
j++;
}
}
matrix[n - 1][n - 1] = m;
print(matrix);
}
} catch (Exception e) {
System.err.println(e);
}
}
static void migiue() {
while (i > 0 && j < n - 1) {
matrix[i][j] = m;
m++;
i--;
j++;
}
matrix[i][j] = m;
m++;
}
static void hidarishita() {
while (j > 0 && i < n - 1) {
matrix[i][j] = m;
m++;
j--;
i++;
}
matrix[i][j] = m;
m++;
}
static void print(int m[][]) {
System.out.println("Case " + c + ":");
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length; j++) {
System.out.print(String.format("%1$3d", m[i][j]));
}
System.out.println();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 503, 39, 506, 0, 507]]
| 3
| 434
|
#include <stdio.h>
char map[10][10];
int main() {
int i, j, k, ic = 1, n, nx;
do {
scanf("%d", &n);
if (!n)
break;
for (i = 0, nx = 1; i < n; i++) {
if (i % 2) {
for (j = 0; j < i + 1; j++, nx++) {
map[j][i - j] = nx;
}
} else {
for (j = 0; j < i + 1; j++, nx++) {
map[i - j][j] = nx;
}
}
}
nx = n * n;
for (i = n - 1; i > 0; i--) {
if (i % 2 == 0) {
for (j = n - 1, k = i; j > i - 1; j--, nx--, k++) {
map[j][k] = nx;
}
} else {
for (j = n - 1, k = i; j > i - 1; j--, nx--, k++) {
map[k][j] = nx;
}
}
}
printf("Case %d:\n", ic++);
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
printf("%2d ", map[i][j]);
}
printf("%2d\n", map[i][j]);
}
} while (1);
return 0;
}
|
#include <stdio.h>
char map[10][10];
int main() {
int i, j, k, ic = 1, n, nx;
do {
scanf("%d", &n);
if (!n)
break;
for (i = 0, nx = 1; i < n; i++) {
if (i % 2) {
for (j = 0; j < i + 1; j++, nx++) {
map[j][i - j] = nx;
}
} else {
for (j = 0; j < i + 1; j++, nx++) {
map[i - j][j] = nx;
}
}
}
nx = n * n;
for (i = n - 1; i > 0; i--) {
if (i % 2 == n % 2) {
for (j = n - 1, k = i; j > i - 1; j--, nx--, k++) {
map[j][k] = nx;
}
} else {
for (j = n - 1, k = i; j > i - 1; j--, nx--, k++) {
map[k][j] = nx;
}
}
}
printf("Case %d:\n", ic++);
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
printf(" %2d", map[i][j]);
}
printf(" %2d\n", map[i][j]);
}
} while (1);
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 109], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 342
|
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
int a, b;
while (cin >> a >> b) {
if (a < b)
swap(a, b);
cout << gcd(a, b);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
int a, b;
while (cin >> a >> b) {
if (a < b)
swap(a, b);
cout << gcd(a, b) << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 93
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<int> a(2);
while (cin >> a[0] >> a[1]) {
while (1) {
sort(a.begin(), a.end());
if (a[1] % a[0] == 0) {
cout << a[0] << endl;
break;
}
int d = a[1];
a[1] = a[1] % a[0];
a[0] = d;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<int> a(2);
while (cin >> a[0] >> a[1]) {
while (1) {
sort(a.begin(), a.end());
if (a[1] % a[0] == 0) {
cout << a[0] << endl;
break;
}
int d = a[0];
a[0] = a[1] % a[0];
a[1] = d;
}
}
}
|
[["-", 0, 43, 49, 50, 51, 69, 341, 342, 0, 13], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 13], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13]]
| 1
| 121
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
if (a < b)
swap(a, b);
for (int i = a; i > 1; i--) {
if (b % i == 0 && a % i == 0) {
cout << i << endl;
break;
}
}
}
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
if (a < b)
swap(a, b);
for (int i = a; i > 0; i--) {
if (b % i == 0 && a % i == 0) {
cout << i << endl;
break;
}
}
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 86
|
#include <iostream>
int eucgcd(int m, int n) {
int p = m % n;
while (p > 0) {
m = n;
n = p;
p = m % n;
}
return n;
}
int main() {
int m, n;
while (std::cin >> m >> n, (m || n)) {
if (m >= n)
std::cout << eucgcd(m, n) << std::endl;
else
std::cout << eucgcd(n, m) << std::endl;
break;
}
return 0;
}
|
#include <iostream>
int eucgcd(int m, int n) {
int p = m % n;
while (p > 0) {
m = n;
n = p;
p = m % n;
}
return n;
}
int main() {
int m, n;
while (std::cin >> m >> n && m && n) {
if (m >= n)
std::cout << eucgcd(m, n) << std::endl;
else
std::cout << eucgcd(n, m) << std::endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["-", 0, 52, 15, 339, 51, 34, 12, 23, 0, 24], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 98], ["-", 15, 339, 51, 34, 12, 23, 0, 16, 17, 106], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 8, 9, 0, 57, 75, 76, 0, 1, 0, 35], ["-", 8, 9, 0, 52, 8, 9, 0, 93, 0, 94]]
| 1
| 116
|
#include <cstdio>
using namespace std;
int main() {
int a, b;
while (scanf("%d %d", &a, &b) != 2) {
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
printf("%d\n", a);
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main() {
int a, b;
while (scanf("%d %d", &a, &b) == 2) {
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
printf("%d\n", a);
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60]]
| 1
| 72
|
#include <iostream>
using namespace std;
int gcd(int m, int n) {
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
// ユークリッドの方法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
};
int main(int argc, const char *argv[]) {
int n, m;
while (cin >> n >> m) {
// std::cout << n << "," << m << "\n";
cout << gcd(m, n);
}
return 0;
}
|
#include <iostream>
using namespace std;
int gcd(int m, int n) {
if ((0 == m) || (0 == n))
return 0;
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
};
int main(int argc, const char *argv[]) {
int n, m;
while (cin >> n >> m) {
cout << gcd(m, n) << "\n";
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
| 1
| 110
|
def gcd(a, b)
gcd(b, a) if b > a
return b if (r = a % b).zero?
gcd(b, r)
end
while str = gets do
a, b = str.chomp.split(" ").to_i
puts gcd(a, b)
end
|
def gcd(a, b)
gcd(b, a) if b > a
return b if (r = a % b).zero?
gcd(b, r)
end
while str = gets do
a, b = str.chomp.split(" ").map(&:to_i)
puts gcd(a, b)
end
|
[["-", 0, 89, 8, 170, 0, 662, 12, 652, 735, 22], ["+", 0, 89, 8, 170, 0, 662, 12, 652, 735, 22], ["+", 8, 170, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 652, 3, 4, 0, 752, 0, 67], ["+", 0, 662, 12, 652, 3, 4, 0, 752, 0, 753], ["+", 8, 170, 0, 662, 12, 652, 3, 4, 0, 25]]
| 4
| 65
|
#include <bits/stdc++.h>
using namespace std;
void sik(int);
int gr[7][7];
int ch[7];
int co[7];
int main() {
while (1) {
//
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
gr[i][j] = 0;
ch[i] = -1;
co[i] = 0;
}
}
int f = 0;
//
int n;
cin >> n;
if (cin.eof())
break;
int st;
for (int i = 0; i < n; i++) {
int bu;
cin >> bu;
gr[bu / 10][bu % 10] = 1;
gr[bu % 10][bu / 10] = 1;
ch[bu % 10] = 0;
ch[bu / 10] = 0;
co[bu / 10]++;
co[bu % 10]++;
st = bu % 10;
}
int cok = 0;
for (int i = 0; i < 7; i++) {
if (co[i] % 2)
cok++;
}
if (cok > 2)
f = 1;
sik(st);
for (int i = 0; i < 7; i++) {
if (ch[i] == 0)
f = 1;
}
if (f)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
void sik(int a) {
for (int i = 0; i < 7; i++) {
if (gr[a][i]) {
if (ch[i])
break;
else {
ch[i] = 1;
sik(i);
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
void sik(int);
int gr[7][7];
int ch[7];
int co[7];
int main() {
while (1) {
//
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
gr[i][j] = 0;
ch[i] = -1;
co[i] = 0;
}
}
int f = 0;
//
int n;
cin >> n;
if (cin.eof())
break;
int st;
for (int i = 0; i < n; i++) {
int bu;
cin >> bu;
gr[bu / 10][bu % 10] = 1;
gr[bu % 10][bu / 10] = 1;
ch[bu % 10] = 0;
ch[bu / 10] = 0;
co[bu / 10]++;
co[bu % 10]++;
st = bu % 10;
}
int cok = 0;
for (int i = 0; i < 7; i++) {
if (co[i] % 2)
cok++;
}
if (cok > 2)
f = 1;
sik(st);
for (int i = 0; i < 7; i++) {
// cout << ch[i] << endl;
if (ch[i] == 0)
f = 1;
}
if (f)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
void sik(int a) {
for (int i = 0; i < 7; i++) {
if (gr[a][i]) {
if (ch[i])
continue;
else {
ch[i] = 1;
sik(i);
}
}
}
}
|
[["-", 0, 57, 64, 9, 0, 57, 64, 93, 0, 94], ["+", 0, 57, 64, 9, 0, 57, 64, 116, 0, 117]]
| 1
| 380
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int N;
int boss[7], height[7];
int get_boss(int id) {
if (boss[id] == id)
return id;
else {
return boss[id] = get_boss(boss[id]);
}
}
void unite(int x, int y) {
int boss_x = get_boss(x);
int boss_y = get_boss(y);
if (boss_x == boss_y)
return;
if (height[x] > height[y]) {
boss[boss_y] = boss_x;
} else if (height[x] < height[y]) {
boss[boss_x] = boss_y;
} else { // height[x] == height[y]
boss[boss_y] = boss_x;
height[x]++;
}
}
void init() {
for (int i = 0; i < 7; i++) {
boss[i] = i;
height[i] = 0;
}
}
int main() {
int array[7], num, num_KI, num_boss;
char buf[3];
int a, b;
bool FLG;
while (scanf("%d", &N) != EOF) {
init();
for (int i = 0; i < 7; i++)
array[i] = 0;
for (int i = 0; i < N; i++) {
scanf("%s", buf);
a = buf[0] - '0';
b = buf[1] - '0';
array[a]++;
array[b]++;
unite(a, b);
}
FLG = true;
num_KI = 0;
for (int i = 0; i < 7; i++)
if (array[i] % 2 == 1)
num_KI++;
if (num_KI > 2) {
printf("No\n");
continue;
}
num_boss = 0;
for (int i = 0; i < 7; i++) {
if (array[i] > 0 && boss[i] == get_boss(i))
num_boss++;
}
if (num_boss > 1)
FLG = false;
if (FLG) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int N;
int boss[7], height[7];
int get_boss(int id) {
if (boss[id] == id)
return id;
else {
return boss[id] = get_boss(boss[id]);
}
}
void unite(int x, int y) {
int boss_x = get_boss(x);
int boss_y = get_boss(y);
if (boss_x == boss_y)
return;
if (height[x] > height[y]) {
boss[boss_y] = boss_x;
} else if (height[x] < height[y]) {
boss[boss_x] = boss_y;
} else { // height[x] == height[y]
boss[boss_y] = boss_x;
height[x]++;
}
}
void init() {
for (int i = 0; i < 7; i++) {
boss[i] = i;
height[i] = 0;
}
}
int main() {
int array[7], num, num_KI, num_boss;
char buf[3];
int a, b;
bool FLG;
while (scanf("%d", &N) != EOF) {
init();
for (int i = 0; i < 7; i++)
array[i] = 0;
for (int i = 0; i < N; i++) {
scanf("%s", buf);
a = buf[0] - '0';
b = buf[1] - '0';
array[a]++;
array[b]++;
unite(a, b);
}
FLG = true;
num_KI = 0;
for (int i = 0; i < 7; i++)
if (array[i] % 2 == 1)
num_KI++;
if (num_KI > 2) {
printf("No\n");
continue;
}
num_boss = 0;
for (int i = 0; i < 7; i++) {
if (array[i] > 0 && i == get_boss(i))
num_boss++;
}
if (num_boss > 1)
FLG = false;
if (FLG) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 16, 31, 69, 28, 22], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 73]]
| 1
| 499
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> void debug(T begin, T end) {
for (T i = begin; i != end; ++i)
cerr << *i << " ";
cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int V = 7;
typedef vector<int> node;
bool judge(vector<node> &G) {
bool exist[V] = {};
REP(i, V) exist[i] = (G[i].size() > 0);
int s = -1;
REP(i, V) if (exist[i]) s = i;
assert(s != -1);
queue<int> que;
bool used[V] = {};
que.push(s);
used[s] = true;
while (!que.empty()) {
int u = que.front();
que.pop();
REP(i, G[u].size()) {
int v = G[u][i];
if (used[v])
continue;
used[v] = true;
que.push(v);
}
}
REP(i, V) if (exist[i] && !used[i]) return false;
int odd = 0;
REP(i, V) if (G[i].size() % 2 == 1) odd++;
return (odd == 2 || odd == 0);
}
int main() {
int N;
while (cin >> N && N) {
vector<node> G(6);
REP(i, N) {
string s;
cin >> s;
int u = s[0] - '0';
int v = s[1] - '0';
G[u].push_back(v);
G[v].push_back(u);
}
if (judge(G))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> void debug(T begin, T end) {
for (T i = begin; i != end; ++i)
cerr << *i << " ";
cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int V = 7;
typedef vector<int> node;
bool judge(vector<node> &G) {
bool exist[V] = {};
REP(i, V) exist[i] = (G[i].size() > 0);
int s = -1;
REP(i, V) if (exist[i]) s = i;
assert(s != -1);
queue<int> que;
bool used[V] = {};
que.push(s);
used[s] = true;
while (!que.empty()) {
int u = que.front();
que.pop();
REP(i, G[u].size()) {
int v = G[u][i];
if (used[v])
continue;
used[v] = true;
que.push(v);
}
}
REP(i, V) if (exist[i] && !used[i]) return false;
int odd = 0;
REP(i, V) if (G[i].size() % 2 == 1) odd++;
return (odd == 2 || odd == 0);
}
int main() {
int N;
while (cin >> N && N) {
vector<node> G(7);
REP(i, N) {
string s;
cin >> s;
int u = s[0] - '0';
int v = s[1] - '0';
G[u].push_back(v);
G[v].push_back(u);
}
if (judge(G))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
| 1
| 581
|
#include <iostream>
using namespace std;
int n, a;
int t[7], u[2];
bool v[7][7];
bool ud[7], vd[7];
void dfs(int pos) {
if (vd[pos] == true)
return;
vd[pos] = true;
for (int i = 0; i < 7; i++) {
if (v[pos][i] == false)
continue;
dfs(i);
}
}
bool check() {
for (int i = 0; i < 7; i++)
vd[i] = false;
for (int i = 0; i < 7; i++)
if (t[i] > 0)
dfs(i);
for (int i = 0; i < 7; i++) {
if (t[i] > 0 && vd[i] == false)
return false;
}
return true;
}
int main() {
while (cin >> n) {
for (int i = 0; i < 7; i++)
t[i] = 0;
for (int i = 0; i < 7; i++)
for (int j = 0; j < 7; j++)
v[i][j] = false;
u[0] = u[1] = 0;
for (int i = 0; i < n; i++) {
cin >> a;
t[a / 10]++;
t[a % 10]++;
v[a / 10][a % 10] = v[a % 10][a / 10] = true;
}
for (int i = 0; i < 7; i++)
if (t[i] > 0)
u[t[i] % 2]++;
if ((u[1] == 2 || u[1] == 0) && check())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int n, a;
int t[7], u[2];
bool v[7][7];
bool ud[7], vd[7];
void dfs(int pos) {
if (vd[pos] == true)
return;
vd[pos] = true;
for (int i = 0; i < 7; i++) {
if (v[pos][i] == false)
continue;
dfs(i);
}
}
bool check() {
for (int i = 0; i < 7; i++)
vd[i] = false;
for (int i = 0; i < 7; i++)
if (t[i] > 0) {
dfs(i);
break;
}
for (int i = 0; i < 7; i++) {
if (t[i] > 0 && vd[i] == false)
return false;
}
return true;
}
int main() {
while (cin >> n) {
for (int i = 0; i < 7; i++)
t[i] = 0;
for (int i = 0; i < 7; i++)
for (int j = 0; j < 7; j++)
v[i][j] = false;
u[0] = u[1] = 0;
for (int i = 0; i < n; i++) {
cin >> a;
t[a / 10]++;
t[a % 10]++;
v[a / 10][a % 10] = v[a % 10][a / 10] = true;
}
for (int i = 0; i < 7; i++)
if (t[i] > 0)
u[t[i] % 2]++;
if ((u[1] == 2 || u[1] == 0) && check())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 7, 8, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 57, 64, 9, 0, 1, 0, 35], ["+", 0, 7, 8, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 7, 8, 57, 64, 9, 0, 46]]
| 1
| 419
|
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
class UnionFind {
private:
int n;
vector<int> a;
public:
UnionFind(int n) : n(n), a(n, -1) {}
int find(int x) { return a[x] < 0 ? x : (a[x] = find(a[x])); }
bool equal(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (a[x] > a[y])
swap(x, y);
a[x] += a[y];
a[y] = x;
--n;
}
int size() { return n; }
};
int main() {
int n;
while (cin >> n) {
int cnt[6] = {};
UnionFind uf(6);
rep(i, n) {
string domino;
cin >> domino;
++cnt[domino[0] - '0'];
++cnt[domino[1] - '0'];
uf.unite(domino[0] - '0', domino[1] - '0');
}
int c = 0;
rep(i, 6) if (cnt[i] % 2)++ c;
if (c > 2) {
cout << "No" << endl;
continue;
}
c = 0;
rep(i, 6) if (!cnt[i])++ c;
if (uf.size() == c + 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
class UnionFind {
private:
int n;
vector<int> a;
public:
UnionFind(int n) : n(n), a(n, -1) {}
int find(int x) { return a[x] < 0 ? x : (a[x] = find(a[x])); }
bool equal(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (a[x] > a[y])
swap(x, y);
a[x] += a[y];
a[y] = x;
--n;
}
int size() { return n; }
};
int main() {
int n;
while (cin >> n) {
int cnt[7] = {};
UnionFind uf(7);
rep(i, n) {
string domino;
cin >> domino;
++cnt[domino[0] - '0'];
++cnt[domino[1] - '0'];
uf.unite(domino[0] - '0', domino[1] - '0');
}
int c = 0;
rep(i, 7) if (cnt[i] % 2)++ c;
if (c > 2) {
cout << "No" << endl;
continue;
}
c = 0;
rep(i, 7) if (!cnt[i])++ c;
if (uf.size() == c + 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
| 1
| 382
|
import java.util.*;
class Main {
public static void main(String args[]) {
Solve s = new Solve();
s.solve();
}
}
class Solve {
Scanner in = new Scanner(System.in);
void solve() {
while (in.hasNext()) {
int n = in.nextInt();
int ans = 0, t = 1;
for (int i = 0; i < n / 2; i++) {
ans += t;
t += 2;
}
ans *= 2;
if (n % 2 == 1)
ans += t;
System.out.println(ans);
}
}
}
|
import java.util.*;
class Main {
public static void main(String args[]) {
Solve s = new Solve();
s.solve();
}
}
class Solve {
Scanner in = new Scanner(System.in);
void solve() {
while (in.hasNext()) {
int n = in.nextInt();
int ans = 0, t = 1;
for (int i = 0; i < n / 2; i++) {
ans += t;
t *= 3;
}
ans *= 2;
if (n % 2 == 1)
ans += t;
System.out.println(ans);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 17, 107], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 499], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 17, 108], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 499]]
| 3
| 137
|
#include <iostream>
using namespace std;
int n, f[33];
int main() {
f[1] = 1, f[2] = 2, f[3] = 5;
for (int i = 4; i <= 30; i++) {
if (i & 1) {
f[i] = 4;
for (int j = 1; j < i / 2; j++)
f[i] *= 3;
f[i] += f[i - 2];
} else {
f[i] = 1;
for (int j = 1; j < i / 2; i++)
f[i] *= 3;
f[i] += f[i - 1];
}
}
while (cin >> n) {
cout << f[n] << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int n, f[33];
int main() {
f[1] = 1, f[2] = 2, f[3] = 5;
for (int i = 4; i <= 30; i++) {
if (i & 1) {
f[i] = 4;
for (int j = 1; j < i / 2; j++)
f[i] *= 3;
f[i] += f[i - 2];
} else {
f[i] = 1;
for (int j = 1; j < i / 2; j++)
f[i] *= 3;
f[i] += f[i - 1];
}
}
while (cin >> n) {
cout << f[n] << endl;
}
return 0;
}
|
[["-", 75, 76, 0, 9, 0, 7, 26, 27, 28, 22], ["+", 75, 76, 0, 9, 0, 7, 26, 27, 28, 22]]
| 1
| 172
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[40] = {}, p = 1;
for (int i = 1; i < 40; i++) {
if (i >= 2 && i % 2)
p += 2;
a[i] = a[i - 1] + p;
}
int n;
while (cin >> n) {
cout << a[n] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a[40] = {}, p = 1;
for (int i = 1; i < 40; i++) {
if (i >= 2 && i % 2)
p *= 3;
a[i] = a[i - 1] + p;
}
int n;
while (cin >> n) {
cout << a[n] << endl;
}
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 107], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 108], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13]]
| 1
| 89
|
#include <iostream>
using namespace std;
int ans[31];
int main(void) {
ans[1] = 1;
ans[2] = 2;
ans[3] = 5;
ans[4] = 8;
for (int i = 5; i <= 30; ++i) {
if (i % 2 == 1) {
ans[i] = 2 * ans[i - 1] + 1;
} else {
ans[i] = ans[i - 1] + (2 * ans[i - 2] + 1);
}
}
while (true) {
int n;
cin >> n;
if (cin.eof())
break;
cout << ans[n] << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int ans[31];
int main(void) {
ans[1] = 1;
ans[2] = 2;
ans[3] = 5;
ans[4] = 8;
for (int i = 5; i <= 30; ++i) {
if (i % 2 == 1) {
ans[i] = 2 * ans[i - 1] + 1;
} else {
ans[i] = ans[i - 1] + ans[i - 2] + 1;
}
}
while (true) {
int n;
cin >> n;
if (cin.eof())
break;
cout << ans[n] << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 31, 13], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 1
| 152
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n > 2) {
if (n % 2)
n = 1 + 2 * (pow(3, (n - 2) / 2) - 1);
else
n = 2 + 3 * (pow(3, (n - 2) / 2) - 1);
}
cout << n << endl;
}
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n > 2) {
if (n % 2)
n = 1 + 2 * (pow(3, (n - 1) / 2) - 1);
else
n = 2 + 3 * (pow(3, (n - 2) / 2) - 1);
}
cout << n << endl;
}
}
|
[["-", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13]]
| 1
| 92
|
#include <cmath>
#include <cstdio>
#include <iostream>
#define print(x) printf("%d\n", x)
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
if (n % 2) {
print((int)(1 + 3 * (pow(3, (n - 2) / 2) - 1)));
} else {
print((int)(2 + 3 * (pow(3, (n - 1) / 2) - 1)));
}
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
#define print(x) printf("%d\n", x)
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
if (n % 2) {
print((int)(1 + 2 * (pow(3, (n - 1) / 2) - 1)));
} else {
print((int)(2 + 3 * (pow(3, (n - 2) / 2) - 1)));
}
}
return 0;
}
|
[["-", 0, 74, 51, 23, 0, 16, 12, 16, 31, 13], ["+", 0, 74, 51, 23, 0, 16, 12, 16, 31, 13], ["-", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13]]
| 1
| 112
|
#include <cstring>
#include <iostream>
int pow(int x, int y) {
int r = x;
for (int i = 1; i < y; i++)
r *= x;
return r;
}
int main() {
int n;
int dp[31];
memset(dp, 0, sizeof(dp));
dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= 30; i++) {
if (i % 2 == 1)
dp[i] = dp[i - 1] + pow(3, (i - 2) / 2);
if (i % 2 == 0)
dp[i] = dp[i - 2] + 2 * pow(3, (i - 2) / 2);
}
while (~scanf("%d", &n)) {
std::cout << dp[n] << std::endl;
}
return 0;
}
|
#include <cstring>
#include <iostream>
int pow(int x, int y) {
int r = x;
for (int i = 1; i < y; i++)
r *= x;
return r;
}
int main() {
int n;
int dp[31];
memset(dp, 0, sizeof(dp));
dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= 30; i++) {
if (i % 2 == 1)
dp[i] = dp[i - 1] + pow(3, (i - 1) / 2);
else if (i % 2 == 0)
dp[i] = dp[i - 2] + 2 * pow(3, (i - 2) / 2);
}
while (~scanf("%d", &n)) {
std::cout << dp[n] << std::endl;
}
return 0;
}
|
[["-", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 197
|
#include <iostream>
using namespace std;
typedef long long ll;
const int MAX = 31;
ll dp[MAX];
ll pow(ll A, ll e) {
ll res = 1;
while (e--)
res *= A;
return res;
}
int main() {
ll d = 2;
dp[0] = 0;
dp[1] = 1;
dp[2] = 2;
dp[3] = 8;
dp[4] = 8;
for (int i = 4; i < MAX; i += 2) {
ll add = pow(3, d++);
dp[i + 1] = dp[i] + add;
dp[i + 2] = dp[i + 1] + add;
}
ll n;
while (cin >> n && n)
cout << dp[n] << endl;
return 0;
}
|
#include <iostream>
using namespace std;
typedef long long ll;
const int MAX = 31;
ll dp[MAX];
ll pow(ll A, ll e) {
ll res = 1;
while (e--)
res *= A;
return res;
}
int main() {
ll d = 2;
dp[0] = 0;
dp[1] = 1;
dp[2] = 2;
dp[3] = 5;
dp[4] = 8;
for (int i = 4; i < MAX; i += 2) {
ll add = pow(3, d++);
dp[i + 1] = dp[i] + add;
dp[i + 2] = dp[i + 1] + add;
}
ll n;
while (cin >> n && n)
cout << dp[n] << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 178
|
// Aizu 1012: Operations with Finite Sets
// 2017.9.23 bal4u@uu
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 510
int set[5][110], sLen[5];
int uSet[MAX], uLen;
int ans[MAX], aLen;
char buf[MAX], *p;
int cmp(int *a, int *b) { return *a - *b; }
int expr(int *a);
int norm(int *a, int len) {
int i, j;
if (len <= 0)
return 0;
qsort(a, len, sizeof(int), cmp);
for (i = 0, j = 1; j < len; j++) {
if (a[j] != a[i]) {
if (++i != j)
a[i] = a[j];
}
}
return i + 1;
}
int bsch(int x, int *a, int len) {
int m, l = 0, r = len - 1;
if (len <= 0)
return 0;
while (l < r) {
m = (l + r) >> 1;
if (*(a + m) == x)
return 1;
if (*(a + m) < x)
l = m + 1;
else
r = m;
}
return *(a + l) == x;
}
int factor(int *a) {
int i, la, lx, f = 0;
int *x;
while (*p == 'c')
p++, f = !f;
if (*p == '(') {
p++;
x = a, lx = expr(x);
p++;
} else if (*p >= 'A' && *p <= 'E') {
int id = *p++ - 'A';
x = set[id], lx = sLen[id];
} else
while (1)
; // panic
if (f) {
for (la = i = 0; i < uLen; i++) {
if (!bsch(uSet[i], x, lx))
a[la++] = uSet[i];
}
} else {
la = lx;
if (x != a)
memcpy(a, x, sizeof(int) * la);
}
return la;
}
int expr(int *x) {
int i, lx, ly, lz, op;
int *y, *z;
lx = factor(x);
while (1) {
op = *p;
if (op == 'u' || op == 'i' || op == 'd' || op == 's')
p++;
else
break;
y = calloc(MAX, sizeof(int));
ly = factor(y);
z = calloc(MAX, sizeof(int));
lz = 0;
if (op == 'u') {
lz = lx, memcpy(z, x, sizeof(int) * lz);
for (i = 0; i < ly; i++)
z[lz++] = y[i];
lz = norm(z, lz);
} else if (op == 'i') {
for (i = 0; i < lx; i++) {
if (bsch(x[i], y, ly))
z[lz++] = x[i];
}
} else if (op == 'd') {
for (i = 0; i < lx; i++) {
if (!bsch(x[i], y, ly))
z[lz++] = x[i];
}
} else { // op == 's'
for (i = 0; i < lx; i++) {
if (!bsch(x[i], y, ly))
z[lz++] = x[i];
}
for (i = 0; i < ly; i++) {
if (!bsch(y[i], x, lx))
z[lz++] = y[i];
}
}
lx = lz, memcpy(x, z, sizeof(int) * lz);
lx = norm(x, lx);
free(z);
free(y);
}
return lx;
}
int main() {
int n, i, id, a;
char s[5];
while (1) {
memset(sLen, 0, sizeof(sLen)), uLen = 0;
while (1) {
if (scanf("%s%d", s, &n) != 2)
return 0;
if (*s == 'R')
break;
if (*s < 'A' || *s > 'E')
while (1)
; // panic
id = *s - 'A';
if (sLen[id] > 0)
while (1)
; // panic
for (i = 0; i < n; i++)
scanf("%d", &a), set[id][i] = a, uSet[uLen++] = a;
sLen[id] = norm(set[id], n);
}
uLen = norm(uSet, uLen);
scanf("%s", buf);
p = buf;
aLen = expr(ans);
aLen = norm(ans, aLen);
if (aLen == 0)
putchar('\n');
else {
printf("%d", ans[0]);
for (i = 1; i < aLen; i++)
printf(" %d", ans[i]);
putchar('\n');
}
}
return 0;
}
|
// Aizu 1012: Operations with Finite Sets
// 2017.9.23 bal4u@uu
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 510
int set[5][110], sLen[5];
int uSet[MAX], uLen;
int ans[MAX], aLen;
char buf[MAX], *p;
int cmp(int *a, int *b) { return *a - *b; }
int expr(int *a);
int norm(int *a, int len) {
int i, j;
if (len <= 0)
return 0;
qsort(a, len, sizeof(int), cmp);
for (i = 0, j = 1; j < len; j++) {
if (a[j] != a[i]) {
if (++i != j)
a[i] = a[j];
}
}
return i + 1;
}
int bsch(int x, int *a, int len) {
int m, l = 0, r = len - 1;
if (len <= 0)
return 0;
while (l < r) {
m = (l + r) >> 1;
if (*(a + m) == x)
return 1;
if (*(a + m) < x)
l = m + 1;
else
r = m;
}
return *(a + l) == x;
}
int factor(int *a) {
int i, la, lx, f = 0;
int *x;
while (*p == 'c')
p++, f = !f;
if (*p == '(') {
p++;
x = a, lx = expr(x);
p++;
} else if (*p >= 'A' && *p <= 'E') {
int id = *p++ - 'A';
x = set[id], lx = sLen[id];
} else
while (1)
; // panic
if (f) {
for (la = i = 0; i < uLen; i++) {
if (!bsch(uSet[i], x, lx))
a[la++] = uSet[i];
}
} else {
la = lx;
if (x != a)
memcpy(a, x, sizeof(int) * la);
}
return la;
}
int expr(int *x) {
int i, lx, ly, lz, op;
int *y, *z;
lx = factor(x);
while (1) {
op = *p;
if (op == 'u' || op == 'i' || op == 'd' || op == 's')
p++;
else
break;
y = calloc(MAX, sizeof(int));
ly = factor(y);
z = calloc(MAX, sizeof(int));
lz = 0;
if (op == 'u') {
lz = lx, memcpy(z, x, sizeof(int) * lz);
for (i = 0; i < ly; i++)
z[lz++] = y[i];
lz = norm(z, lz);
} else if (op == 'i') {
for (i = 0; i < lx; i++) {
if (bsch(x[i], y, ly))
z[lz++] = x[i];
}
} else if (op == 'd') {
for (i = 0; i < lx; i++) {
if (!bsch(x[i], y, ly))
z[lz++] = x[i];
}
} else { // op == 's'
for (i = 0; i < lx; i++) {
if (!bsch(x[i], y, ly))
z[lz++] = x[i];
}
for (i = 0; i < ly; i++) {
if (!bsch(y[i], x, lx))
z[lz++] = y[i];
}
}
lx = lz, memcpy(x, z, sizeof(int) * lz);
lx = norm(x, lx);
free(z);
free(y);
}
return lx;
}
int main() {
int n, i, id, a;
char s[5];
while (1) {
memset(sLen, 0, sizeof(sLen)), uLen = 0;
while (1) {
if (scanf("%s%d", s, &n) != 2)
return 0;
if (*s == 'R')
break;
if (*s < 'A' || *s > 'E')
while (1)
; // panic
id = *s - 'A';
if (sLen[id] > 0)
while (1)
; // panic
for (i = 0; i < n; i++)
scanf("%d", &a), set[id][i] = a, uSet[uLen++] = a;
sLen[id] = norm(set[id], n);
}
uLen = norm(uSet, uLen);
scanf("%s", buf);
p = buf;
aLen = expr(ans);
aLen = norm(ans, aLen);
if (aLen == 0)
puts("NULL");
else {
printf("%d", ans[0]);
for (i = 1; i < aLen; i++)
printf(" %d", ans[i]);
putchar('\n');
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["-", 64, 1, 0, 2, 3, 4, 0, 103, 0, 104], ["-", 64, 1, 0, 2, 3, 4, 0, 103, 0, 44], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 1,157
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using S = set<int>;
S U;
map<char, S> m;
string s;
int N;
int c;
S expr();
S factor();
S num();
void debug(string text) {
// return;
cout << text + " " + s << endl;
for (int i = 0; i < text.size() + 1 + N; i++) {
if (i == text.size() + 1 + c)
cout << "*";
else
cout << " ";
}
cout << endl;
}
S Union(S s1, S s2) {
for (auto v : s2) {
s1.insert(v);
}
return s1;
}
S Intersection(S s1, S s2) {
S ret;
for (auto v : s2) {
if (s1.count(v))
ret.insert(v);
}
return ret;
}
S Diff(S s1, S s2) {
S ret;
for (auto v : s1) {
if (!s2.count(v))
ret.insert(v);
}
return ret;
}
S SymDiff(S s1, S s2) {
S ret;
for (auto v : s1) {
if (!s2.count(v))
ret.insert(v);
}
for (auto v : s2) {
if (!s1.count(v))
ret.insert(v);
}
return ret;
}
S Comp(S s1) {
S ret;
for (auto v : U) {
if (!s1.count(v))
ret.insert(v);
}
return ret;
}
S expr() {
debug("expr");
S x = factor();
while (c < N) {
if (s[c] == 'u') {
c++;
x = Union(x, factor());
} else if (s[c] == 'i') {
c++;
x = Intersection(x, factor());
} else if (s[c] == 'd') {
c++;
x = Diff(x, factor());
} else if (s[c] == 's') {
c++;
x = SymDiff(x, factor());
} else
break;
}
return x;
}
S factor() {
debug("factor");
bool rev = false;
if (s[c] == 'c') {
rev = 1;
c++;
}
if (s[c] == '(') {
c++;
S ret = expr();
assert(s[c] == ')');
c++;
if (rev)
ret = Comp(ret);
return ret;
}
S ret = num();
if (rev)
ret = Comp(ret);
return ret;
}
S num() {
debug("num");
S ret = m[s[c]];
c++;
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef LOCAL
std::ifstream in("in");
std::cin.rdbuf(in.rdbuf());
#endif
while (true) {
m.clear();
U.clear();
char name;
int n;
while (true) {
if (!(cin >> name >> n))
return 0;
if (name == 'R')
break;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
U.insert(a);
m[name].insert(a);
}
}
m['U'] = U;
cin >> s;
N = s.size();
c = 0;
S ans = expr();
if (ans.size()) {
vector<int> v(ans.begin(), ans.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i != v.size() - 1)
cout << " ";
}
cout << endl;
} else {
cout << "NULL" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using S = set<int>;
S U;
map<char, S> m;
string s;
int N;
int c;
S expr();
S factor();
S num();
void debug(string text) {
return;
cout << text + " " + s << endl;
for (int i = 0; i < text.size() + 1 + N; i++) {
if (i == text.size() + 1 + c)
cout << "*";
else
cout << " ";
}
cout << endl;
}
S Union(S s1, S s2) {
for (auto v : s2) {
s1.insert(v);
}
return s1;
}
S Intersection(S s1, S s2) {
S ret;
for (auto v : s2) {
if (s1.count(v))
ret.insert(v);
}
return ret;
}
S Diff(S s1, S s2) {
S ret;
for (auto v : s1) {
if (!s2.count(v))
ret.insert(v);
}
return ret;
}
S SymDiff(S s1, S s2) {
S ret;
for (auto v : s1) {
if (!s2.count(v))
ret.insert(v);
}
for (auto v : s2) {
if (!s1.count(v))
ret.insert(v);
}
return ret;
}
S Comp(S s1) {
S ret;
for (auto v : U) {
if (!s1.count(v))
ret.insert(v);
}
return ret;
}
S expr() {
debug("expr");
S x = factor();
while (c < N) {
if (s[c] == 'u') {
c++;
x = Union(x, factor());
} else if (s[c] == 'i') {
c++;
x = Intersection(x, factor());
} else if (s[c] == 'd') {
c++;
x = Diff(x, factor());
} else if (s[c] == 's') {
c++;
x = SymDiff(x, factor());
} else
break;
}
return x;
}
S factor() {
debug("factor");
bool rev = false;
if (s[c] == 'c') {
rev = 1;
c++;
}
if (s[c] == '(') {
c++;
S ret = expr();
assert(s[c] == ')');
c++;
if (rev)
ret = Comp(ret);
return ret;
}
S ret = num();
if (rev)
ret = Comp(ret);
return ret;
}
S num() {
debug("num");
S ret = m[s[c]];
c++;
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef LOCAL
std::ifstream in("in");
std::cin.rdbuf(in.rdbuf());
#endif
while (true) {
m.clear();
U.clear();
char name;
int n;
while (true) {
if (!(cin >> name >> n))
return 0;
if (name == 'R')
break;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
U.insert(a);
m[name].insert(a);
}
}
m['U'] = U;
cin >> s;
N = s.size();
c = 0;
S ans = expr();
if (ans.size()) {
vector<int> v(ans.begin(), ans.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i != v.size() - 1)
cout << " ";
}
cout << endl;
} else {
cout << "NULL" << endl;
}
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
| 1
| 901
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] arg) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String is;
String[] ia;
while (true) {
ia = in.readLine().split("[ \t]");
int s = Integer.parseInt(ia[0]);
int d = Integer.parseInt(ia[1]);
if (s == 0 && d == 0) {
break;
}
int[][] x = new int[s][d];
for (int i = 0; i < s; ++i) {
ia = in.readLine().split("[ \t]");
for (int j = 0; j < d; ++j) {
x[i][j] = Integer.parseInt(ia[j]);
}
}
int[][] y = new int[d][d];
for (int i = 0; i < d - 1; ++i) {
ia = in.readLine().split("[ \t]");
for (int j = 0; j < d - i - 1; ++j) {
y[i][i + j + 1] = y[i + j + 1][i] = Integer.parseInt(ia[j]);
}
}
boolean[] a = new boolean[d];
Arrays.fill(a, true);
int b = 0;
while (check(a)) {
b += find_min(x, y, a);
}
System.out.println(b);
}
}
static int find_min(int[][] x, int[][] y, boolean[] b) {
int next = -1;
int c = Integer.MAX_VALUE;
for (int i = 0; i < x.length; ++i) {
for (int j = 0; j < x[i].length; ++j) {
if (b[j] && 0 < x[i][j] && x[i][j] < c) {
c = x[i][j];
next = j;
}
}
}
for (int i = 0; i < y.length; ++i) {
if (!b[i]) {
for (int j = i + 1; j < y[i].length; ++j) {
if (b[j] && 0 < y[i][j] && y[i][j] < c) {
c = y[i][j];
next = j;
}
}
}
}
b[next] = false;
return c;
}
static boolean check(boolean[] a) {
for (int i = 0; i < a.length; ++i) {
if (a[i]) {
return true;
}
}
return false;
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] arg) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String is;
String[] ia;
while (true) {
ia = in.readLine().split("[ \t]");
int s = Integer.parseInt(ia[0]);
int d = Integer.parseInt(ia[1]);
if (s == 0 && d == 0) {
break;
}
int[][] x = new int[s][d];
for (int i = 0; i < s; ++i) {
ia = in.readLine().split("[ \t]");
for (int j = 0; j < d; ++j) {
x[i][j] = Integer.parseInt(ia[j]);
}
}
int[][] y = new int[d][d];
for (int i = 0; i < d - 1; ++i) {
ia = in.readLine().split("[ \t]");
for (int j = 0; j < d - i - 1; ++j) {
y[i][i + j + 1] = y[i + j + 1][i] = Integer.parseInt(ia[j]);
}
}
boolean[] a = new boolean[d];
Arrays.fill(a, true);
int b = 0;
while (check(a)) {
b += find_min(x, y, a);
}
System.out.println(b);
}
}
static int find_min(int[][] x, int[][] y, boolean[] b) {
int next = -1;
int c = Integer.MAX_VALUE;
for (int i = 0; i < x.length; ++i) {
for (int j = 0; j < x[i].length; ++j) {
if (b[j] && 0 < x[i][j] && x[i][j] < c) {
c = x[i][j];
next = j;
}
}
}
for (int i = 0; i < y.length; ++i) {
if (!b[i]) {
for (int j = 0; j < y[i].length; ++j) {
if (b[j] && 0 < y[i][j] && y[i][j] < c) {
c = y[i][j];
next = j;
}
}
}
}
b[next] = false;
return c;
}
static boolean check(boolean[] a) {
for (int i = 0; i < a.length; ++i) {
if (a[i]) {
return true;
}
}
return false;
}
}
|
[["-", 0, 7, 502, 503, 49, 200, 51, 16, 31, 22], ["-", 0, 7, 502, 503, 49, 200, 51, 16, 17, 72], ["-", 0, 7, 502, 503, 49, 200, 51, 16, 12, 499], ["+", 64, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
| 3
| 629
|
s, m, k;
main() {
for (; scanf("%d", &m), k-- ? (s += m) : (k = m / 4);
k ?: (s = !printf("%d\n", s)))
;
}
|
s, k;
main(m) {
for (; scanf("%d", &m), k-- ? s += m, 1 : (k = m / 4);
k ?: (s = !printf("%d\n", s)))
;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 49, 22], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 0, 21], ["+", 36, 36, 0, 30, 0, 14, 49, 65, 0, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35], ["-", 0, 7, 15, 34, 12, 41, 64, 23, 0, 24], ["-", 0, 7, 15, 34, 12, 41, 64, 23, 0, 25], ["+", 0, 7, 15, 34, 12, 41, 0, 42, 0, 21], ["+", 0, 7, 15, 34, 12, 41, 0, 42, 0, 13]]
| 0
| 61
|
main(l, h, a) {
for (; scanf("%d", &l) * l; printf("%d", h))
for (h = 0; l > 1; l = l - 4, h += a)
scanf("%d", &a);
}
|
main(l, h, a) {
for (; scanf("%d", &l) * l; printf("%d\n", h))
for (h = 0; l > 1; l = l - 4, h += a)
scanf("%d", &a);
}
|
[["+", 0, 7, 26, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 65
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
int main() {
int N;
while (cin >> N && N) {
int ans = 0;
REP(i, N) {
int n;
cin >> n;
ans += n;
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
int main() {
int N;
while (cin >> N && N) {
int ans = 0;
REP(i, N / 4) {
int n;
cin >> n;
ans += n;
}
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 85], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
| 1
| 131
|
#include <iostream>
int n;
int sum = 0;
int main() {
while (1) {
sum = 0;
int a;
std::cin >> n;
if (n == 0)
break;
for (int i = 0; i < n / 4; ++i) {
std::cin >> a;
sum += a * 4;
}
std::cout << sum << std::endl;
}
return 0;
}
|
#include <iostream>
int n;
int sum = 0;
int main() {
while (1) {
sum = 0;
int a;
std::cin >> n;
if (n == 0)
break;
for (int i = 0; i < n / 4; ++i) {
std::cin >> a;
sum += a * 4;
}
std::cout << sum / 4 << std::endl;
}
return 0;
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 86
|
#include <iostream>
int main() {
while (1) {
int a = 0, c, n;
std::cin >> n;
if (n == 0)
break;
for (int i = 0; i < n / 4; i++) {
std::cin >> c;
a += c;
}
std::cout << c << std::endl;
}
return 0;
}
|
#include <iostream>
int main() {
while (1) {
int a = 0, c, n;
std::cin >> n;
if (n == 0)
break;
for (int i = 0; i < n / 4; i++) {
std::cin >> c;
a += c;
}
std::cout << a << std::endl;
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 78
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n) {
int sum = 0;
for (int i = 0; i < n / 4; ++i) {
int tmp;
cin >> tmp;
sum += tmp;
}
cout << sum << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int sum = 0;
for (int i = 0; i < n / 4; ++i) {
int tmp;
cin >> tmp;
sum += tmp;
}
cout << sum << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
| 1
| 68
|
while gets
n = $_.to_i
break if n==0
a = 0
n.times do
a += gets.to_i
end
p a
end
|
while gets
n = $_.to_i
break if n==0
a = 0
(n/4).times do
a += gets.to_i
end
p a
end
|
[["+", 0, 89, 8, 170, 0, 652, 486, 739, 0, 24], ["+", 8, 170, 0, 652, 486, 739, 0, 738, 17, 85], ["+", 8, 170, 0, 652, 486, 739, 0, 738, 12, 612], ["+", 0, 89, 8, 170, 0, 652, 486, 739, 0, 25]]
| 4
| 28
|
class Q1041
def doIt
n = gets.to_i / 4
while n > 1
calc n
n = gets.to_i / 4
end
end
def calc(n)
sum = 0
for i in 1..n
sum += gets.to_i
end
puts sum
end
end
Q1041.new.doIt
|
class Q1041
def doIt
n = gets.to_i / 4
while n > 0
calc n
n = gets.to_i / 4
end
end
def calc(n)
sum = 0
for i in 1..n
sum += gets.to_i
end
puts sum
end
end
Q1041.new.doIt
|
[["-", 0, 735, 8, 736, 0, 89, 15, 738, 12, 612], ["+", 0, 735, 8, 736, 0, 89, 15, 738, 12, 612]]
| 4
| 55
|
while True:
n = int(input())
if n == 0: break
print(sum([int(input()) for _ in range(n)]))
|
while True:
n = int(input())
if n == 0: break
print(sum([int(input()) for _ in range(n//4)]))
|
[["+", 0, 659, 12, 652, 3, 4, 0, 657, 17, 676], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 38
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
while (sc.hasNext()) {
String s = sc.nextLine();
if (s.equals("END OF INPUT"))
;
String[] str = s.split(" ");
for (String a : str) { // str[]の全長までaにいれて回す
System.out.print(a.length());
}
System.out.println();
}
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
while (sc.hasNext()) {
String s = sc.nextLine();
if (s.equals("END OF INPUT"))
break;
String[] str = s.split(" ");
for (String a : str) {
System.out.print(a.length());
}
System.out.println();
}
}
}
}
|
[["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94]]
| 3
| 115
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string S;
while (true) {
S = "";
while (S == "") {
getline(cin, S);
}
if (S == "END OF INPUT") {
break;
}
int count_ = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == ' ') {
cout << count_ << endl;
count_ = 0;
} else {
count_++;
}
}
cout << count_ << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string S;
while (true) {
S = "";
while (S == "") {
getline(cin, S);
}
if (S == "END OF INPUT") {
break;
}
int count_ = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == ' ') {
cout << count_;
count_ = 0;
} else {
count_++;
}
}
cout << count_ << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 119
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
string a;
while (cin >> a && a != "END OF INPUT") {
string h = "";
string g = "";
a += " ";
for (int i = 0; i < a.length(); i++) {
if (a[i] == ' ') {
g += to_string(h.length());
h = "";
} else
h += a[i];
}
cout << g << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
string a;
while (getline(cin, a) && a != "END OF INPUT") {
string h = "";
string g = "";
a += " ";
for (int i = 0; i < a.length(); i++) {
if (a[i] == ' ') {
g += to_string(h.length());
h = "";
} else
h += a[i];
}
cout << g << endl;
}
}
|
[["+", 0, 52, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["-", 0, 52, 15, 339, 51, 16, 31, 16, 17, 152], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 21], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25]]
| 1
| 116
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
while (getline(cin, s)) {
if (s == "END OF TEXT")
return 0;
int num = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ' ') {
cout << num;
num = 0;
} else if (i == s.size() - 1) {
cout << num + 1;
} else
num++;
}
cout << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
while (getline(cin, s)) {
if (s == "END OF INPUT")
return 0;
int num = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ' ') {
cout << num;
num = 0;
} else if (i == s.size() - 1) {
cout << num + 1;
} else
num++;
}
cout << endl;
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 5, 0, 6], ["+", 0, 57, 15, 339, 51, 16, 12, 5, 0, 6]]
| 1
| 118
|
#include <iostream>
using namespace std;
int main() {
int K;
while (cin >> K) {
if (K == 0) {
break;
} else {
int m;
for (int i = 0; i < K * (K - 1) / 2; ++i) {
int c;
cin >> c;
m += c;
}
int r;
r = m / (K - 1);
cout << r << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int K;
while (cin >> K) {
if (K == 0) {
break;
} else {
int m = 0;
for (int i = 0; i < K * (K - 1) / 2; ++i) {
int c;
cin >> c;
m += c;
}
int r;
r = m / (K - 1);
cout << r << endl;
}
}
return 0;
}
|
[["+", 75, 76, 0, 9, 0, 43, 49, 50, 0, 32], ["+", 75, 76, 0, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 96
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
while (1) {
int k, sum;
cin >> k;
int n = k * (k - 1) / 2;
vector<int> c(n);
if (k == 0)
break;
for (int i = 0; i < n; i++) {
cin >> c[i];
sum += c[i];
}
cout << sum / (k - 1) << endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
while (1) {
int k, sum = 0;
cin >> k;
int n = k * (k - 1) / 2;
vector<int> c(n);
if (k == 0)
break;
for (int i = 0; i < n; i++) {
cin >> c[i];
sum += c[i];
}
cout << sum / (k - 1) << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 101
|
#include <bits/stdc++.h>
using namespace std;
int K, a, t;
int main() {
while (scanf("%d", &K), K) {
a = 0;
for (int x = 0; x < K * (K - 1) / 2; ++x) {
scanf("%d", &t);
a += t;
}
printf("%d\n", a / (t - 1));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int K, a, t;
int main() {
while (scanf("%d", &K), K) {
a = 0;
for (int x = 0; x < K * (K - 1) / 2; ++x) {
scanf("%d", &t);
a += t;
}
printf("%d\n", a / (K - 1));
}
return 0;
}
|
[["-", 3, 4, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 31, 22]]
| 1
| 96
|
#include <iostream>
using namespace std;
int main() {
int k, sum;
while (cin >> k) {
if (k == 0)
break;
sum = 0;
for (int i = 0; i < k * (k - 1) / 2; i++) {
cin >> k;
sum += k;
}
cout << sum / (k - 1) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int k, n, sum;
while (cin >> k) {
if (k == 0)
break;
sum = 0;
for (int i = 0; i < k * (k - 1) / 2; i++) {
cin >> n;
sum += n;
}
cout << sum / (k - 1) << endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 84
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class t> using table = vector<vector<t>>;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
int main() {
while (1) {
int K;
cin >> K;
if (!K)
break;
int sum = 0;
for (int i = 0; i < K * (K - 1) / 2; ++i) {
int c;
cin >> c;
sum += c;
}
cout << sum / 2 << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class t> using table = vector<vector<t>>;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
int main() {
while (1) {
int K;
cin >> K;
if (!K)
break;
int sum = 0;
for (int i = 0; i < K * (K - 1) / 2; ++i) {
int c;
cin >> c;
sum += c;
}
cout << sum / (K - 1) << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
| 1
| 122
|
#include <iostream>
using namespace std;
int main() {
int k;
while (cin >> k) {
if (!k)
return 0;
int sum = 0;
for (int i = 0; i < k * (k - 1) / 2; i++) {
int a;
cin >> a;
sum += k;
}
cout << sum / (k - 1) << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int k;
while (cin >> k) {
if (!k)
return 0;
int sum = 0;
for (int i = 0; i < k * (k - 1) / 2; i++) {
int a;
cin >> a;
sum += a;
}
cout << sum / (k - 1) << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 83
|
#include <iostream>
using namespace std;
int main() {
int n, k, c;
for (;;) {
c = 0;
cin >> n;
if (!n)
break;
for (int i = 0; i < k * (k - 1) / 2; i++)
cin >> k, c += k;
cout << c / (n - 1) << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int n, k, c;
for (;;) {
c = 0;
cin >> n;
if (!n)
break;
for (int i = 0; i < n * (n - 1) / 2; i++)
cin >> k, c += k;
cout << c / (n - 1) << endl;
}
}
|
[["-", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22]]
| 1
| 83
|
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
while (1) {
int n;
scanf("%d", &n);
if (n == 0) {
break;
}
int cont = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j <= i; j++) {
int a;
scanf("%d", &a);
cont += a;
}
}
printf("%d\n", cont / 2);
}
}
|
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
while (1) {
int n;
scanf("%d", &n);
if (n == 0) {
break;
}
int cont = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j <= i; j++) {
int a;
scanf("%d", &a);
cont += a;
}
}
printf("%d\n", cont / (n - 1));
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
| 1
| 121
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
int main(void) {
for (int k, c, s; s = 0, cin >> k, k; cout << s / (c - 1) << endl)
rep(i, k * (k - 1) / 2) cin >> c, s += c;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
int main(void) {
for (int k, c, s; s = 0, cin >> k, k; cout << s / (k - 1) << endl)
rep(i, k * (k - 1) / 2) cin >> c, s += c;
return 0;
}
|
[["-", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22]]
| 1
| 149
|
loop {
n = gets.to_i
break if n == 0
p gets.map(&:to_i).inject(:+) / (n-1)
}
|
loop {
n = gets.to_i
break if n == 0
p gets.split.map(&:to_i).inject(:+) / (n-1)
}
|
[["+", 0, 738, 31, 652, 486, 652, 486, 652, 735, 22], ["+", 3, 4, 0, 738, 31, 652, 486, 652, 17, 131]]
| 4
| 32
|
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
priority_queue<long long int, vector<long long int>, greater<long long int>>
pq;
long long int a;
for (int i = 0; i < n; i++) {
cin >> a;
pq.push(a);
}
for (int i = 0; i < m; i++) {
cin >> a;
pq.push(a);
}
a = pq.top();
pq.pop();
long long int MAX = 0;
while (!pq.empty()) {
long long int b = pq.top();
pq.pop();
MAX = max(MAX, b - a);
a = b;
}
cout << MAX << endl;
}
return 0;
}
|
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
priority_queue<long long int, vector<long long int>, greater<long long int>>
pq;
long long int a;
for (int i = 0; i < n; i++) {
cin >> a;
pq.push(a);
}
for (int i = 0; i < m; i++) {
cin >> a;
pq.push(a);
}
a = pq.top();
pq.pop();
long long int MAX = a;
while (!pq.empty()) {
long long int b = pq.top();
pq.pop();
MAX = max(MAX, b - a);
a = b;
}
cout << MAX << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 22]]
| 1
| 203
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int MAX = 10000100;
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
int GCD(int a, int b) {
if (!b)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int main(void) {
ll n, m;
while (cin >> n >> m, n + m) {
vector<ll> tl(n + m);
rep(i, n + m) { cin >> tl[i]; }
sort(tl.begin(), tl.end());
ll maxx = 0;
rep(i, n + m - 1) { maxx = max(maxx, tl[i + 1] - tl[i]); }
cout << maxx << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int MAX = 10000100;
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
int GCD(int a, int b) {
if (!b)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int main(void) {
ll n, m;
while (cin >> n >> m, n + m) {
vector<ll> tl(n + m);
rep(i, n + m) { cin >> tl[i]; }
sort(tl.begin(), tl.end());
ll maxx = tl[0];
rep(i, n + m - 1) { maxx = max(maxx, tl[i + 1] - tl[i]); }
cout << maxx << endl;
}
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 70], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 73]]
| 1
| 228
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
int i, j;
int n, m;
while (1) {
cin >> n >> m;
if (n + m == 0)
break;
vi a(n + m + 1);
a[0] = 0;
rep(i, n) cin >> a[i + 1];
rep(i, m) cin >> a[n + i + 1];
sort(all(a));
int ans = 0;
rep(i, n + m - 1) ans = max(ans, a[i + 1] - a[i]);
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
int i, j;
int n, m;
while (1) {
cin >> n >> m;
if (n + m == 0)
break;
vi a(n + m + 1);
a[0] = 0;
rep(i, n) cin >> a[i + 1];
rep(i, m) cin >> a[n + i + 1];
sort(all(a));
int ans = 0;
rep(i, n + m) ans = max(ans, a[i + 1] - a[i]);
cout << ans << endl;
}
}
|
[["-", 0, 11, 31, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 11, 31, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 233
|
#include <algorithm>
#include <cstdio>
using namespace std;
int n, m, t[20000];
int main() {
while (scanf("%d%d", &n, &m), (n | m) != 0) {
for (int i = 0; i < n + m; i++) {
scanf("%d", &t[i]);
}
sort(t, t + n + m);
int mx = t[0];
for (int i = 1; i < n + n; i++) {
if (mx < t[i] - t[i - 1]) {
mx = t[i] - t[i - 1];
}
}
printf("%d\n", mx);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int n, m, t[20000];
int main() {
while (scanf("%d%d", &n, &m), (n | m) != 0) {
for (int i = 0; i < n + m; i++) {
scanf("%d", &t[i]);
}
sort(t, t + n + m);
int mx = t[0];
for (int i = 1; i < n + m; i++) {
if (mx < t[i] - t[i - 1]) {
mx = t[i] - t[i - 1];
}
}
printf("%d\n", mx);
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
| 1
| 162
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const string eof = "END OF INPUT";
typedef vector<string> VS;
typedef vector<int> VI;
typedef istringstream ISS;
int main() {
string line;
while (getline(cin, line)) {
if (line == eof)
break;
string s = line;
int n = s.size();
n--;
int cnt = 0;
VI L;
for (int i = 0; i < n; ++i) {
cnt = 0;
for (; i < n;) {
if (s[i] == ' ')
break;
cnt++;
i++;
}
L.push_back(cnt);
}
for (VI::iterator it_i = L.begin(); it_i != L.end(); ++it_i) {
cout << *it_i;
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const string eof = "END OF INPUT";
typedef vector<string> VS;
typedef vector<int> VI;
typedef istringstream ISS;
int main() {
string line;
while (getline(cin, line)) {
if (line == eof)
break;
string s = line;
int n = s.size();
int cnt = 0;
VI L;
for (int i = 0; i < n; ++i) {
cnt = 0;
for (; i < n;) {
if (s[i] == ' ')
break;
cnt++;
i++;
}
L.push_back(cnt);
}
for (VI::iterator it_i = L.begin(); it_i != L.end(); ++it_i) {
cout << *it_i;
}
cout << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 27, 28, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 27, 17, 68], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 205
|
#include <cmath>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
int main() {
char s[1000];
while (true) {
fgets(s, 1000, stdin);
if (s[strlen(s) - 1] == '\n') {
s[strlen(s) - 1] = '\0';
}
if (s[strlen(s) - 1] == '\r') {
s[strlen(s) - 1] = '\0';
}
if (strcmp(s, "END OF INPUT") == 0) {
break;
}
int len = 0;
for (int i = 0; i < (int)strlen(s); i++) {
if (s[i] != ' ') {
len++;
} else {
cout << len;
len = 0;
}
}
cout << len - 1 << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
int main() {
char s[1000];
while (true) {
fgets(s, 1000, stdin);
if (s[strlen(s) - 1] == '\n') {
s[strlen(s) - 1] = '\0';
}
if (s[strlen(s) - 1] == '\r') {
s[strlen(s) - 1] = '\0';
}
if (strcmp(s, "END OF INPUT") == 0) {
break;
}
int len = 0;
for (int i = 0; i < (int)strlen(s); i++) {
if (s[i] != ' ') {
len++;
} else {
cout << len;
len = 0;
}
}
cout << len << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 185
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int main() {
string str;
for (; getline(cin, str), str != "END OF INPUT";) {
int len = str.size();
int n = 0, i;
for (i = 0; i < len - 1; i++) {
if (str[i] == ' ') {
cout << n;
n = 0;
} else
n++;
}
cout << n << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int main() {
string str;
for (; getline(cin, str), str != "END OF INPUT";) {
int len = str.size();
int n = 0, i;
for (i = 0; i < len; i++) {
if (str[i] == ' ') {
cout << n;
n = 0;
} else
n++;
}
cout << n << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 276
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (cin >> str) {
if (str == "END OF INPUT")
break;
int idx = 0;
while (idx < str.size()) {
int cnt = 0;
while (idx < str.size() && str[idx++] != ' ')
cnt++;
cout << cnt;
}
cout << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (getline(cin, str)) {
if (str == "END OF INPUT")
break;
int idx = 0;
while (idx < str.size()) {
int cnt = 0;
while (idx < str.size() && str[idx++] != ' ')
cnt++;
cout << cnt;
}
cout << endl;
}
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 2, 63, 22], ["+", 0, 52, 15, 339, 51, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 152], ["+", 0, 52, 15, 339, 51, 2, 3, 4, 0, 21], ["+", 0, 52, 15, 339, 51, 2, 3, 4, 0, 25]]
| 1
| 88
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (getline(cin, str)) {
if (str == "END OF INPUT")
break;
int res = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == ' ') {
cout << res << endl;
res = 0;
} else {
res++;
}
}
cout << res << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (getline(cin, str)) {
if (str == "END OF INPUT")
break;
int res = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == ' ') {
cout << res;
res = 0;
} else {
res++;
}
}
cout << res << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 101
|
puts $_.chomp.split.map{ |i| i.length }.join(" ") until gets == "END OF INPUT\n"
|
puts $_.chomp.split(/ /).map{ |i| i.length }.join("") until gets == "END OF INPUT\n"
|
[["+", 0, 652, 486, 652, 486, 652, 3, 4, 0, 24], ["+", 486, 652, 486, 652, 3, 4, 0, 575, 0, 85], ["+", 486, 652, 486, 652, 3, 4, 0, 575, 0, 6], ["+", 0, 652, 486, 652, 486, 652, 3, 4, 0, 25], ["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
| 4
| 30
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x % (mod))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool debug = false;
/*---------------------------------------------------*/
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
map<int, int> m;
vector<pair<pi, pi>> data;
pair<pi, pi> d;
rep(i, n) {
cin >> d.second.first >> d.second.second >> d.first.first >>
d.first.second;
d.second.first = (-d.second.first);
d.first.second = (-d.first.second);
data.pb(d);
}
sort(all(data));
reverse(all(data));
int win = 0;
rep(i, n) {
if (win < 10 && m[data[i].second.first] < 3) {
cout << -data[i].second.first << endl;
m[data[i].second.first]++;
win++;
} else if (win < 20 && m[data[i].second.first] < 2) {
cout << -data[i].second.first << endl;
m[data[i].second.first]++;
win++;
} else if (win < 26 && m[data[i].second.first] == 0) {
cout << -data[i].second.first << endl;
m[data[i].second.first]++;
win++;
}
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x % (mod))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool debug = false;
/*---------------------------------------------------*/
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
map<int, int> m;
vector<pair<pi, pi>> data;
pair<pi, pi> d;
rep(i, n) {
cin >> d.second.first >> d.second.second >> d.first.first >>
d.first.second;
d.second.first = (-d.second.first);
d.first.second = (-d.first.second);
data.pb(d);
}
sort(all(data));
reverse(all(data));
int win = 0;
rep(i, n) {
if (win < 10 && m[data[i].second.second] < 3) {
cout << -data[i].second.first << endl;
m[data[i].second.second]++;
win++;
} else if (win < 20 && m[data[i].second.second] < 2) {
cout << -data[i].second.first << endl;
m[data[i].second.second]++;
win++;
} else if (win < 26 && m[data[i].second.second] == 0) {
cout << -data[i].second.first << endl;
m[data[i].second.second]++;
win++;
}
}
}
return 0;
}
|
[["-", 12, 16, 31, 69, 341, 342, 0, 118, 119, 120], ["+", 12, 16, 31, 69, 341, 342, 0, 118, 119, 120], ["-", 0, 27, 28, 69, 341, 342, 0, 118, 119, 120], ["+", 0, 27, 28, 69, 341, 342, 0, 118, 119, 120]]
| 1
| 461
|
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
class teamInfo {
public:
int id;
int u;
int a;
int p;
bool operator<(const teamInfo &ti) const {
if (ti.a < this->a)
return true;
else if (ti.a > this->a)
return false;
else {
if (ti.p < this->p)
return false;
else if (ti.a > this->a)
return true;
else {
if (ti.id > this->id)
return true;
else
return false;
}
}
}
};
int main() {
int n;
while (cin >> n && n != 0) {
vector<teamInfo> v;
map<int, int> ucnt;
for (int i = 0; i < n; i++) {
teamInfo ti;
cin >> ti.id >> ti.u >> ti.a >> ti.p;
v.push_back(ti);
}
sort(v.begin(), v.end());
int team = 0;
for (int i = 0; i < n; i++) {
if (team < 10) {
ucnt[v[i].u]++;
if (ucnt[v[i].u] >= 4) {
ucnt[v[i].u]--;
} else {
cout << v[i].id << endl;
team++;
}
} else if (team < 20) {
ucnt[v[i].u]++;
if (ucnt[v[i].u] >= 3) {
ucnt[v[i].u]--;
} else {
cout << v[i].id << endl;
team++;
}
} else if (team < 26) {
ucnt[v[i].u]++;
if (ucnt[v[i].u] >= 2) {
ucnt[v[i].u]--;
} else {
team++;
cout << v[i].id << endl;
}
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
class teamInfo {
public:
int id;
int u;
int a;
int p;
bool operator<(const teamInfo &ti) const {
if (ti.a < this->a)
return true;
else if (ti.a > this->a)
return false;
else {
if (ti.p < this->p)
return false;
else if (ti.p > this->p)
return true;
else {
if (ti.id > this->id)
return true;
else
return false;
}
}
}
};
int main() {
int n;
while (cin >> n && n != 0) {
vector<teamInfo> v;
map<int, int> ucnt;
for (int i = 0; i < n; i++) {
teamInfo ti;
cin >> ti.id >> ti.u >> ti.a >> ti.p;
v.push_back(ti);
}
sort(v.begin(), v.end());
int team = 0;
for (int i = 0; i < n; i++) {
if (team < 10) {
ucnt[v[i].u]++;
if (ucnt[v[i].u] >= 4) {
ucnt[v[i].u]--;
} else {
cout << v[i].id << endl;
team++;
}
} else if (team < 20) {
ucnt[v[i].u]++;
if (ucnt[v[i].u] >= 3) {
ucnt[v[i].u]--;
} else {
cout << v[i].id << endl;
team++;
}
} else if (team < 26) {
ucnt[v[i].u]++;
if (ucnt[v[i].u] >= 2) {
ucnt[v[i].u]--;
} else {
team++;
cout << v[i].id << endl;
}
}
}
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["-", 0, 57, 15, 339, 51, 16, 12, 118, 119, 120], ["+", 0, 57, 15, 339, 51, 16, 12, 118, 119, 120]]
| 1
| 429
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int a, b, c, d, n, cnt, tmp;
string str;
int id[300], id2[300], ac[300], wa[300], used[1001];
void change(int x) {
tmp = id[x];
id[x] = id[x + 1];
id[x + 1] = tmp;
tmp = id2[x];
id2[x] = id2[x + 1];
id2[x + 1] = tmp;
tmp = ac[x];
ac[x] = ac[x + 1];
ac[x + 1] = tmp;
tmp = wa[x];
wa[x] = wa[x + 1];
wa[x + 1] = tmp;
}
int main() {
while (cin >> n && n) {
for (int i = 0; i < n; i++) {
cin >> id[i] >> id2[300] >> ac[300] >> wa[300];
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (id[j] > id[j + 1]) {
change(j);
}
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (wa[j] > wa[j + 1]) {
change(j);
}
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (ac[j] < ac[j + 1]) {
change(j);
}
}
}
cnt = 0;
for (int i = 0; i < 1001; i++)
used[i] = 0;
for (int i = 0; i < n; i++) {
if (cnt < 10) {
if (used[id2[i]] < 3) {
used[id2[i]]++;
cout << id[i] << endl;
cnt++;
}
} else if (cnt < 20) {
if (used[id2[i]] < 2) {
used[id2[i]]++;
cout << id[i] << endl;
cnt++;
}
} else if (cnt < 26) {
if (used[id2[i]] == 0) {
used[id2[i]]++;
cout << id[i] << endl;
cnt++;
}
}
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int a, b, c, d, n, cnt, tmp;
string str;
int id[300], id2[300], ac[300], wa[300], used[1001];
void change(int x) {
tmp = id[x];
id[x] = id[x + 1];
id[x + 1] = tmp;
tmp = id2[x];
id2[x] = id2[x + 1];
id2[x + 1] = tmp;
tmp = ac[x];
ac[x] = ac[x + 1];
ac[x + 1] = tmp;
tmp = wa[x];
wa[x] = wa[x + 1];
wa[x + 1] = tmp;
}
int main() {
while (cin >> n && n) {
for (int i = 0; i < n; i++) {
cin >> id[i] >> id2[i] >> ac[i] >> wa[i];
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (id[j] > id[j + 1]) {
change(j);
}
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (wa[j] > wa[j + 1]) {
change(j);
}
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (ac[j] < ac[j + 1]) {
change(j);
}
}
}
cnt = 0;
for (int i = 0; i < 1001; i++)
used[i] = 0;
for (int i = 0; i < n; i++) {
if (cnt < 10) {
if (used[id2[i]] < 3) {
used[id2[i]]++;
cout << id[i] << endl;
cnt++;
}
} else if (cnt < 20) {
if (used[id2[i]] < 2) {
used[id2[i]]++;
cout << id[i] << endl;
cnt++;
}
} else if (cnt < 26) {
if (used[id2[i]] == 0) {
used[id2[i]]++;
cout << id[i] << endl;
cnt++;
}
}
}
}
return 0;
}
|
[["-", 31, 16, 31, 16, 12, 69, 341, 342, 0, 13], ["+", 31, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 13], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
| 1
| 568
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
String word = sc.next();
String query = sc.next();
if (query.equals("X"))
break;
ArrayList<String> elems = new ArrayList<String>();
if (word.indexOf("_") >= 0) {
String[] vals = word.split("_");
for (String val : vals) {
elems.add(val);
}
} else {
int pos = 0;
for (int i = 1; i < word.length(); ++i) {
if (Character.isUpperCase(word.charAt(i))) {
elems.add(word.substring(pos, i).toLowerCase());
pos = i;
}
}
elems.add(word.substring(pos));
}
StringBuilder result = new StringBuilder();
if (query.equals("U")) {
for (int i = 0; i < elems.size(); ++i) {
result.append(Character.toUpperCase(elems.get(i).charAt(0)));
result.append(elems.get(i).substring(1));
}
} else if (query.equals("L")) {
result.append(elems.get(0));
for (int i = 1; i < elems.size(); ++i) {
result.append(Character.toUpperCase(elems.get(i).charAt(0)));
result.append(elems.get(i).substring(1));
}
} else {
result.append(elems.get(0));
for (int i = 1; i < elems.size(); ++i) {
result.append("_");
result.append(elems.get(i));
}
}
System.out.println(result);
}
}
}
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
String word = sc.next();
String query = sc.next();
if (query.equals("X"))
break;
ArrayList<String> elems = new ArrayList<String>();
if (word.indexOf("_") >= 0) {
String[] vals = word.split("_");
for (String val : vals) {
elems.add(val);
}
} else {
int pos = 0;
for (int i = 1; i < word.length(); ++i) {
if (Character.isUpperCase(word.charAt(i))) {
elems.add(word.substring(pos, i).toLowerCase());
pos = i;
}
}
elems.add(word.substring(pos).toLowerCase());
}
StringBuilder result = new StringBuilder();
if (query.equals("U")) {
for (int i = 0; i < elems.size(); ++i) {
result.append(Character.toUpperCase(elems.get(i).charAt(0)));
result.append(elems.get(i).substring(1));
}
} else if (query.equals("L")) {
result.append(elems.get(0));
for (int i = 1; i < elems.size(); ++i) {
result.append(Character.toUpperCase(elems.get(i).charAt(0)));
result.append(elems.get(i).substring(1));
}
} else {
result.append(elems.get(0));
for (int i = 1; i < elems.size(); ++i) {
result.append("_");
result.append(elems.get(i));
}
}
System.out.println(result);
}
}
}
|
[["+", 0, 1, 0, 492, 3, 4, 0, 492, 0, 131], ["+", 0, 1, 0, 492, 3, 4, 0, 492, 141, 22], ["+", 0, 492, 3, 4, 0, 492, 3, 4, 0, 24], ["+", 75, 196, 0, 1, 0, 492, 3, 4, 0, 25]]
| 3
| 447
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string str;
while (1) {
getline(cin, str);
string name = str.substr(0, str.size() - 2);
char type = str[str.size() - 1];
if (type == 'L') {
if (name[0] >= 'a' && name[0] <= 'z') {
for (int i = 0; i < name.size(); i++) {
if (name[i] == '_') {
cout << (char)(name[i + 1] - 'a' + 'A') << flush;
i++;
} else {
cout << name[i] << flush;
}
}
cout << endl;
} else {
cout << (char)(name[0] + 'a' - 'A') << flush;
for (int i = 1; i < name.size(); i++) {
cout << name[i] << flush;
}
cout << endl;
}
} else if (type == 'U') {
if (name[0] >= 'a' && name[0] <= 'z') {
cout << (char)(name[0] - 'a' + 'A') << flush;
for (int i = 1; i < name.size(); i++) {
if (name[i] == '_') {
cout << (char)(name[i + 1] - 'a' + 'A') << flush;
i++;
} else {
cout << name[i] << flush;
}
}
cout << endl;
} else {
cout << name[0] << flush;
for (int i = 1; i < name.size(); i++) {
cout << name[i] << flush;
}
cout << endl;
}
} else if (type == 'D') {
if (name[0] >= 'a' && name[0] <= 'z') {
for (int i = 0; i < name.size(); i++) {
if (name[i] >= 'A' && name[i] <= 'Z') {
cout << '_' << flush;
cout << (char)(name[i] + 'a' - 'A') << flush;
i++;
} else {
cout << name[i] << flush;
}
}
cout << endl;
} else {
cout << (char)(name[0] - 'A' + 'a') << flush;
for (int i = 1; i < name.size(); i++) {
if (name[i] >= 'A' && name[i] <= 'Z') {
cout << '_' << flush;
cout << (char)(name[i] - 'A' + 'a') << flush;
} else
cout << name[i] << flush;
}
cout << endl;
}
} else
break;
// cout<<endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string str;
while (1) {
getline(cin, str);
string name = str.substr(0, str.size() - 2);
char type = str[str.size() - 1];
if (type == 'L') {
if (name[0] >= 'a' && name[0] <= 'z') {
for (int i = 0; i < name.size(); i++) {
if (name[i] == '_') {
cout << (char)(name[i + 1] - 'a' + 'A') << flush;
i++;
} else {
cout << name[i] << flush;
}
}
cout << endl;
} else {
cout << (char)(name[0] + 'a' - 'A') << flush;
for (int i = 1; i < name.size(); i++) {
cout << name[i] << flush;
}
cout << endl;
}
} else if (type == 'U') {
if (name[0] >= 'a' && name[0] <= 'z') {
cout << (char)(name[0] - 'a' + 'A') << flush;
for (int i = 1; i < name.size(); i++) {
if (name[i] == '_') {
cout << (char)(name[i + 1] - 'a' + 'A') << flush;
i++;
} else {
cout << name[i] << flush;
}
}
cout << endl;
} else {
cout << name[0] << flush;
for (int i = 1; i < name.size(); i++) {
cout << name[i] << flush;
}
cout << endl;
}
} else if (type == 'D') {
if (name[0] >= 'a' && name[0] <= 'z') {
for (int i = 0; i < name.size(); i++) {
if (name[i] >= 'A' && name[i] <= 'Z') {
cout << '_' << flush;
cout << (char)(name[i] + 'a' - 'A') << flush;
// i++;
} else {
cout << name[i] << flush;
}
}
cout << endl;
} else {
cout << (char)(name[0] - 'A' + 'a') << flush;
for (int i = 1; i < name.size(); i++) {
if (name[i] >= 'A' && name[i] <= 'Z') {
cout << '_' << flush;
cout << (char)(name[i] - 'A' + 'a') << flush;
} else
cout << name[i] << flush;
}
cout << endl;
}
} else
break;
// cout<<endl;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 27, 17, 29], ["-", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 650
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int W, Q;
while (cin >> W >> Q, W | Q) {
vector<char> field(W, '#');
int id, w;
for (int p = 0; p < Q; p++) {
char c;
cin >> c;
if (c == 's') {
bool flg;
int id, w;
cin >> id >> w;
for (int i = 0; i <= W - w; i++) {
flg = true;
int index;
for (int j = 0; j < w; j++) {
if (field[i + j] != '#') {
flg = false;
}
}
if (flg) {
cout << i << endl;
for (int j = 0; j < w; j++) {
field[i + j] = id + '0';
}
break;
}
}
if (!flg) {
cout << "impossible" << endl;
}
} else {
int id;
cin >> id;
for (int i = 0; i < W; i++) {
if (field[i] == id + '0')
field[i] = '#';
}
}
}
cout << "END" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int W, Q;
while (cin >> W >> Q, W | Q) {
vector<char> field(W, '#');
int id, w;
for (int p = 0; p < Q; p++) {
char c;
cin >> c;
if (c == 's') {
bool flg = false;
int id, w;
cin >> id >> w;
for (int i = 0; i <= W - w; i++) {
flg = true;
int index;
for (int j = 0; j < w; j++) {
if (field[i + j] != '#') {
flg = false;
}
}
if (flg) {
cout << i << endl;
for (int j = 0; j < w; j++) {
field[i + j] = id + '0';
}
break;
}
}
if (!flg) {
cout << "impossible" << endl;
}
} else {
int id;
cin >> id;
for (int i = 0; i < W; i++) {
if (field[i] == id + '0')
field[i] = '#';
}
}
}
cout << "END" << endl;
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 57, 64, 9, 0, 43, 49, 50, 51, 147]]
| 1
| 274
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define VI vector<int>
#define VS vector<string>
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ": " << x << endl
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1000000;
char fi[101][101];
int d[21][21];
int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int N, M;
int sx, sy;
int gx, gy;
int w, h;
int ans;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
const int MAX_V = 100;
const int MAX_N = 100;
char o[3] = {'+', '-', '*'};
#define md 1000003
int dp[353][353] = {0};
int bow[353][353] = {0};
set<string> a;
int main() {
int w, q;
while (cin >> w >> q, w != 0 && q != 0) {
string d;
int id[110] = {0};
int u[110] = {0};
bool ss[110] = {false};
while (q > 0) {
int a;
cin >> d;
if (d == "s") {
cin >> a;
cin >> id[a];
// debug(id[a]);
int h = 0, b = 0;
bool f = false;
for (int i = 0; i < w; i++) {
// debug(ss[i]);
if (!ss[i]) {
if (b == 0) {
h = i;
}
// debug(b);
b++;
if (b == id[a]) {
for (int j = h; j <= i; j++) {
ss[j] = true;
}
f = true;
u[a] = h;
cout << u[a] << endl;
break;
}
} else {
h = 0;
b = 0;
}
}
if (!f)
cout << "imposible" << endl;
}
else {
cin >> a;
for (int i = u[a]; i - u[a] < id[a]; i++) {
ss[i] = false;
}
}
q--;
}
cout << "END" << endl;
}
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define VI vector<int>
#define VS vector<string>
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ": " << x << endl
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1000000;
char fi[101][101];
int d[21][21];
int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int N, M;
int sx, sy;
int gx, gy;
int w, h;
int ans;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
const int MAX_V = 100;
const int MAX_N = 100;
char o[3] = {'+', '-', '*'};
#define md 1000003
int dp[353][353] = {0};
int bow[353][353] = {0};
set<string> a;
int main() {
int w, q;
while (cin >> w >> q, w != 0 || q != 0) {
string d;
int id[110] = {0};
int u[110] = {0};
bool ss[110] = {false};
while (q > 0) {
int a;
cin >> d;
if (d == "s") {
cin >> a;
cin >> id[a];
// debug(id[a]);
int h = 0, b = 0;
bool f = false;
for (int i = 0; i < w; i++) {
// debug(ss[i]);
if (!ss[i]) {
if (b == 0) {
h = i;
}
// debug(b);
b++;
if (b == id[a]) {
for (int j = h; j <= i; j++) {
ss[j] = true;
}
f = true;
u[a] = h;
cout << u[a] << endl;
break;
}
} else {
h = 0;
b = 0;
}
}
if (!f)
cout << "impossible" << endl;
}
else {
cin >> a;
for (int i = u[a]; i - u[a] < id[a]; i++) {
ss[i] = false;
}
}
q--;
}
cout << "END" << endl;
}
}
|
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106], ["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 566
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int N, Q;
int state[100];
signed main() {
while (cin >> N >> Q, N || Q) {
memset(state, -1, sizeof(state));
rep(i, Q) {
char c;
int a, b;
cin >> c >> a;
if (c == 's') {
cin >> b;
int pos = -1;
rep(j, N - b + 1) {
bool f = true;
rep(k, b) if (state[j + k] != -1) f = false;
if (f) {
pos = j;
rep(k, b) state[j + k] = a;
break;
}
}
if (pos >= 0)
cout << pos << endl;
else
cout << "Impossible" << endl;
} else {
rep(j, N) if (state[j] == a) state[j] = -1;
}
}
cout << "END" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int N, Q;
int state[100];
signed main() {
while (cin >> N >> Q, N || Q) {
memset(state, -1, sizeof(state));
rep(i, Q) {
char c;
int a, b;
cin >> c >> a;
if (c == 's') {
cin >> b;
int pos = -1;
rep(j, N - b + 1) {
bool f = true;
rep(k, b) if (state[j + k] != -1) f = false;
if (f) {
pos = j;
rep(k, b) state[j + k] = a;
break;
}
}
if (pos >= 0)
cout << pos << endl;
else
cout << "impossible" << endl;
} else {
rep(j, N) if (state[j] == a) state[j] = -1;
}
}
cout << "END" << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 344
|
#include <cstdio>
#include <iostream>
#include <string>
#define P pair<int, string>
using namespace std;
int main() {
int a, b;
while (cin >> b >> a, a | b) {
int c[100]{};
for (int d = 0; d < a; d++) {
char e;
cin >> e;
if (e == 's') {
int f, g;
cin >> f >> g;
f++;
int s = 0;
for (int i = 0; i < b; i++) {
if (c[i] == 0) {
s++;
if (s >= g) {
cout << i - s + 1 << endl;
for (int o = i - s + 1; o <= i; o++)
c[o] = f;
break;
}
} else
s = 0;
if (b - 1 == i)
puts("impossible");
}
} else {
int f;
cin >> f;
f++;
for (int i = 0; i < b; i++) {
if (c[i] == f)
c[i] = 0;
}
}
}
}
puts("END");
}
|
#include <cstdio>
#include <iostream>
#include <string>
#define P pair<int, string>
using namespace std;
int main() {
int a, b;
while (cin >> b >> a, a | b) {
int c[100]{};
for (int d = 0; d < a; d++) {
char e;
cin >> e;
if (e == 's') {
int f, g;
cin >> f >> g;
f++;
int s = 0;
for (int i = 0; i < b; i++) {
if (c[i] == 0) {
s++;
if (s >= g) {
cout << i - s + 1 << endl;
for (int o = i - s + 1; o <= i; o++)
c[o] = f;
break;
}
} else
s = 0;
if (b - 1 == i)
puts("impossible");
}
} else {
int f;
cin >> f;
f++;
for (int i = 0; i < b; i++) {
if (c[i] == f)
c[i] = 0;
}
}
}
puts("END");
}
}
|
[["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 245
|
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
while (true) {
int W, Q;
cin >> W >> Q;
vector<int> ws(W, -1);
map<int, pair<int, int>> m; // id = idx, w
if (W + Q == 0) {
break;
}
for (int i = 0; i < Q; i++) {
string s;
cin >> s;
if (s == "s") {
int id, w;
cin >> id >> w;
if (W == 0) {
cout << "impossible" << endl;
continue;
}
for (int j = 0; j < W; j++) {
bool isok = true;
for (int k = j; k < j + w; k++) {
if (j >= W) {
isok = false;
break;
}
if (ws[k] != -1) {
isok = false;
break;
}
}
if (isok) {
cout << j << endl;
for (int k = j; k < j + w; k++) {
ws[k] = id;
}
m[id] = pair<int, int>(j, w);
break;
}
if (j == W - w) {
cout << "impossible" << endl;
}
}
} else {
int id;
cin >> id;
for (int j = 0; j < W; j++) {
if (ws[j] == id) {
ws[j] = -1;
}
}
}
}
cout << "END" << endl;
}
return 0;
}
|
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
while (true) {
int W, Q;
cin >> W >> Q;
vector<int> ws(W, -1);
map<int, pair<int, int>> m; // id = idx, w
if (W + Q == 0) {
break;
}
for (int i = 0; i < Q; i++) {
string s;
cin >> s;
if (s == "s") {
int id, w;
cin >> id >> w;
if (W == 0) {
cout << "impossible" << endl;
continue;
}
for (int j = 0; j < W; j++) {
bool isok = true;
for (int k = j; k < j + w; k++) {
if (j >= W) {
isok = false;
break;
}
if (ws[k] != -1) {
isok = false;
break;
}
}
if (isok) {
cout << j << endl;
for (int k = j; k < j + w; k++) {
ws[k] = id;
}
m[id] = pair<int, int>(j, w);
break;
}
if (j == W - 1) {
cout << "impossible" << endl;
}
}
} else {
int id;
cin >> id;
for (int j = 0; j < W; j++) {
if (ws[j] == id) {
ws[j] = -1;
}
}
}
}
cout << "END" << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 335
|
#include <cstdio>
#include <vector>
#define R second.second
#define Z(i, a, b, c) v.insert(v.begin() + i, make_pair(a, make_pair(b, c)))
using namespace std;
main() {
int W, Q, d, w, i;
char s[2];
for (; scanf("%d%d", &W, &Q), W; puts("END")) { // some case Q==0
vector<pair<int, pair<int, int>>> v;
for (Z(0, -2, 0, 0), Z(0, -1, W, 0); Q; Q--) {
if (scanf("%s", s), *s - 'w') {
for (scanf("%d%d", &d, &w), i = 0; ~v[i].first; i++)
if (v[i + 1].second.first - v[i].R >= w) {
Z(i + 1, d, v[i].R, v[i].R + w);
printf("%d\n", v[i].R);
break;
}
if (v[i].first == -1)
puts("impossible");
} else
for (scanf("%d", &d), i = 0; i < v.size(); i++)
if (v[i].first == d) {
v.erase(v.begin() + i);
break;
}
}
}
}
|
#include <cstdio>
#include <vector>
#define R second.second
#define Z(i, a, b, c) v.insert(v.begin() + i, make_pair(a, make_pair(b, c)))
using namespace std;
main() {
int W, Q, d, w, i;
char s[2];
for (; scanf("%d%d", &W, &Q), W; puts("END")) { // some case Q==0
vector<pair<int, pair<int, int>>> v;
for (Z(0, -2, 0, 0), Z(1, -1, W, 0); Q; Q--) {
if (scanf("%s", s), *s - 'w') {
for (scanf("%d%d", &d, &w), i = 0; ~v[i].first; i++)
if (v[i + 1].second.first - v[i].R >= w) {
Z(i + 1, d, v[i].R, v[i].R + w);
printf("%d\n", v[i].R);
break;
}
if (v[i].first == -1)
puts("impossible");
} else
for (scanf("%d", &d), i = 0; i < v.size(); i++)
if (v[i].first == d) {
v.erase(v.begin() + i);
break;
}
}
}
}
|
[["-", 0, 7, 10, 34, 12, 2, 3, 4, 0, 13], ["+", 0, 7, 10, 34, 12, 2, 3, 4, 0, 13]]
| 1
| 310
|
char r[99], g[99], d[99];
main() {
int c, i, j, k;
for (; scanf("%s%s%s", r, g, d) > 2; puts("")) {
for (i = j = k = 0, c = g[j++]; i + j < strlen(r) + strlen(g);) {
// if(c==r[i]){
if (c == d[k]) { // push_down
k++;
c = r[i++];
} else { // push_right
putchar(c);
c = g[j++];
}
}
}
exit(0);
}
|
char r[99], g[99], d[99];
main() {
int c, i, j, k;
for (; scanf("%s%s%s", r, g, d) > 2; puts("")) {
for (i = j = k = 0, c = g[j++]; i + j <= strlen(r) + strlen(g);) {
// if(c==r[i]){
if (c == d[k]) { // push_down
k++;
c = r[i++];
} else { // push_right
putchar(c);
c = g[j++];
}
}
}
exit(0);
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 138
|
char r[99], g[99], *G, d[99];
main(c, i, k) {
for (; scanf("%s%s%s", r, g, d) > 1; puts(""))
for (i = k = 0, G = g, c = *G++; *G;)
c == d[k] ? k++, c = r[i++] : (putchar(c), c = *G++);
exit(0);
}
|
char r[99], g[99], *G, d[99];
main(c, i, k) {
for (; scanf("%s%s%s", r, g, d) > 1; puts(""))
for (i = k = 0, G = g, c = *G++; *(G - 1);)
c == d[k] ? k++, c = r[i++] : (putchar(c), c = *G++);
exit(0);
}
|
[["+", 0, 7, 8, 7, 15, 66, 28, 23, 0, 24], ["+", 8, 7, 15, 66, 28, 23, 0, 16, 17, 33], ["+", 8, 7, 15, 66, 28, 23, 0, 16, 12, 13], ["+", 0, 7, 8, 7, 15, 66, 28, 23, 0, 25]]
| 0
| 112
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> void debug(T begin, T end) {
for (T i = begin; i != end; ++i)
cerr << *i << " ";
cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S {
int x, y;
int cx[3];
int cy[3];
int SW;
int cost;
S() {
SW = 0;
cx[0] = cx[1] = cx[2] = 10;
cy[0] = cy[1] = cy[2] = 10;
cost = 0;
}
bool operator<(const S &s) const {
if (x != s.x)
return x < s.x;
if (y != s.y)
return y < s.y;
REP(i, 3) if (cx[i] != s.cx[i]) return cx[i] < s.cx[i];
REP(i, 3) if (cy[i] != s.cy[i]) return cy[i] < s.cy[i];
return SW < s.SW;
}
};
bool get(S &s, bool cost[10][10][11][11][11][11][11][11]) {
return cost[s.y][s.x][s.cy[0]][s.cx[0]][s.cy[1]][s.cx[1]][s.cy[2]][s.cx[2]];
}
void set_x(S &s, bool x, bool cost[10][10][11][11][11][11][11][11]) {
cost[s.y][s.x][s.cy[0]][s.cx[0]][s.cy[1]][s.cx[1]][s.cy[2]][s.cx[2]] = x;
}
void print(S &s) {
printf("x = %d y = %d SW = %d cost = %d c = (%d, %d) (%d, %d) (%d, %d)\n",
s.x, s.y, s.SW, s.cost, s.cx[0], s.cy[0], s.cx[1], s.cy[1], s.cx[2],
s.cy[2]);
}
int main() {
int H, W;
while (cin >> H >> W && H) {
vector<string> grid(H);
REP(i, H) cin >> grid[i];
int WC = 0;
int CC = 0;
int wx[3], wy[3];
S start;
REP(y, H) REP(x, W) {
if (grid[y][x] == '@') {
start.x = x, start.y = y;
}
if (grid[y][x] == 'w') {
wx[WC] = x, wy[WC] = y;
start.SW |= 1 << WC;
WC++;
}
if (grid[y][x] == 'c') {
start.cx[CC] = x;
start.cy[CC] = y;
CC++;
}
}
// static bool cost[10][10][11][11][11][11][11][11] = {};
// memset(cost, 0, sizeof(cost));
set<S> setS;
deque<S> que;
que.push_back(start);
// set_x(start, 1, cost);
setS.insert(start);
bool NG = true;
while (!que.empty()) {
S s = que.front();
que.pop_front();
print(s);
if (grid[s.y][s.x] == 'E') {
cout << s.cost << endl;
NG = false;
break;
}
REP(r, 4) {
int nx = s.x + dx[r];
int ny = s.y + dy[r];
if (!valid(nx, ny, W, H))
continue;
S next = s;
bool move = true;
REP(i, CC) {
if (nx == s.cx[i] && ny == s.cy[i]) {
move = false;
// container move
int xx = nx, yy = ny;
while (true) {
xx += dx[r];
yy += dy[r];
if (grid[yy][xx] == '#') {
xx -= dx[r];
yy -= dy[r];
goto C1;
}
REP(j, CC) if (i != j && s.cx[j] == xx && s.cy[j] == yy) {
xx -= dx[r];
yy -= dy[r];
goto C1;
}
REP(i, WC) if (s.SW >> i & 1 && wx[i] == xx && wy[i] == yy) {
next.SW ^= 1 << i;
xx = 10;
yy = 10;
goto C1;
}
}
C1:
next.cx[i] = xx, next.cy[i] = yy;
// if(!get(next, cost)){
if (!setS.count(next)) {
// set_x(next, true, cost);
setS.insert(next);
que.push_front(next);
}
}
}
REP(i, WC)
if (s.SW >> i & 1 && wx[i] == nx && wy[i] == ny) move = false;
if (!move || grid[ny][nx] == '#')
continue;
next.x = nx, next.y = ny;
// if(!get(next, cost)){
if (!setS.count(next)) {
next.cost += 1;
// set_x(next, true, cost);
setS.insert(next);
que.push_back(next);
}
}
}
if (NG)
cout << -1 << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> void debug(T begin, T end) {
for (T i = begin; i != end; ++i)
cerr << *i << " ";
cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S {
int x, y;
int cx[3];
int cy[3];
int SW;
int cost;
S() {
SW = 0;
cx[0] = cx[1] = cx[2] = 10;
cy[0] = cy[1] = cy[2] = 10;
cost = 0;
}
bool operator<(const S &s) const {
if (x != s.x)
return x < s.x;
if (y != s.y)
return y < s.y;
REP(i, 3) if (cx[i] != s.cx[i]) return cx[i] < s.cx[i];
REP(i, 3) if (cy[i] != s.cy[i]) return cy[i] < s.cy[i];
return SW < s.SW;
}
};
bool get(S &s, bool cost[10][10][11][11][11][11][11][11]) {
return cost[s.y][s.x][s.cy[0]][s.cx[0]][s.cy[1]][s.cx[1]][s.cy[2]][s.cx[2]];
}
void set_x(S &s, bool x, bool cost[10][10][11][11][11][11][11][11]) {
cost[s.y][s.x][s.cy[0]][s.cx[0]][s.cy[1]][s.cx[1]][s.cy[2]][s.cx[2]] = x;
}
void print(S &s) {
printf("x = %d y = %d SW = %d cost = %d c = (%d, %d) (%d, %d) (%d, %d)\n",
s.x, s.y, s.SW, s.cost, s.cx[0], s.cy[0], s.cx[1], s.cy[1], s.cx[2],
s.cy[2]);
}
int main() {
int H, W;
while (cin >> H >> W && H) {
vector<string> grid(H);
REP(i, H) cin >> grid[i];
int WC = 0;
int CC = 0;
int wx[3], wy[3];
S start;
REP(y, H) REP(x, W) {
if (grid[y][x] == '@') {
start.x = x, start.y = y;
}
if (grid[y][x] == 'w') {
wx[WC] = x, wy[WC] = y;
start.SW |= 1 << WC;
WC++;
}
if (grid[y][x] == 'c') {
start.cx[CC] = x;
start.cy[CC] = y;
CC++;
}
}
// static bool cost[10][10][11][11][11][11][11][11] = {};
// memset(cost, 0, sizeof(cost));
set<S> setS;
deque<S> que;
que.push_back(start);
// set_x(start, 1, cost);
setS.insert(start);
bool NG = true;
while (!que.empty()) {
S s = que.front();
que.pop_front();
// print(s);
if (grid[s.y][s.x] == 'E') {
cout << s.cost << endl;
NG = false;
break;
}
REP(r, 4) {
int nx = s.x + dx[r];
int ny = s.y + dy[r];
if (!valid(nx, ny, W, H))
continue;
S next = s;
bool move = true;
REP(i, CC) {
if (nx == s.cx[i] && ny == s.cy[i]) {
move = false;
// container move
int xx = nx, yy = ny;
while (true) {
xx += dx[r];
yy += dy[r];
if (grid[yy][xx] == '#') {
xx -= dx[r];
yy -= dy[r];
goto C1;
}
REP(j, CC) if (i != j && s.cx[j] == xx && s.cy[j] == yy) {
xx -= dx[r];
yy -= dy[r];
goto C1;
}
REP(i, WC) if (s.SW >> i & 1 && wx[i] == xx && wy[i] == yy) {
next.SW ^= 1 << i;
xx = 10;
yy = 10;
goto C1;
}
}
C1:
next.cx[i] = xx, next.cy[i] = yy;
// if(!get(next, cost)){
if (!setS.count(next)) {
// set_x(next, true, cost);
setS.insert(next);
que.push_front(next);
}
}
}
REP(i, WC)
if (s.SW >> i & 1 && wx[i] == nx && wy[i] == ny) move = false;
if (!move || grid[ny][nx] == '#')
continue;
next.x = nx, next.y = ny;
// if(!get(next, cost)){
if (!setS.count(next)) {
next.cost += 1;
// set_x(next, true, cost);
setS.insert(next);
que.push_back(next);
}
}
}
if (NG)
cout << -1 << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 1,384
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
double eps = 1e-9;
double inf = 1e30;
int N;
int M;
typedef struct tag_Point {
double X;
double Y;
} Point;
Point Add(const Point v, const Point w) {
Point P;
P.X = v.X + w.X;
P.Y = v.Y + w.Y;
return P;
}
Point Times(const double r, const Point v) {
Point P;
P.X = r * v.X;
P.Y = r * v.Y;
return P;
}
Point setPoint(const double x, const double y) {
Point P;
P.X = x;
P.Y = y;
return P;
}
double Length(const Point v) {
double r = sqrt(v.X * v.X + v.Y * v.Y);
return r;
}
void solve() {
Point Dogs[N];
double Velo[N];
Point Fris[M];
Point FVelo[M];
int i;
double d[4];
for (i = 0; i < N; i++) {
scanf("%lf %lf %lf\n", &d[0], &d[1], &d[2]);
Dogs[i].X = d[0];
Dogs[i].Y = d[1];
Velo[i] = d[2];
}
for (i = 0; i < M; i++) {
scanf("%lf %lf %lf %lf\n", &d[0], &d[1], &d[2], &d[3]);
Fris[i].X = d[0];
Fris[i].Y = d[1];
FVelo[i].X = d[2];
FVelo[i].Y = d[3];
}
int Catch[N];
for (i = 0; i < N; i++)
Catch[i] = 0;
Point UMove[N];
double Time[N];
int j;
for (i = 0; i < M; i++) {
for (j = 0; j < M; j++) {
double A =
FVelo[i].X * FVelo[i].X + FVelo[i].Y * FVelo[i].Y - Velo[j] * Velo[j];
double B = 2 * (Fris[i].X - Dogs[j].X) * FVelo[i].X +
2 * (Fris[i].Y - Dogs[j].Y) * FVelo[i].Y;
double C = (Fris[i].X - Dogs[j].X) * (Fris[i].X - Dogs[j].X) +
(Fris[i].Y - Dogs[j].Y) * (Fris[i].Y - Dogs[j].Y);
double D = B * B - 4 * A * C;
if (A <= eps && A >= -eps) {
// A=0の場合、犬とフリスビーが等速
// C=0(犬の位置とフリスビー位置が同じ(このケースは無い筈)
// B<0の時のみ解をもつ(犬とフリスビーを結ぶ線分の垂直二等分線とフリスビー軌道が交わる
if (C <= eps && C >= -eps) {
Time[j] = 0.0;
UMove[j] = setPoint(0, 0);
} else {
if (B > -eps) {
Time[j] = inf;
UMove[j] = setPoint(0, 0);
} else {
Time[j] = -C / B;
Point Ptemp1 = Fris[i];
// Ptemp1=Ptemp1.Add(FVelo[i].Times(Time[j]));
// Ptemp1=Ptemp1.Add(Dogs[j].Times(-1.0));
Ptemp1 = Add(Ptemp1, Times(Time[j], FVelo[i]));
Ptemp1 = Add(Ptemp1, Times(-1.0, Dogs[j]));
if (Length(Ptemp1) != 0) {
// UMove[j]=Ptemp1.Times(Velo[j]/Ptemp1.Length);
UMove[j] = Times(Velo[j] / Length(Ptemp1), Ptemp1);
} else {
UMove[j] = setPoint(0, 0);
}
}
}
}
if (A < -eps) {
// A<0の時は必ず解があり、かつ0の両側にある
//(A<0⇔犬の方が速い)
// フリスビーがアポロニウスの円に囲まれている
Time[j] = (-B - sqrt(D)) / (2.0 * A); //正の解
Point Ptemp = Fris[i];
// Ptemp=Ptemp.Add(FVelo[i].Times(Time[j]));
// Ptemp=Ptemp.Add(Dogs[j].Times(-1.0));
Ptemp = Add(Ptemp, Times(Time[j], FVelo[i]));
Ptemp = Add(Ptemp, Times(-1.0, Dogs[j]));
if (Length(Ptemp) != 0) {
// UMove[j]=Ptemp.Times(Velo[j]/Ptemp.Length);
UMove[j] = Times(Velo[j] / Length(Ptemp), Ptemp);
} else {
UMove[j] = setPoint(0, 0);
}
}
if (A > eps) {
// A>0の時は解がある時とない時がある
// //(A<0⇔犬の方が速い) 犬がアポロニウスの円に囲まれている
// フリスビー軌跡がT>0でアポロニウスの円と交わる時のみキャッチ可
// ⇔D>=0 かつ 解が正 この時、小さいほうの解を取る
// (解は 正,正 または 負,負 しかない)
if (D < -eps) {
Time[j] = inf;
UMove[j] = setPoint(0, 0);
} else {
// D+=eps;//RE避ける
Time[j] = (-B - sqrt(D)) / (2.0 * A); //小さい方の符号を見ればよい
if (Time[j] < -eps) {
Time[j] = inf;
UMove[j] = setPoint(0, 0);
} else {
Point Ptemp = Fris[i];
// Ptemp=Ptemp.Add(FVelo[i].Times(Time[j]));
// Ptemp=Ptemp.Add(Dogs[j].Times(-1.0));
Ptemp = Add(Ptemp, Times(Time[j], FVelo[i]));
Ptemp = Add(Ptemp, Times(-1.0, Dogs[j]));
if (Length(Ptemp) != 0) {
// UMove[j]=Ptemp.Times(Velo[j]/Ptemp.Length);
UMove[j] = Times(Velo[j] / Length(Ptemp), Ptemp);
} else {
UMove[j] = setPoint(0, 0);
}
}
}
}
}
double Tmin = inf;
int idx = -1;
for (j = 0; j < N; j++) {
if (Tmin > Time[j]) {
Tmin = Time[j];
idx = j;
}
}
// if(idx==-1)idx=0;
Catch[idx]++;
for (j = 0; j < N; j++) {
Dogs[j] = Add(Dogs[j], Times(Tmin, UMove[j]));
}
}
for (i = 0; i < N; i++) {
printf(i == 0 ? "%d" : " %d", Catch[i]);
}
printf("\n");
}
int main() {
while (1) {
scanf("%d %d\n", &N, &M);
if (!N && !M)
break;
solve();
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
double eps = 1e-9;
double inf = 1e30;
int N;
int M;
typedef struct tag_Point {
double X;
double Y;
} Point;
Point Add(const Point v, const Point w) {
Point P;
P.X = v.X + w.X;
P.Y = v.Y + w.Y;
return P;
}
Point Times(const double r, const Point v) {
Point P;
P.X = r * v.X;
P.Y = r * v.Y;
return P;
}
Point setPoint(const double x, const double y) {
Point P;
P.X = x;
P.Y = y;
return P;
}
double Length(const Point v) {
double r = sqrt(v.X * v.X + v.Y * v.Y);
return r;
}
void solve() {
Point Dogs[N];
double Velo[N];
Point Fris[M];
Point FVelo[M];
int i;
double d[4];
for (i = 0; i < N; i++) {
scanf("%lf %lf %lf\n", &d[0], &d[1], &d[2]);
Dogs[i].X = d[0];
Dogs[i].Y = d[1];
Velo[i] = d[2];
}
for (i = 0; i < M; i++) {
scanf("%lf %lf %lf %lf\n", &d[0], &d[1], &d[2], &d[3]);
Fris[i].X = d[0];
Fris[i].Y = d[1];
FVelo[i].X = d[2];
FVelo[i].Y = d[3];
}
int Catch[N];
for (i = 0; i < N; i++)
Catch[i] = 0;
Point UMove[N];
double Time[N];
int j;
for (i = 0; i < M; i++) {
for (j = 0; j < N; j++) {
double A =
FVelo[i].X * FVelo[i].X + FVelo[i].Y * FVelo[i].Y - Velo[j] * Velo[j];
double B = 2 * (Fris[i].X - Dogs[j].X) * FVelo[i].X +
2 * (Fris[i].Y - Dogs[j].Y) * FVelo[i].Y;
double C = (Fris[i].X - Dogs[j].X) * (Fris[i].X - Dogs[j].X) +
(Fris[i].Y - Dogs[j].Y) * (Fris[i].Y - Dogs[j].Y);
double D = B * B - 4 * A * C;
if (A <= eps && A >= -eps) {
// A=0の場合、犬とフリスビーが等速
// C=0(犬の位置とフリスビー位置が同じ(このケースは無い筈)
// B<0の時のみ解をもつ(犬とフリスビーを結ぶ線分の垂直二等分線とフリスビー軌道が交わる
if (C <= eps && C >= -eps) {
Time[j] = 0.0;
UMove[j] = setPoint(0, 0);
} else {
if (B > -eps) {
Time[j] = inf;
UMove[j] = setPoint(0, 0);
} else {
Time[j] = -C / B;
Point Ptemp1 = Fris[i];
// Ptemp1=Ptemp1.Add(FVelo[i].Times(Time[j]));
// Ptemp1=Ptemp1.Add(Dogs[j].Times(-1.0));
Ptemp1 = Add(Ptemp1, Times(Time[j], FVelo[i]));
Ptemp1 = Add(Ptemp1, Times(-1.0, Dogs[j]));
if (Length(Ptemp1) != 0) {
// UMove[j]=Ptemp1.Times(Velo[j]/Ptemp1.Length);
UMove[j] = Times(Velo[j] / Length(Ptemp1), Ptemp1);
} else {
UMove[j] = setPoint(0, 0);
}
}
}
}
if (A < -eps) {
// A<0の時は必ず解があり、かつ0の両側にある
//(A<0⇔犬の方が速い)
// フリスビーがアポロニウスの円に囲まれている
Time[j] = (-B - sqrt(D)) / (2.0 * A); //正の解
Point Ptemp = Fris[i];
// Ptemp=Ptemp.Add(FVelo[i].Times(Time[j]));
// Ptemp=Ptemp.Add(Dogs[j].Times(-1.0));
Ptemp = Add(Ptemp, Times(Time[j], FVelo[i]));
Ptemp = Add(Ptemp, Times(-1.0, Dogs[j]));
if (Length(Ptemp) != 0) {
// UMove[j]=Ptemp.Times(Velo[j]/Ptemp.Length);
UMove[j] = Times(Velo[j] / Length(Ptemp), Ptemp);
} else {
UMove[j] = setPoint(0, 0);
}
}
if (A > eps) {
// A>0の時は解がある時とない時がある
// //(A<0⇔犬の方が速い) 犬がアポロニウスの円に囲まれている
// フリスビー軌跡がT>0でアポロニウスの円と交わる時のみキャッチ可
// ⇔D>=0 かつ 解が正 この時、小さいほうの解を取る
// (解は 正,正 または 負,負 しかない)
if (D < -eps) {
Time[j] = inf;
UMove[j] = setPoint(0, 0);
} else {
// D+=eps;//RE避ける
Time[j] = (-B - sqrt(D)) / (2.0 * A); //小さい方の符号を見ればよい
if (Time[j] < -eps) {
Time[j] = inf;
UMove[j] = setPoint(0, 0);
} else {
Point Ptemp = Fris[i];
// Ptemp=Ptemp.Add(FVelo[i].Times(Time[j]));
// Ptemp=Ptemp.Add(Dogs[j].Times(-1.0));
Ptemp = Add(Ptemp, Times(Time[j], FVelo[i]));
Ptemp = Add(Ptemp, Times(-1.0, Dogs[j]));
if (Length(Ptemp) != 0) {
// UMove[j]=Ptemp.Times(Velo[j]/Ptemp.Length);
UMove[j] = Times(Velo[j] / Length(Ptemp), Ptemp);
} else {
UMove[j] = setPoint(0, 0);
}
}
}
}
}
double Tmin = inf;
int idx = -1;
for (j = 0; j < N; j++) {
if (Tmin > Time[j]) {
Tmin = Time[j];
idx = j;
}
}
// if(idx==-1)idx=0;
Catch[idx]++;
for (j = 0; j < N; j++) {
Dogs[j] = Add(Dogs[j], Times(Tmin, UMove[j]));
}
}
for (i = 0; i < N; i++) {
printf(i == 0 ? "%d" : " %d", Catch[i]);
}
printf("\n");
}
int main() {
while (1) {
scanf("%d %d\n", &N, &M);
if (!N && !M)
break;
solve();
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
| 0
| 1,322
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
double dx[11];
double dy[11];
double dv[11];
int ret[11];
double eps = 1e-7;
double fx[1100];
double fy[1100];
double vx[1100];
double vy[1100];
double tx[11];
double ty[11];
double ABS(double a) { return max(a, -a); }
int main() {
int a, b;
while (scanf("%d%d", &a, &b), a) {
for (int i = 0; i < a; i++) {
scanf("%lf%lf%lf", dx + i, dy + i, dv + i);
}
for (int i = 0; i < a; i++)
ret[i] = 0;
for (int i = 0; i < b; i++) {
scanf("%lf%lf%lf%lf", fx + i, fy + i, vx + i, vy + i);
}
for (int i = 0; i < b; i++) {
double val = 999999999;
int at = -1;
for (int j = 0; j < a; j++) {
if ((dx[j] - fx[i]) * (dx[j] - fx[i]) +
(dy[j] - fy[i]) * (dy[j] - fy[i]) <
eps)
at = j;
}
if (~at) {
ret[at]++;
continue;
}
for (int j = 0; j < a; j++)
tx[j] = ty[j] = 0;
for (int j = 0; j < a; j++) {
double A = vx[i] * vx[i] + vy[i] * vy[i] - dv[j] * dv[j];
double B = 2.0 * ((fx[i] - dx[j]) * vx[i] + (fy[i] - dy[j]) * vy[i]);
double C = (fx[i] - dx[j]) * (fx[i] - dx[j]) +
(fy[i] - dy[j]) * (fy[i] - dy[j]);
double t;
if (ABS(A) < eps) {
if (ABS(B) < eps)
continue;
t = -C / B;
} else if (B * B - A * C * 4 > -eps) {
t = (-B - sqrt(max(0.0, B * B - A * C * 4))) / A / 2;
if (t < 0)
t = (-B + sqrt(max(0.0, B * B - A * C * 4))) / A / 2;
} else
continue;
if (t < 0)
continue;
if (val > t) {
val = t;
at = j;
}
double sx = fx[i] + vx[i] * t;
double sy = fy[i] + vy[i] * t;
tx[j] = (sx - dx[j]) / t;
ty[j] = (sy - dx[j]) / t;
}
ret[at]++;
for (int j = 0; j < a; j++) {
dx[j] += val * tx[j];
dy[j] += val * ty[j];
}
}
for (int i = 0; i < a; i++) {
if (i)
printf(" ");
printf("%d", ret[i]);
}
printf("\n");
}
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
double dx[11];
double dy[11];
double dv[11];
int ret[11];
double eps = 1e-7;
double fx[1100];
double fy[1100];
double vx[1100];
double vy[1100];
double tx[11];
double ty[11];
double ABS(double a) { return max(a, -a); }
int main() {
int a, b;
while (scanf("%d%d", &a, &b), a) {
for (int i = 0; i < a; i++) {
scanf("%lf%lf%lf", dx + i, dy + i, dv + i);
}
for (int i = 0; i < a; i++)
ret[i] = 0;
for (int i = 0; i < b; i++) {
scanf("%lf%lf%lf%lf", fx + i, fy + i, vx + i, vy + i);
}
for (int i = 0; i < b; i++) {
double val = 999999999;
int at = -1;
for (int j = 0; j < a; j++) {
if ((dx[j] - fx[i]) * (dx[j] - fx[i]) +
(dy[j] - fy[i]) * (dy[j] - fy[i]) <
eps)
at = j;
}
if (~at) {
ret[at]++;
continue;
}
for (int j = 0; j < a; j++)
tx[j] = ty[j] = 0;
for (int j = 0; j < a; j++) {
double A = vx[i] * vx[i] + vy[i] * vy[i] - dv[j] * dv[j];
double B = 2.0 * ((fx[i] - dx[j]) * vx[i] + (fy[i] - dy[j]) * vy[i]);
double C = (fx[i] - dx[j]) * (fx[i] - dx[j]) +
(fy[i] - dy[j]) * (fy[i] - dy[j]);
double t;
if (ABS(A) < eps) {
if (ABS(B) < eps)
continue;
t = -C / B;
} else if (B * B - A * C * 4 > -eps) {
t = (-B - sqrt(max(0.0, B * B - A * C * 4))) / A / 2;
if (t < 0)
t = (-B + sqrt(max(0.0, B * B - A * C * 4))) / A / 2;
} else
continue;
if (t < 0)
continue;
if (val > t) {
val = t;
at = j;
}
double sx = fx[i] + vx[i] * t;
double sy = fy[i] + vy[i] * t;
tx[j] = (sx - dx[j]) / t;
ty[j] = (sy - dy[j]) / t;
}
ret[at]++;
for (int j = 0; j < a; j++) {
dx[j] += val * tx[j];
dy[j] += val * ty[j];
}
}
for (int i = 0; i < a; i++) {
if (i)
printf(" ");
printf("%d", ret[i]);
}
printf("\n");
}
}
|
[["-", 12, 16, 31, 23, 0, 16, 12, 69, 28, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 69, 28, 22]]
| 1
| 792
|
#include <bits/stdc++.h>
#define double long double
using namespace std;
typedef complex<double> P;
const int INF = 1e9;
double calc_time(P s, P t, P dog, double v) {
dog -= s;
double a = abs(t * t) - v * v;
double b = -2 * (t.real() * dog.real() + t.imag() * dog.imag());
double c = abs(dog * dog);
if (a < 0)
a *= -1, b *= -1, c *= -1;
double d = b * b - 4 * a * c;
if (d < 0)
return -1;
if (-b - sqrt(d) >= 0)
return (-b - sqrt(d)) / (2 * a);
if (-b + sqrt(d) >= 0)
return (-b + sqrt(d)) / (2 * a);
return -1;
}
P Go(P s, P t, P dog, double v, double x, double T) {
t -= s;
t *= T;
dog -= s;
P res = (t - dog) / abs(t - dog);
return (res * v * x) + dog + s;
}
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (!n && !m)
break;
P dog[11];
double v[11];
for (int i = 0; i < n; i++) {
double x, y;
cin >> x >> y >> v[i];
dog[i] = P(x, y);
}
int ans[11] = {};
while (m--) {
P s, t;
double x, y;
cin >> x >> y;
s = P(x, y);
cin >> x >> y;
t = P(x, y);
double mnt = INF, time[11] = {};
for (int i = 0; i < n; i++) {
time[i] = calc_time(s, t, dog[i], v[i]);
if (time[i] >= 0)
mnt = min(mnt, time[i]);
}
for (int i = 0; i < n; i++) {
if (time[i] > 0)
dog[i] = Go(s, t, dog[i], v[i], mnt, time[i]);
ans[i] += time[i] == mnt;
}
}
for (int i = 0; i < n; i++) {
if (i)
cout << " ";
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define double long double
using namespace std;
typedef complex<double> P;
const int INF = 1e9;
double calc_time(P s, P t, P dog, double v) {
dog -= s;
double a = abs(t * t) - v * v;
double b = -2 * (t.real() * dog.real() + t.imag() * dog.imag());
double c = abs(dog * dog);
if (a < 0)
a *= -1, b *= -1, c *= -1;
double d = b * b - 4 * a * c;
if (d < 0)
return -1;
if (-b - sqrt(d) >= 0)
return (-b - sqrt(d)) / (2 * a);
if (-b + sqrt(d) >= 0)
return (-b + sqrt(d)) / (2 * a);
return -1;
}
P Go(P s, P t, P dog, double v, double x, double T) {
t *= T;
dog -= s;
P res = (t - dog) / abs(t - dog);
return (res * v * x) + dog + s;
}
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (!n && !m)
break;
P dog[11];
double v[11];
for (int i = 0; i < n; i++) {
double x, y;
cin >> x >> y >> v[i];
dog[i] = P(x, y);
}
int ans[11] = {};
while (m--) {
P s, t;
double x, y;
cin >> x >> y;
s = P(x, y);
cin >> x >> y;
t = P(x, y);
double mnt = INF, time[11] = {};
for (int i = 0; i < n; i++) {
time[i] = calc_time(s, t, dog[i], v[i]);
if (time[i] >= 0)
mnt = min(mnt, time[i]);
}
for (int i = 0; i < n; i++) {
if (time[i] > 0)
dog[i] = Go(s, t, dog[i], v[i], mnt, time[i]);
ans[i] += time[i] == mnt;
}
}
for (int i = 0; i < n; i++) {
if (i)
cout << " ";
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 110], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22]]
| 1
| 586
|
#include <stdio.h>
int main(void) {
int i, n, sum, x;
scanf("%d", &n);
while (n != 0) {
for (i = 0; i < n / 4; i++) {
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, n, sum, x;
scanf("%d", &n);
while (n != 0) {
sum = 0;
for (i = 0; i < n / 4; i++) {
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
scanf("%d", &n);
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 90
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n, m;
int tl[22222];
int main(void) {
while (cin >> n >> m && n + m) {
for (int i = 1; i <= n + m; i++)
cin >> tl[i];
sort(tl, tl + n + m + 1);
int res = 0;
for (int i = 1; i <= n + m + 1; i++)
res = max(res, tl[i] - tl[i - 1]);
cout << res << endl;
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n, m;
int tl[22222];
int main(void) {
while (cin >> n >> m && n + m) {
for (int i = 1; i <= n + m; i++)
cin >> tl[i];
sort(tl, tl + n + m + 1);
int res = 0;
for (int i = 1; i <= n + m; i++)
res = max(res, tl[i] - tl[i - 1]);
cout << res << endl;
}
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 126
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int t[20000];
int n, m;
while (1) {
for (int i = 0; i < 2000; i++)
t[i] = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n + m; i++)
cin >> t[i];
sort(t, t + (n + m));
int max = 0;
for (int i = 1; i < n + m; i++) {
if ((t[i] - t[i - 1]) > max && (t[i] - t[i - 1]) != 0)
max = t[i] - t[i - 1];
}
if (max == 0)
cout << t[0] << endl;
else
cout << max << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int t[20000];
int n, m;
while (1) {
for (int i = 0; i < 2000; i++)
t[i] = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n + m; i++)
cin >> t[i];
sort(t, t + (n + m));
int max = 0;
for (int i = 1; i < n + m; i++) {
if ((t[i] - t[i - 1]) > max && (t[i] - t[i - 1]) != 0)
max = t[i] - t[i - 1];
}
if (t[0] > max)
cout << t[0] << endl;
else
cout << max << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
| 1
| 202
|
get = lambda:list(map(int, input().split()))
while True:
n,m = get()
if n==m==0: break
t = [0]
if n!=0: t += get()
if m!=0: t += get()
t.sort()
print(max(t[i+1]-t[i] for i in range(n+m-1)) if n+m>1 else t[0])
|
get = lambda:list(map(int, input().split()))
while True:
n,m = get()
if n==m==0: break
t = [0]
if n!=0: t += get()
if m!=0: t += get()
t.sort()
print(max(t[i+1]-t[i] for i in range(n+m)) if n+m>1 else t[1])
|
[["-", 0, 659, 12, 652, 3, 4, 0, 657, 17, 33], ["-", 0, 659, 12, 652, 3, 4, 0, 657, 12, 612], ["-", 0, 652, 3, 4, 0, 41, 0, 206, 206, 612], ["+", 0, 652, 3, 4, 0, 41, 0, 206, 206, 612]]
| 5
| 106
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
var nh = arr.shift();
if (nh == "0 0")
break;
nh = nh.split(" ").map(Number);
var n = nh[0];
var h = nh[1];
var obj = {};
for (var i = 0; i < h; i++) {
var ary = arr.shift().split(" ");
var x = ary[0];
var a = ary[1] - 0;
var b = ary[2] - 0;
if (x == "xy") {
for (var j = 0; j < n; j++)
obj[a + "," + b + "," + j] = true;
} else if (x == "xz") {
for (var j = 0; j < n; j++)
obj[a + "," + j + "," + b] = true;
} else if (x == "yz") {
for (var j = 0; j < n; j++)
obj[j + "," + a + "," + b] = true;
}
}
console.log(n * n * n - Object.keys(obj).length);
}
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
var nh = arr.shift();
if (nh == "0 0")
break;
nh = nh.split(" ").map(Number);
var n = nh[0];
var h = nh[1];
var obj = {};
for (var i = 0; i < h; i++) {
var ary = arr.shift().split(" ");
var x = ary[0];
var a = ary[1] - 0;
var b = ary[2] - 0;
if (x == "xy") {
for (var j = 1; j <= n; j++)
obj[a + "," + b + "," + j] = true;
} else if (x == "xz") {
for (var j = 1; j <= n; j++)
obj[a + "," + j + "," + b] = true;
} else if (x == "yz") {
for (var j = 1; j <= n; j++)
obj[j + "," + a + "," + b] = true;
}
}
console.log(n * n * n - Object.keys(obj).length);
}
|
[["-", 64, 556, 0, 7, 10, 198, 0, 200, 51, 555], ["+", 64, 556, 0, 7, 10, 198, 0, 200, 51, 555], ["-", 64, 556, 0, 7, 15, 1, 0, 16, 17, 18], ["+", 64, 556, 0, 7, 15, 1, 0, 16, 17, 19]]
| 2
| 311
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;
typedef pair<int, pair<int, int>> cube_t;
int main(void) {
int n, h;
string s;
int a, b;
while (1) {
cin >> n >> h;
if (n == 0 && h == 0)
break;
set<cube_t> cube;
for (int i = 0; i < h; i++) {
cin >> s >> a >> b;
for (int j = 0; j < n; j++)
if (s == "xy") {
cube.insert(make_pair(a, make_pair(b, j)));
} else if (s == "xz") {
cube.insert(make_pair(a, make_pair(j, b)));
} else {
cube.insert(make_pair(j, make_pair(a, b)));
}
}
cout << n * n * n - cube.size() << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;
typedef pair<int, pair<int, int>> cube_t;
int main(void) {
int n, h;
string s;
int a, b;
while (1) {
cin >> n >> h;
if (n == 0 && h == 0)
break;
set<cube_t> cube;
for (int i = 0; i < h; i++) {
cin >> s >> a >> b;
for (int j = 1; j <= n; j++)
if (s == "xy") {
cube.insert(make_pair(a, make_pair(b, j)));
} else if (s == "xz") {
cube.insert(make_pair(a, make_pair(j, b)));
} else {
cube.insert(make_pair(j, make_pair(a, b)));
}
}
cout << n * n * n - cube.size() << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 238
|
#include <iostream>
#include <set>
#include <string>
#include <tuple>
using namespace std;
int n, q, a, b;
string s;
int main() {
while (cin >> n >> q, n | q) {
set<tuple<int, int, int>> d;
for (int i = 0; i < q; i++) {
cin >> s >> a >> b;
for (int j = 1; j < n; j++) {
if (s == "xy")
d.insert(make_tuple(a, b, j));
if (s == "xz")
d.insert(make_tuple(a, j, b));
if (s == "yz")
d.insert(make_tuple(j, a, b));
}
}
cout << n * n * n - s.size() << endl;
}
}
|
#include <iostream>
#include <set>
#include <string>
#include <tuple>
using namespace std;
int n, q, a, b;
string s;
int main() {
while (cin >> n >> q, n | q) {
set<tuple<int, int, int>> d;
for (int i = 0; i < q; i++) {
cin >> s >> a >> b;
for (int j = 1; j <= n; j++) {
if (s == "xy")
d.insert(make_tuple(a, b, j));
if (s == "xz")
d.insert(make_tuple(a, j, b));
if (s == "yz")
d.insert(make_tuple(j, a, b));
}
}
cout << n * n * n - d.size() << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 31, 16, 12, 16, 12, 2, 63, 118, 28, 22], ["+", 31, 16, 12, 16, 12, 2, 63, 118, 28, 22]]
| 1
| 179
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
class Point {
public:
int x, y, z;
Point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const Point &p) const {
if (z != p.z)
return z < p.z;
if (y != p.y)
return y < p.y;
if (x != p.x)
return x < p.x;
return false;
}
};
int main() {
while (1) {
int n, h;
cin >> n >> h;
if (n == 0 && h == 0)
break;
set<Point> hole;
for (int i = 0; i < h; i++) {
string str;
int a, b;
cin >> str >> a >> b;
if (str == "xy") {
for (int j = 0; j < n; j++) {
hole.insert(Point(a, b, j));
}
} else if (str == "xz") {
for (int j = 0; j < n; j++) {
hole.insert(Point(a, j, b));
}
} else if (str == "yz") {
for (int j = 0; j < n; j++) {
hole.insert(Point(j, a, b));
}
}
}
cout << n * n * n - hole.size() << endl;
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
class Point {
public:
int x, y, z;
Point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const Point &p) const {
if (z != p.z)
return z < p.z;
if (y != p.y)
return y < p.y;
if (x != p.x)
return x < p.x;
return false;
}
};
int main() {
while (1) {
int n, h;
cin >> n >> h;
if (n == 0 && h == 0)
break;
set<Point> hole;
for (int i = 0; i < h; i++) {
string str;
int a, b;
cin >> str >> a >> b;
if (str == "xy") {
for (int j = 1; j <= n; j++) {
hole.insert(Point(a, b, j));
}
} else if (str == "xz") {
for (int j = 1; j <= n; j++) {
hole.insert(Point(a, j, b));
}
} else if (str == "yz") {
for (int j = 1; j <= n; j++) {
hole.insert(Point(j, a, b));
}
}
}
cout << n * n * n - hole.size() << endl;
}
return 0;
}
|
[["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 332
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
void solve() {
int n, h;
while (cin >> n >> h, n || h) {
set<int> Set;
string str;
int a, b;
for (int i = 0; i < h; ++i) {
cin >> str >> a >> b;
--a;
--b;
int temp;
if (str == "xy") {
temp = a + n * b;
for (int i = 0; i < n; ++i) {
Set.insert(temp);
temp += n * n;
}
} else if (str == "xz") {
temp = a + n * n * b;
for (int i = 0; i < n; ++i) {
Set.insert(temp);
temp += 1;
}
} else if (str == "yz") {
temp = a + n * n * b;
for (int i = 0; i < n; ++i) {
Set.insert(temp);
temp += 4;
}
}
}
cout << n * n * n - Set.size() << endl;
}
}
int main() {
solve();
return (0);
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
void solve() {
int n, h;
while (cin >> n >> h, n || h) {
set<int> Set;
string str;
int a, b;
for (int i = 0; i < h; ++i) {
cin >> str >> a >> b;
--a;
--b;
int temp;
if (str == "xy") {
temp = a + n * b;
for (int i = 0; i < n; ++i) {
Set.insert(temp);
temp += n * n;
}
} else if (str == "xz") {
temp = a + n * n * b;
for (int i = 0; i < n; ++i) {
Set.insert(temp);
temp += n;
}
} else if (str == "yz") {
temp = a * n + n * n * b;
for (int i = 0; i < n; ++i) {
Set.insert(temp);
temp += 1;
}
}
}
cout << n * n * n - Set.size() << endl;
}
}
int main() {
solve();
return (0);
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 256
|
require 'set'
loop do
n,h = gets.split.map(&:to_i)
break if (n|h)==0
set = Set.new
h.times do
s,a,b = gets.split
n.times do |i|
case s
when "xy"
set << a+","+b+","+i.to_s
when "yz"
set << i.to_s+","+a+","+b
when "xz"
set << a+","+i.to_s+","+b
end
end
end
puts n**3-set.size
end
|
require 'set'
loop do
n,h = gets.split.map(&:to_i)
break if (n|h)==0
set = Set.new
h.times do
s,a,b = gets.split
1.upto(n) do |i|
case s
when "xy"
set << a+","+b+","+i.to_s
when "yz"
set << i.to_s+","+a+","+b
when "xz"
set << a+","+i.to_s+","+b
end
end
end
puts n**3-set.size
end
|
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 486, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 486, 612], ["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 196, 737, 8, 736, 0, 652, 3, 4, 0, 24], ["+", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22], ["+", 196, 737, 8, 736, 0, 652, 3, 4, 0, 25]]
| 4
| 130
|
// Aizu Vol-10 1031: Simple GUI Application
// 2017.8.19 bal4u@uu
#include <ctype.h>
#include <stdio.h>
#include <string.h>
char *gets(char *);
char buf[100], *p;
int getInt(void) {
int n = 0;
while (isspace(*p) || *p == ',')
p++;
while (isdigit(*p))
n = 10 * n + (*p++ - '0');
return n;
}
char tag[1005];
int x, y;
char ans[100];
int no;
char *parse(char *tp, int *done, int *k) {
int x1, y1, x2, y2;
int ok = 0;
int sum = 0, s;
char name[100], *np;
*k = 0;
// while (isspace(*tp)) tp++;
if (!*tp)
return tp;
tp++; // '<'
np = name;
while (*tp != '>')
*np++ = *tp++;
*np = 0;
tp++; // '>'
p = tp, x1 = getInt(), y1 = getInt(), x2 = getInt(), y2 = getInt(), tp = p;
if (x1 <= x && x <= x2 && y1 <= x && x <= y2)
ok = 1;
while (*tp) {
// while (isspace(*tp)) tp++;
if (*(tp + 1) == '/')
break;
tp = parse(tp, done, &s), sum++; // sum += s+1;
}
while (*tp++ != '>')
;
if (!*done && ok)
strcpy(ans, name), no = sum, *done = 1;
*k = sum;
return tp;
}
int main() {
int n, i, d, k;
while (1) {
gets(p = buf);
if (!(n = getInt()))
break;
gets(tag);
for (i = 0; i < n; i++) {
gets(p = buf), x = getInt(), y = getInt();
no = -1, d = 0;
parse(tag, &d, &k);
if (no < 0)
puts("OUT OF MAIN PANEL 1");
else
printf("%s %d\n", ans, no);
}
}
return 0;
}
|
// Aizu Vol-10 1031: Simple GUI Application
// 2017.8.19 bal4u@uu
#include <ctype.h>
#include <stdio.h>
#include <string.h>
char *gets(char *);
char buf[100], *p;
int getInt(void) {
int n = 0;
while (isspace(*p) || *p == ',')
p++;
while (isdigit(*p))
n = 10 * n + (*p++ - '0');
return n;
}
char tag[1005];
int x, y;
char ans[100];
int no;
char *parse(char *tp, int *done, int *k) {
int x1, y1, x2, y2;
int ok = 0;
int sum = 0, s;
char name[100], *np;
*k = 0;
// while (isspace(*tp)) tp++;
if (!*tp)
return tp;
tp++; // '<'
np = name;
while (*tp != '>')
*np++ = *tp++;
*np = 0;
tp++; // '>'
p = tp, x1 = getInt(), y1 = getInt(), x2 = getInt(), y2 = getInt(), tp = p;
if (x1 <= x && x <= x2 && y1 <= y && y <= y2)
ok = 1;
while (*tp) {
// while (isspace(*tp)) tp++;
if (*(tp + 1) == '/')
break;
tp = parse(tp, done, &s), sum++; // sum += s+1;
}
while (*tp++ != '>')
;
if (!*done && ok)
strcpy(ans, name), no = sum, *done = 1;
*k = sum;
return tp;
}
int main() {
int n, i, d, k;
while (1) {
gets(p = buf);
if (!(n = getInt()))
break;
gets(tag);
for (i = 0; i < n; i++) {
gets(p = buf), x = getInt(), y = getInt();
no = -1, d = 0;
parse(tag, &d, &k);
if (no < 0)
puts("OUT OF MAIN PANEL 1");
else
printf("%s %d\n", ans, no);
}
}
return 0;
}
|
[["-", 15, 23, 0, 16, 31, 16, 12, 16, 12, 22], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22]]
| 0
| 463
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define DUMP(list) \
cout << "{ "; \
for (auto nth : list) { \
cout << nth << " "; \
} \
cout << "}" << endl
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) \
;
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
struct Panel {
string name;
int x1, y1, x2, y2;
vector<Panel> v;
};
int fp;
Panel parse(string s) {
Panel p;
int ep = 0;
while (s[fp] != '>') {
ep++;
fp++;
}
p.name = s.substr(fp - ep, ep);
ep = 0;
fp++;
while (s[fp] != ',') {
ep++;
fp++;
}
p.x1 = toInt(s.substr(fp - ep, ep));
ep = 0;
fp++;
while (s[fp] != ',') {
ep++;
fp++;
}
p.y1 = toInt(s.substr(fp - ep, ep));
ep = 0;
fp++;
while (s[fp] != ',') {
ep++;
fp++;
}
p.x2 = toInt(s.substr(fp - ep, ep));
ep = 0;
fp++;
while (s[fp] != '<') {
ep++;
fp++;
}
p.y2 = toInt(s.substr(fp - ep, fp - 1));
fp++;
while (1) {
if (s[fp] == '/') {
fp += p.name.size() + 3;
break;
} else
p.v.push_back(parse(s));
}
return p;
}
Panel search(int x, int y, Panel r_p, Panel p) {
if (p.x1 <= x && p.x2 >= x && p.y1 <= y && p.y2 >= y) {
if (p.v.size() == 0)
return p;
rep(i, p.v.size()) {
Panel tmp = search(x, y, p, p.v[i]);
if (tmp.name != p.name)
return tmp;
}
}
return r_p;
}
int main() {
while (1) {
int n;
string str;
cin >> n;
if (n == 0)
break;
cin >> str;
fp = 1;
Panel p = parse(str);
rep(i, n) {
int x, y;
cin >> x >> y;
Panel root;
root.name = "-1";
Panel ans = search(x, y, root, p);
if (ans.name == "-1")
cout << "OUT OF MAIN PANEL 1" << endl;
else
cout << ans.name << " " << ans.v.size() << endl;
}
}
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define DUMP(list) \
cout << "{ "; \
for (auto nth : list) { \
cout << nth << " "; \
} \
cout << "}" << endl
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) \
;
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
struct Panel {
string name;
int x1, y1, x2, y2;
vector<Panel> v;
};
int fp;
Panel parse(string s) {
Panel p;
int ep = 0;
while (s[fp] != '>') {
ep++;
fp++;
}
p.name = s.substr(fp - ep, ep);
ep = 0;
fp++;
while (s[fp] != ',') {
ep++;
fp++;
}
p.x1 = toInt(s.substr(fp - ep, ep));
ep = 0;
fp++;
while (s[fp] != ',') {
ep++;
fp++;
}
p.y1 = toInt(s.substr(fp - ep, ep));
ep = 0;
fp++;
while (s[fp] != ',') {
ep++;
fp++;
}
p.x2 = toInt(s.substr(fp - ep, ep));
ep = 0;
fp++;
while (s[fp] != '<') {
ep++;
fp++;
}
p.y2 = toInt(s.substr(fp - ep, fp - 1));
fp++;
while (1) {
if (s[fp] == '/') {
fp += p.name.size() + 3;
break;
} else
p.v.push_back(parse(s));
}
return p;
}
Panel search(int x, int y, Panel r_p, Panel p) {
if (p.x1 <= x && p.x2 >= x && p.y1 <= y && p.y2 >= y) {
if (p.v.size() == 0)
return p;
rep(i, p.v.size()) {
Panel tmp = search(x, y, p, p.v[i]);
if (tmp.name != p.name)
return tmp;
}
return p;
}
return r_p;
}
int main() {
while (1) {
int n;
string str;
cin >> n;
if (n == 0)
break;
cin >> str;
fp = 1;
Panel p = parse(str);
rep(i, n) {
int x, y;
cin >> x >> y;
Panel root;
root.name = "-1";
Panel ans = search(x, y, root, p);
if (ans.name == "-1")
cout << "OUT OF MAIN PANEL 1" << endl;
else
cout << ans.name << " " << ans.v.size() << endl;
}
}
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 35]]
| 1
| 642
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool between(int a, int b, int c) { return a <= b && b <= c; }
vector<string> split(const string &s, char c) {
vector<string> v;
size_t prev = 0, cur;
while ((cur = s.find(c, prev)) != string::npos) {
v.push_back(s.substr(prev, cur - prev));
prev = cur + 1;
}
v.push_back(s.substr(prev));
return v;
}
int to_int(const string &s) { return atoi(s.c_str()); }
struct Node {
string name;
int left, top, right, bottom;
vector<Node> children;
};
struct Result {
Node node;
int p;
};
Result parse(const string &s, int p) {
Result r;
++p;
size_t t = s.find('>', p);
r.node.name = s.substr(p, t - p);
p = t + 1;
t = s.find('<', p);
vector<string> loc = split(s.substr(p, t - p), ',');
r.node.left = to_int(loc[0]);
r.node.top = to_int(loc[1]);
r.node.right = to_int(loc[2]);
r.node.bottom = to_int(loc[3]);
p = t;
while (s[p + 1] != '/') {
Result q = parse(s, p);
r.node.children.push_back(q.node);
p = q.p;
}
r.p = p + 3 + r.node.name.size();
return r;
}
pair<string, int> solve(const Node &n, int x, int y) {
pair<string, int> r(n.name, n.children.size());
for (int i = 0; i < n.children.size(); ++i) {
const Node &c = n.children[i];
if (between(c.left, x, c.right) && between(c.top, x, c.bottom)) {
r = solve(c, x, y);
break;
}
}
return r;
}
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
string s;
cin >> s;
s = "<OUT OF MAIN PANEL>0,0,10000,10000" + s + "</OUT OF MAIN PANEL>";
Node root = parse(s, 0).node;
while (n--) {
int x, y;
cin >> x >> y;
pair<string, int> answer = solve(root, x, y);
cout << answer.first << " " << answer.second << endl;
}
}
return 0;
}
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool between(int a, int b, int c) { return a <= b && b <= c; }
vector<string> split(const string &s, char c) {
vector<string> v;
size_t prev = 0, cur;
while ((cur = s.find(c, prev)) != string::npos) {
v.push_back(s.substr(prev, cur - prev));
prev = cur + 1;
}
v.push_back(s.substr(prev));
return v;
}
int to_int(const string &s) { return atoi(s.c_str()); }
struct Node {
string name;
int left, top, right, bottom;
vector<Node> children;
};
struct Result {
Node node;
int p;
};
Result parse(const string &s, int p) {
Result r;
++p;
size_t t = s.find('>', p);
r.node.name = s.substr(p, t - p);
p = t + 1;
t = s.find('<', p);
vector<string> loc = split(s.substr(p, t - p), ',');
r.node.left = to_int(loc[0]);
r.node.top = to_int(loc[1]);
r.node.right = to_int(loc[2]);
r.node.bottom = to_int(loc[3]);
p = t;
while (s[p + 1] != '/') {
Result q = parse(s, p);
r.node.children.push_back(q.node);
p = q.p;
}
r.p = p + 3 + r.node.name.size();
return r;
}
pair<string, int> solve(const Node &n, int x, int y) {
pair<string, int> r(n.name, n.children.size());
for (int i = 0; i < n.children.size(); ++i) {
const Node &c = n.children[i];
if (between(c.left, x, c.right) && between(c.top, y, c.bottom)) {
r = solve(c, x, y);
break;
}
}
return r;
}
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
string s;
cin >> s;
s = "<OUT OF MAIN PANEL>0,0,10000,10000" + s + "</OUT OF MAIN PANEL>";
Node root = parse(s, 0).node;
while (n--) {
int x, y;
cin >> x >> y;
pair<string, int> answer = solve(root, x, y);
cout << answer.first << " " << answer.second << endl;
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 2, 3, 4, 0, 22], ["+", 15, 339, 51, 16, 12, 2, 3, 4, 0, 22]]
| 1
| 630
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c) \
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;
int main() {
int n, u;
while (scanf("%d%d", &n, &u), n | u) {
int c[32], r[32];
for (int i = 0; i < n; ++i) {
int k;
scanf("%d%d", c + i, &k);
r[i] = 0;
while (k--) {
int t;
scanf("%d", &t);
r[i] |= 1 << t;
}
}
if (u == 0) {
puts("0");
continue;
}
int res = n;
for (int bits = 1; bits < n; ++bits) {
int i = (1 << bits) - 1;
do {
bool ok = true;
int s = 0;
for (int j = 0; j < n; ++j) {
if (i >> j & 1) {
if ((i & r[i]) != r[i]) {
ok = false;
break;
} else
s += c[i];
}
}
if (ok) {
// int s = 0;
// for (int j = 0; j < n; ++j)
// if (i >> j & 1)
// s += c[j];
if (s >= u) {
res = bits;
goto end;
}
}
// combination
int leastBit = i & -i;
int mostBits = i + leastBit;
int leastSequentialBits = i & ~mostBits;
i = mostBits | ((leastSequentialBits / leastBit) >> 1);
} while (i < 1 << n);
}
end:
printf("%d\n", res);
}
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c) \
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;
int main() {
int n, u;
while (scanf("%d%d", &n, &u), n | u) {
int c[32], r[32];
for (int i = 0; i < n; ++i) {
int k;
scanf("%d%d", c + i, &k);
r[i] = 0;
while (k--) {
int t;
scanf("%d", &t);
r[i] |= 1 << t;
}
}
if (u == 0) {
puts("0");
continue;
}
int res = n;
for (int bits = 1; bits < n; ++bits) {
int i = (1 << bits) - 1;
do {
bool ok = true;
int s = 0;
for (int j = 0; j < n; ++j) {
if (i >> j & 1) {
if ((i & r[j]) != r[j]) {
ok = false;
break;
} else
s += c[j];
}
}
if (ok) {
// int s = 0;
// for (int j = 0; j < n; ++j)
// if (i >> j & 1)
// s += c[j];
if (s >= u) {
res = bits;
goto end;
}
}
// combination
int leastBit = i & -i;
int mostBits = i + leastBit;
int leastSequentialBits = i & ~mostBits;
i = mostBits | ((leastSequentialBits / leastBit) >> 1);
} while (i < 1 << n);
}
end:
printf("%d\n", res);
}
}
|
[["-", 31, 23, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 23, 0, 16, 12, 69, 341, 342, 0, 22], ["-", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
| 1
| 509
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, U, tmp, sum;
int c[30], k[30], r[30], low[30];
int ans;
bool f;
int main() {
while (scanf("%d%d", &n, &U), (n || U)) {
for (int i = 0; i < n; i++) {
scanf("%d%d", &c[i], &k[i]);
low[i] = c[i];
r[i] = 0;
for (int j = 0; j < k[i]; j++) {
scanf("%d", &tmp);
r[i] |= 1 << tmp;
}
}
sort(low, low + n, greater<int>());
int l;
sum = 0;
for (l = 0; l < n; l++) {
sum += c[l];
if (U <= sum)
break;
}
f = false;
;
for (ans = l + 1; ans < n; ans++) {
int comb = (1 << ans) - 1;
while (comb < (1 << n)) {
sum = 0;
f = true;
for (int i = 0; i < n; i++) {
if ((comb >> i) & 1) {
if ((comb & r[i]) != r[i]) {
f = false;
break;
}
sum += c[i];
}
}
if (f && U <= sum) {
break;
}
f = false;
int x = comb & -comb, y = comb + x;
comb = (((comb & ~y) / x) >> 1) | y;
}
if (f)
break;
}
printf("%d\n", ans);
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, U, tmp, sum;
int c[30], k[30], r[30], low[30];
int ans;
bool f;
int main() {
while (scanf("%d%d", &n, &U), (n || U)) {
for (int i = 0; i < n; i++) {
scanf("%d%d", &c[i], &k[i]);
low[i] = c[i];
r[i] = 0;
for (int j = 0; j < k[i]; j++) {
scanf("%d", &tmp);
r[i] |= 1 << tmp;
}
}
sort(low, low + n, greater<int>());
int l;
sum = 0;
for (l = 0; l < n; l++) {
sum += low[l];
if (U <= sum)
break;
}
f = false;
;
for (ans = l + 1; ans < n; ans++) {
int comb = (1 << ans) - 1;
while (comb < (1 << n)) {
sum = 0;
f = true;
for (int i = 0; i < n; i++) {
if ((comb >> i) & 1) {
if ((comb & r[i]) != r[i]) {
f = false;
break;
}
sum += c[i];
}
}
if (f && U <= sum) {
break;
}
f = false;
int x = comb & -comb, y = comb + x;
comb = (((comb & ~y) / x) >> 1) | y;
}
if (f)
break;
}
printf("%d\n", ans);
}
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22]]
| 1
| 397
|
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
/* input */
String[] line = br.readLine().split(" ");
int w = Integer.parseInt(line[0]), q = Integer.parseInt(line[1]);
if (w == 0 && q == 0) {
br.close();
break;
}
// initialize each with available width
int[] f = new int[w];
for (int i = 0; i < w; i++) {
f[i] = w - i;
}
for (int i = 0; i < q; i++) {
line = br.readLine().split(" ");
char c = line[0].charAt(0);
switch (c) {
case 's': {
int id = Integer.parseInt(line[1]);
int width = Integer.parseInt(line[2]);
// look for available place
boolean ok = false;
for (int j = 0; j < w; j++) {
if (f[j] >= width) {
for (int k = 0; k < width; k++) {
f[j + k] = -id;
}
ok = true;
System.out.println(j);
break;
}
}
if (!ok)
System.out.println("impossible");
break;
}
case 'w': {
int id = Integer.parseInt(line[1]);
int p = w - 1;
while (f[p] != -id)
p--;
if (p == w - 1)
f[p] = 1;
while (p >= 0 && (f[p] == -id || f[p] > 0)) {
f[p] = (f[p + 1] < 0) ? 1 : f[p + 1] + 1;
p--;
}
}
}
}
System.out.println("END");
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
/* input */
String[] line = br.readLine().split(" ");
int w = Integer.parseInt(line[0]), q = Integer.parseInt(line[1]);
if (w == 0 && q == 0) {
br.close();
break;
}
// initialize each with available width
int[] f = new int[w];
for (int i = 0; i < w; i++) {
f[i] = w - i;
}
for (int i = 0; i < q; i++) {
line = br.readLine().split(" ");
char c = line[0].charAt(0);
switch (c) {
case 's': {
int id = Integer.parseInt(line[1]);
int width = Integer.parseInt(line[2]);
// look for available place
boolean ok = false;
for (int j = 0; j < w; j++) {
if (f[j] >= width) {
for (int k = 0; k < width; k++) {
f[j + k] = -id;
}
ok = true;
System.out.println(j);
break;
}
}
if (!ok)
System.out.println("impossible");
break;
}
case 'w': {
int id = Integer.parseInt(line[1]);
int p = w - 1;
while (f[p] != -id)
p--;
if (p == w - 1) {
f[p] = 1;
p--;
}
while (p >= 0 && (f[p] == -id || f[p] > 0)) {
f[p] = (f[p + 1] < 0) ? 1 : f[p + 1] + 1;
p--;
}
}
}
}
System.out.println("END");
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
[["+", 0, 520, 0, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 27, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 27, 0, 68], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 520, 0, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 460
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;
int ww[110], ID[110];
int W, Q;
int check(int w, int id) {
for (int i = 0; i < W; i++) {
int j;
for (j = 0; j < w; j++) {
if (i + j < W && ww[i + j] != -1)
break;
}
if (j == w) {
for (j = 0; j < w; j++) {
ww[i + j] = id;
}
return i;
}
}
return -1;
}
void remove(int id) {
int w = ID[id];
int i;
for (i = 0; i < W; i++) {
if (ww[i] == id)
break;
}
for (int j = 0; j < w; j++) {
ww[i + j] = -1;
}
}
int main(void) {
while (1) {
cin >> W >> Q;
if (W == 0 && Q == 0)
break;
for (int i = 0; i < W; i++)
ww[i] = -1;
for (int i = 0; i < Q; i++) {
char c;
cin >> c;
if (c == 's') {
int id, w;
cin >> id >> w;
ID[id] = w;
int ans = check(w, id);
if (ans == -1)
cout << "impossible" << endl;
else
cout << ans << endl;
} else {
int id;
cin >> id;
remove(id);
}
}
cout << "END" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;
int ww[110], ID[110];
int W, Q;
int check(int w, int id) {
for (int i = 0; i < W; i++) {
int j;
for (j = 0; j < w; j++) {
if (i + j >= W || ww[i + j] != -1)
break;
}
if (j == w) {
for (j = 0; j < w; j++) {
ww[i + j] = id;
}
return i;
}
}
return -1;
}
void remove(int id) {
int w = ID[id];
int i;
for (i = 0; i < W; i++) {
if (ww[i] == id)
break;
}
for (int j = 0; j < w; j++) {
ww[i + j] = -1;
}
}
int main(void) {
while (1) {
cin >> W >> Q;
if (W == 0 && Q == 0)
break;
for (int i = 0; i < W; i++)
ww[i] = -1;
for (int i = 0; i < Q; i++) {
char c;
cin >> c;
if (c == 's') {
int id, w;
cin >> id >> w;
ID[id] = w;
int ans = check(w, id);
if (ans == -1)
cout << "impossible" << endl;
else
cout << ans << endl;
} else {
int id;
cin >> id;
remove(id);
}
}
cout << "END" << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 390
|
#include <algorithm>
#include <stdio.h>
using namespace std;
int used[110];
char in[3];
int main() {
int a, b;
while (scanf("%d%d", &a, &b), a) {
for (int i = 0; i < a; i++)
used[i] = -1;
while (b--) {
scanf("%s", in);
if (in[0] == 's') {
int c, d;
scanf("%d%d", &c, &d);
int now = 0;
bool yet = true;
for (int i = 0; i < a; i++) {
if (~used[i])
now = 0;
else
now++;
if (now == d) {
yet = false;
printf("%d\n", i - d + 1);
for (int j = 0; j < d; j++)
used[i - j] = c;
}
}
if (yet)
printf("impossible\n");
} else {
int c;
scanf("%d", &c);
for (int i = 0; i < a; i++)
if (used[i] == c)
used[i] = -1;
}
}
printf("END\n");
}
}
|
#include <algorithm>
#include <stdio.h>
using namespace std;
int used[110];
char in[3];
int main() {
int a, b;
while (scanf("%d%d", &a, &b), a) {
for (int i = 0; i < a; i++)
used[i] = -1;
while (b--) {
scanf("%s", in);
if (in[0] == 's') {
int c, d;
scanf("%d%d", &c, &d);
int now = 0;
bool yet = true;
for (int i = 0; i < a; i++) {
if (~used[i])
now = 0;
else
now++;
if (now == d) {
yet = false;
printf("%d\n", i - d + 1);
for (int j = 0; j < d; j++)
used[i - j] = c;
break;
}
}
if (yet)
printf("impossible\n");
} else {
int c;
scanf("%d", &c);
for (int i = 0; i < a; i++)
if (used[i] == c)
used[i] = -1;
}
}
printf("END\n");
}
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 275
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int w, q, wall[100], id, cat;
string op;
cin >> w >> q;
while (w) {
for (int i = 0; i < w; i++) {
wall[i] = -1;
}
for (int i = 0; i < q; i++) {
cin >> op >> id;
if (op == "s") {
cin >> cat;
int possible = 0, idx;
for (idx = 0; idx < w - cat; idx++) {
if (wall[idx] == -1) {
possible = 1;
for (int j = 0; j < cat; j++) {
if (wall[idx + j] != -1) {
possible = 0;
break;
}
}
if (possible) {
cout << idx << endl;
for (int i = 0; i < cat; i++) {
wall[idx + i] = id;
}
break;
}
}
}
if (!possible) {
cout << "impossible" << endl;
}
} else if (op == "w") {
for (int i = 0; i < w; i++) {
if (wall[i] == id) {
for (int j = i; wall[j] == id; j++) {
wall[j] = -1;
}
break;
}
}
}
}
cout << "END" << endl;
cin >> w >> q;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int w, q, wall[100], id, cat;
string op;
cin >> w >> q;
while (w) {
for (int i = 0; i < w; i++) {
wall[i] = -1;
}
for (int i = 0; i < q; i++) {
cin >> op >> id;
if (op == "s") {
cin >> cat;
int possible = 0, idx;
for (idx = 0; idx <= w - cat; idx++) {
if (wall[idx] == -1) {
possible = 1;
for (int j = 0; j < cat; j++) {
if (wall[idx + j] != -1) {
possible = 0;
break;
}
}
if (possible) {
cout << idx << endl;
for (int i = 0; i < cat; i++) {
wall[idx + i] = id;
}
break;
}
}
}
if (!possible) {
cout << "impossible" << endl;
}
} else if (op == "w") {
for (int i = 0; i < w; i++) {
if (wall[i] == id) {
for (int j = i; wall[j] == id; j++) {
wall[j] = -1;
}
break;
}
}
}
}
cout << "END" << endl;
cin >> w >> q;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 313
|
loop do
name,type = gets.split
break if type =='X'
if name.include?('_')
words = name.split('_')
else
name.gsub!(/(.)([A-Z])/,'\1 \2')
words = name.split
end
case type
when 'U'
puts words.map(&:capitalize).join
when 'L'
words.map!(&:capitalize)
words[0].downcase!
puts words.join
when 'D'
words.map!(&:downcase)
puts words.join('_')
end
end
|
loop do
name,type = gets.split
break if type =='X'
if name.include?('_')
words = name.split('_')
else
name.gsub!(/([A-Z])/,' \1')
words = name.split
end
case type
when 'U'
puts words.map(&:capitalize).join
when 'L'
words.map!(&:capitalize)
words[0].downcase!
puts words.join
when 'D'
words.map!(&:downcase)
puts words.join('_')
end
end
|
[["-", 75, 95, 0, 652, 3, 4, 0, 575, 0, 6], ["+", 75, 95, 0, 652, 3, 4, 0, 575, 0, 6], ["-", 75, 95, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 75, 95, 0, 652, 3, 4, 0, 557, 0, 6]]
| 4
| 113
|
def main
loop do
str,pattern = gets.chomp.split(' ')
break if pattern.eql?('X')
answers << case pattern
when 'U'
puts conversion_to_upper_camel_case(str)
when 'L'
puts conversion_to_lower_camel_case(str)
when 'D'
puts conversion_to_snake_case(str)
end
end
end
def split_word str
words = []
word = ''
str.length.times do |i|
if str[i].match(/_/)
words << word
word = ''
elsif str[i].match(/[A-Z]/)
words << word unless i == 0
word = str[i]
else
word << str[i]
end
end
words << word
words
end
def conversion_to_upper_camel_case str
words = split_word(str)
words.map{|word|word.capitalize}.join
end
def conversion_to_lower_camel_case str
conversion_word = ''
words = split_word(str)
words.each_with_index do |word, i|
if i == 0
conversion_word << word.downcase
else
conversion_word << word.capitalize
end
end
conversion_word
end
def conversion_to_snake_case str
words = split_word(str)
words.each.map{|word|word.downcase}.join('_')
end
main
|
def main
loop do
str,pattern = gets.chomp.split(' ')
break if pattern.eql?('X')
case pattern
when 'U'
puts conversion_to_upper_camel_case(str)
when 'L'
puts conversion_to_lower_camel_case(str)
when 'D'
puts conversion_to_snake_case(str)
end
end
end
def split_word str
words = []
word = ''
str.length.times do |i|
if str[i].match(/_/)
words << word
word = ''
elsif str[i].match(/[A-Z]/)
words << word unless i == 0
word = str[i]
else
word << str[i]
end
end
words << word
words
end
def conversion_to_upper_camel_case str
words = split_word(str)
words.map{|word|word.capitalize}.join
end
def conversion_to_lower_camel_case str
conversion_word = ''
words = split_word(str)
words.each_with_index do |word, i|
if i == 0
conversion_word << word.downcase
else
conversion_word << word.capitalize
end
end
conversion_word
end
def conversion_to_snake_case str
words = split_word(str)
words.each.map{|word|word.downcase}.join('_')
end
main
|
[["-", 0, 652, 196, 737, 8, 736, 0, 738, 31, 22], ["-", 0, 652, 196, 737, 8, 736, 0, 738, 17, 151]]
| 4
| 235
|
while True:
name,type = list(map(str, input().split()))
ans = ""
if (type == 'X'):
break
names = []
if (name.find("_") != -1):
names = name.split("_")
elif (name[0].islower() == True):
tmp = name[0]
for i in range(1, len(name)):
if (name[i].isupper() == True):
names.append(tmp)
tmp = name[i]
else:
tmp += name[i]
if (len(tmp) > 1):
names.append(tmp)
else:
tmp = name[0]
for i in range(1, len(name)):
if (name[i].isupper() == True):
names.append(tmp)
tmp = name[i]
else:
tmp += name[i]
if (len(tmp) > 1):
names.append(tmp)
if (type == "U"):
for x in names:
ans += x[0].upper()
ans += x[1:].lower()
elif (type == "L"):
cnt = 0
for x in names:
if (cnt == 0):
ans += x.lower()
else:
ans += x[0].upper()
ans += x[1:].lower()
cnt += 1
else:
ans = "_".join(names)
ans = ans.lower()
print(ans)
|
while True:
name,type = list(map(str, input().split()))
ans = ""
if (type == 'X'):
break
names = []
if (name.find("_") != -1):
names = name.split("_")
elif (name[0].islower() == True):
tmp = name[0]
for i in range(1, len(name)):
if (name[i].isupper() == True):
names.append(tmp)
tmp = name[i]
else:
tmp += name[i]
if (len(tmp) > 0):
names.append(tmp)
else:
tmp = name[0]
for i in range(1, len(name)):
if (name[i].isupper() == True):
names.append(tmp)
tmp = name[i]
else:
tmp += name[i]
if (len(tmp) > 0):
names.append(tmp)
# print names
if (type == "U"):
for x in names:
ans += x[0].upper()
ans += x[1:].lower()
elif (type == "L"):
cnt = 0
for x in names:
if (cnt == 0):
ans += x.lower()
else:
ans += x[0].upper()
ans += x[1:].lower()
cnt += 1
else:
ans = "_".join(names)
ans = ans.lower()
print(ans)
|
[["-", 64, 196, 0, 57, 15, 23, 0, 666, 0, 612], ["+", 64, 196, 0, 57, 15, 23, 0, 666, 0, 612], ["-", 8, 196, 0, 57, 15, 23, 0, 666, 0, 612], ["+", 8, 196, 0, 57, 15, 23, 0, 666, 0, 612]]
| 5
| 334
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.