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
|
|---|---|---|---|---|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
int p, q, a, n;
int solve(int d, int numer, int denom, int m) {
int c = 0;
for (int i = d; i * denom <= a; i++) {
int n1 = p * i * denom;
int n2 = numer * i + denom;
if (n1 < n2 * q) {
continue;
}
if (n1 == n2 * q) {
c++;
continue;
}
if (n == 1) {
continue;
}
c += solve(i, n2, denom * i, m - 1);
}
return c;
}
int main() {
while (cin >> p >> q >> a >> n, p | q | a | n) {
cout << solve(1, 0, 1, n) << endl;
}
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
int p, q, a, n;
int solve(int d, int numer, int denom, int m) {
int c = 0;
for (int i = d; i * denom <= a; i++) {
int n1 = p * i * denom;
int n2 = numer * i + denom;
if (n1 < n2 * q) {
continue;
}
if (n1 == n2 * q) {
c++;
continue;
}
if (m == 1) {
continue;
}
c += solve(i, n2, denom * i, m - 1);
}
return c;
}
int main() {
while (cin >> p >> q >> a >> n, p | q | a | n) {
cout << solve(1, 0, 1, n) << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
| 1
| 246
|
#include <iostream>
using namespace std;
int solve(int p, int q, int r, int a, int n) {
int k = 0;
for (int i = max(r, p / q); i <= a; i++) {
if (i * p == q)
k++;
else if (n != 1)
k += solve(i * p - q, i * q, i, a / i, n - 1);
}
return k;
}
int main() {
int p, q, a, n;
while (cin >> p >> q >> a >> n, p)
cout << solve(p, q, 1, a, n) << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int solve(int p, int q, int r, int a, int n) {
int k = 0;
for (int i = max(r, q / p); i <= a; i++) {
if (i * p == q)
k++;
else if (n != 1)
k += solve(i * p - q, i * q, i, a / i, n - 1);
}
return k;
}
int main() {
int p, q, a, n;
while (cin >> p >> q >> a >> n, p)
cout << solve(p, q, 1, a, n) << endl;
return 0;
}
|
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22], ["-", 49, 50, 51, 2, 3, 4, 0, 16, 17, 85], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 85], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 149
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
const int INF = (1 << 29) + 1;
int n, m;
template <typename T> struct Serializer {
map<T, int> enc;
vector<T> dec;
int operator()(const T &t) {
auto it = enc.find(t);
if (it != enc.end())
return it->second;
dec.push_back(t);
return enc[t] = dec.size() - 1;
}
size_t size() { return dec.size(); }
};
int g[201][201], g2[201][201];
int main() {
while (cin >> n, n) {
Serializer<string> se;
REP(i, 200) REP(j, 200) g[i][j] = g2[i][j] = i == j ? 0 : INF;
REP(i, n) {
string s;
cin >> s;
int p = s.find('-');
int u = se(s.substr(0, p));
int v = se(s.substr(p + 1));
g[u][v] = g2[u][v] = g2[v][u] = 1;
}
n = se.size();
REP(i, n) REP(j, i) {
int f = 0;
REP(k, n) {
if (g[i][k] == 1 && g[k][j] == 1 || g[j][k] == 1 && g[k][i] == 1) {
f = 0;
break;
}
if (g[i][k] == 1 && g[j][k] == 1 || g[k][i] == 1 && g[j][i] == 1)
f = 1;
}
if (f) {
if (g[i][j] == INF)
g[i][j] = 501;
if (g[j][i] == INF)
g[j][i] = 501;
}
}
REP(k, n) REP(i, n) REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
REP(k, n) REP(i, n) REP(j, n) g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
cout << n << endl;
cin >> m;
REP(i, m) {
string s;
cin >> s;
int p = s.find('-');
int u = se(s.substr(0, p));
int v = se(s.substr(p + 1));
if ((g2[u][v] & 1) && g[u][v] < INF)
puts("YES");
else
puts("NO");
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
const int INF = (1 << 29) + 1;
int n, m;
template <typename T> struct Serializer {
map<T, int> enc;
vector<T> dec;
int operator()(const T &t) {
auto it = enc.find(t);
if (it != enc.end())
return it->second;
dec.push_back(t);
return enc[t] = dec.size() - 1;
}
size_t size() { return dec.size(); }
};
int g[201][201], g2[201][201];
int main() {
while (cin >> n, n) {
Serializer<string> se;
REP(i, 200) REP(j, 200) g[i][j] = g2[i][j] = i == j ? 0 : INF;
REP(i, n) {
string s;
cin >> s;
int p = s.find('-');
int u = se(s.substr(0, p));
int v = se(s.substr(p + 1));
g[u][v] = g2[u][v] = g2[v][u] = 1;
}
n = se.size();
REP(i, n) REP(j, i) {
int f = 0;
REP(k, n) {
if (g[i][k] == 1 && g[k][j] == 1 || g[j][k] == 1 && g[k][i] == 1) {
f = 0;
break;
}
if (g[i][k] == 1 && g[j][k] == 1 || g[k][i] == 1 && g[k][j] == 1)
f = 1;
}
if (f) {
if (g[i][j] == INF)
g[i][j] = 501;
if (g[j][i] == INF)
g[j][i] = 501;
}
}
REP(k, n) REP(i, n) REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
REP(k, n) REP(i, n) REP(j, n) g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
cout << n << endl;
cin >> m;
REP(i, m) {
string s;
cin >> s;
int p = s.find('-');
int u = se(s.substr(0, p));
int v = se(s.substr(p + 1));
if ((g2[u][v] & 1) && g[u][v] < INF)
puts("YES");
else
puts("NO");
}
}
return 0;
}
|
[["-", 12, 16, 31, 69, 28, 69, 341, 342, 0, 22], ["+", 12, 16, 31, 69, 28, 69, 341, 342, 0, 22], ["-", 12, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 12, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
| 1
| 693
|
#include <stdio.h>
int calc(int type, int y, int init, double rate, int c) {
int i, b = 0;
if (type == 0) {
for (i = 0; i < y; i++) {
b += init * rate;
init -= c;
}
return init + b;
} else {
for (i = 0; i < y; i++) {
b = init * rate;
init = init + b - c;
}
return init;
}
}
int main(void) {
int m, ans, init, y, n, t, c, tmp;
double r;
scanf("%d", &m);
while (m--) {
ans = 0;
scanf("%d %d %d", &init, &y, &n);
while (n--) {
scanf("%d %lf %d", &t, &r, &c);
tmp = calc(t, y, init, r, c);
if (ans < tmp)
ans = tmp;
}
printf("%d\n", tmp);
}
return 0;
}
|
#include <stdio.h>
int calc(int type, int y, int init, double rate, int c) {
int i, b = 0;
if (type == 0) {
for (i = 0; i < y; i++) {
b += init * rate;
init -= c;
}
return init + b;
} else {
for (i = 0; i < y; i++) {
b = init * rate;
init = init + b - c;
}
return init;
}
}
int main(void) {
int m, ans, init, y, n, t, c, tmp;
double r;
scanf("%d", &m);
while (m--) {
ans = 0;
scanf("%d %d %d", &init, &y, &n);
while (n--) {
scanf("%d %lf %d", &t, &r, &c);
tmp = calc(t, y, init, r, c);
if (ans < tmp)
ans = tmp;
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 0
| 227
|
#include <stdio.h>
int n;
int main() {
scanf("%d", &n);
while (n--) {
int money, year, way;
double rate;
scanf("%d", &money);
scanf("%d", &year);
scanf("%d", &way);
int c, d = 0, ans;
while (way--) {
int flag, factorage;
int y = year;
scanf("%d", &flag);
scanf("%lf", &rate);
scanf("%d", &factorage);
if (flag == 0) {
int a = money, b, q = 0;
while (y--) {
b = (int)a * rate;
a -= factorage;
q += b;
}
a += q;
c = a;
}
if (flag == 1) {
int a = money, b;
while (y--) {
b = (int)a * rate;
a = a + b - factorage;
}
c = a;
}
if (c > d) {
d = c;
}
}
printf("%d", d);
}
return 0;
}
|
#include <stdio.h>
int n;
int main() {
scanf("%d", &n);
while (n--) {
int money, year, way;
double rate;
scanf("%d", &money);
scanf("%d", &year);
scanf("%d", &way);
int c, d = 0, ans;
while (way--) {
int flag, factorage;
int y = year;
scanf("%d", &flag);
scanf("%lf", &rate);
scanf("%d", &factorage);
if (flag == 0) {
int a = money, b, q = 0;
while (y--) {
b = (int)a * rate;
a -= factorage;
q += b;
}
a += q;
c = a;
}
if (flag == 1) {
int a = money, b;
while (y--) {
b = (int)a * rate;
a = a + b - factorage;
}
c = a;
}
if (c > d) {
d = c;
}
}
printf("%d\n", d);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 242
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i, j;
int fmoney, lmoney;
int r;
int year;
int b, cost;
double per;
int m, n;
int *a;
scanf("%d", &m);
while (1) {
if (m == 0)
break;
scanf("%d", &fmoney);
scanf("%d", &year);
scanf("%d", &n);
a = (int *)malloc(sizeof(int) * n);
for (i = 0; i < n; i++) {
scanf("%d %lf %d", &b, &per, &cost);
lmoney = fmoney;
r = 0;
if (b == 0) {
for (j = 0; j < year; j++) {
r += (int)(lmoney * per);
lmoney -= cost;
}
a[i] = r + lmoney;
}
if (b == 1) {
for (j = 0; j < year; j++) {
r += (int)(lmoney * per);
lmoney -= cost;
}
a[i] = lmoney;
}
}
for (i = 1; i < n; i++) {
if (a[0] < a[i]) {
a[0] = a[i];
}
}
printf("%d\n", a[0]);
m--;
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i, j;
int fmoney, lmoney;
int r;
int year;
int b, cost;
double per;
int m, n;
int *a;
scanf("%d", &m);
while (1) {
if (m == 0)
break;
scanf("%d", &fmoney);
scanf("%d", &year);
scanf("%d", &n);
a = (int *)malloc(sizeof(int) * n);
for (i = 0; i < n; i++) {
scanf("%d %lf %d", &b, &per, &cost);
lmoney = fmoney;
r = 0;
if (b == 0) {
for (j = 0; j < year; j++) {
r += (int)(lmoney * per);
lmoney -= cost;
}
a[i] = r + lmoney;
}
if (b == 1) {
for (j = 0; j < year; j++) {
r = (int)(lmoney * per);
lmoney = lmoney + r - cost;
}
a[i] = lmoney;
}
}
for (i = 1; i < n; i++) {
if (a[0] < a[i]) {
a[0] = a[i];
}
}
printf("%d\n", a[0]);
m--;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33]]
| 0
| 303
|
#include <stdio.h>
#include <stdlib.h>
int estimate_Tanri(int operatingfund, double rate_of_interest, int period,
int fee);
int estimate_Fukuri(int operatingfund, double rate_of_interest, int period,
int fee);
int main(void) {
int m;
scanf("%d", &m);
int i;
for (i = 0; i < m; i++) {
int operatingfund;
scanf("%f", &operatingfund);
int period;
scanf("%d", &period);
int n; //?????¨??????????¨??????°
scanf("%d", &n);
int result = 0;
int j;
for (j = 0; j < n; j++) {
int TorF;
double rate_of_interest;
int fee;
scanf("%d %f %d", &TorF, &rate_of_interest, &fee);
int tmp;
if (TorF == 0) {
tmp = estimate_Tanri(operatingfund, rate_of_interest, period, fee);
} else {
tmp = estimate_Fukuri(operatingfund, rate_of_interest, period, fee);
}
if (result <= tmp) {
result = tmp;
}
}
printf("%d\n", result);
}
return 0;
}
int estimate_Tanri(int operatingfund, double rate_of_interest, int period,
int fee) {
int i;
int total_interest = 0;
for (i = 0; i < period; i++) {
total_interest += (int)(operatingfund * rate_of_interest);
operatingfund -= fee;
}
return total_interest + operatingfund;
}
int estimate_Fukuri(int operatingfund, double rate_of_interest, int period,
int fee) {
int i;
for (i = 0; i < period; i++) {
operatingfund =
operatingfund + (int)(operatingfund * rate_of_interest) - fee;
}
return operatingfund;
}
|
#include <stdio.h>
#include <stdlib.h>
int estimate_Tanri(int operatingfund, double rate_of_interest, int period,
int fee);
int estimate_Fukuri(int operatingfund, double rate_of_interest, int period,
int fee);
int main(void) {
int m;
scanf("%d", &m);
int i;
for (i = 0; i < m; i++) {
int operatingfund;
scanf("%d", &operatingfund);
int period;
scanf("%d", &period);
int n; //?????¨??????????¨??????°
scanf("%d", &n);
int result = 0;
int j;
for (j = 0; j < n; j++) {
int TorF;
double rate_of_interest;
int fee;
scanf("%d %lf %d", &TorF, &rate_of_interest, &fee);
int tmp;
if (TorF == 0) {
tmp = estimate_Tanri(operatingfund, rate_of_interest, period, fee);
} else {
tmp = estimate_Fukuri(operatingfund, rate_of_interest, period, fee);
}
if (result <= tmp) {
result = tmp;
}
}
printf("%d\n", result);
}
return 0;
}
int estimate_Tanri(int operatingfund, double rate_of_interest, int period,
int fee) {
int i;
int total_interest = 0;
for (i = 0; i < period; i++) {
total_interest += (int)(operatingfund * rate_of_interest);
operatingfund -= fee;
}
return total_interest + operatingfund;
}
int estimate_Fukuri(int operatingfund, double rate_of_interest, int period,
int fee) {
int i;
for (i = 0; i < period; i++) {
operatingfund =
operatingfund + (int)(operatingfund * rate_of_interest) - fee;
}
return operatingfund;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 340
|
#include <stdio.h>
int main(void) {
int m, plan, set, money, year, part, total, top, answer[100] = {0};
float r;
scanf("%d", &m);
int i, j, k;
for (i = 0; i < m; i++) {
scanf(" %d %d %d", &money, &year, &part);
for (j = 0; j < part; j++) {
scanf(" %d %f %d", &plan, &r, &set);
total = money;
if (plan == 0) //??????
{
top = 0;
for (k = 0; k < year; k++) {
top += total * r;
total -= set;
}
total += top;
if (answer[i] <= total) {
answer[i] = total; //?????§???
}
} else if (plan == 1) //??????
{
for (k = 0; k < year; k++) {
total += total * r - set;
}
if (answer[i] <= total) {
answer[i] = total; //?????§???
}
} else {
break;
}
}
}
for (i = 0; i < m; i++)
printf("%d\n", answer[i]);
return 0;
}
|
#include <stdio.h>
int main(void) {
int m, plan, set, money, year, part, total, top, answer[500] = {0};
double r;
scanf("%d", &m);
int i, j, k;
for (i = 0; i < m; i++) {
scanf(" %d %d %d", &money, &year, &part);
for (j = 0; j < part; j++) {
/* scanf(" %d %f %d", &plan, &r, &set);*/
scanf(" %d %lf %d", &plan, &r, &set);
total = money;
if (plan == 0) //??????
{
top = 0;
for (k = 0; k < year; k++) {
top += total * r;
total -= set;
}
total += top;
if (answer[i] <= total) {
answer[i] = total; //?????§???
}
} else if (plan == 1) //??????
{
for (k = 0; k < year; k++) {
total += total * r - set;
}
if (answer[i] <= total) {
answer[i] = total; //?????§???
}
} else {
break;
}
}
}
for (i = 0; i < m; i++)
printf("%d\n", answer[i]);
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 268
|
#include <stdio.h>
int main() {
int m, n;
int value, year;
int type, cost;
int result;
int i, j, k;
int a, b;
int max;
float ratio;
scanf("%d", &m);
for (k = 0; k < m; k++) {
scanf("%d", &value);
scanf("%d", &year);
scanf("%d", &n);
max = 0;
for (i = 0; i < n; i++) {
scanf("%d %f %d", &type, &ratio, &cost);
a = value;
b = 0;
if (type == 0) {
for (j = 0; j < year; j++) {
b = b + a * ratio;
a = a - cost;
}
result = b + a;
} else {
for (j = 0; j < year; j++) {
b = a * ratio;
a = a + b - cost;
}
result = a;
}
if (result > max) {
max = result;
}
}
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
int main() {
int m, n;
int value, year;
int type, cost;
int result;
int i, j, k;
int a, b;
int max;
double ratio;
scanf("%d", &m);
for (k = 0; k < m; k++) {
scanf("%d", &value);
scanf("%d", &year);
scanf("%d", &n);
max = 0;
for (i = 0; i < n; i++) {
scanf("%d %lf %d", &type, &ratio, &cost);
a = value;
b = 0;
if (type == 0) {
for (j = 0; j < year; j++) {
b = b + a * ratio;
a = a - cost;
}
result = b + a;
} else {
for (j = 0; j < year; j++) {
b = a * ratio;
a = a + b - cost;
}
result = a;
}
if (result > max) {
max = result;
}
}
printf("%d\n", max);
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 246
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#define pi 3.14159
using namespace std;
int main() {
int m;
cin >> m;
for (int i = 0; i < m; i++) {
double a, b, money, in, sum, max;
int y, c, d, n;
cin >> a >> y >> n;
double e[100];
for (int j = 0; j < n; j++) {
money = a;
sum = 0;
cin >> c >> in >> d;
for (int k = 0; k < y; k++) {
if (c == 0) {
b = money * in;
money -= d;
sum += floor(b);
} else {
b = floor(money * in);
money = money + b - d;
}
}
if (c == 0)
e[j] = money + sum;
else
e[j] = money;
}
max = e[0];
for (int j = 1; j < m; j++) {
if (max < e[j])
max = e[j];
}
cout << (int)max << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#define pi 3.14159
using namespace std;
int main() {
int m;
cin >> m;
for (int i = 0; i < m; i++) {
double a, b, money, in, sum, max;
int y, c, d, n;
cin >> a >> y >> n;
double e[100];
for (int j = 0; j < n; j++) {
money = a;
sum = 0;
cin >> c >> in >> d;
for (int k = 0; k < y; k++) {
if (c == 0) {
b = money * in;
money -= d;
sum += floor(b);
} else {
b = floor(money * in);
money = money + b - d;
}
}
if (c == 0)
e[j] = money + sum;
else
e[j] = money;
}
max = e[0];
for (int j = 1; j < n; j++) {
if (max < e[j])
max = e[j];
}
cout << (int)max << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
| 1
| 249
|
#include <algorithm>
#include <assert.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define ALL(s) begin(s), end(s)
#define ITE(c) typeof((c).begin())
#define VIEW(dat) \
for (auto v : dat) { \
cout << v << endl; \
}
#define clr(a) memset((a), 0, sizeof(a))
#define nclr(a) memset((a), -1, sizeof(a))
#define pb push_back
#define INRANGE(x, s, e) ((s) <= (x) && (x) < (e))
#define MP(a, b) make_pair((a), (b))
using namespace std;
int main() {
int m, S, s, y, n, t, c;
float p;
vector<int> dat;
// ifstream cin("in.txt");
cin >> m;
rep(I, m) {
cin >> S >> y >> n;
dat.clear();
dat.reserve(n);
rep(i, n) {
cin >> t >> p >> c;
s = S;
if (t) {
rep(j, y) {
float B = s * p;
s += B - c;
}
dat.push_back(s);
} else {
int r = 0;
rep(j, y) {
int B = s * p;
s -= c;
r += B;
}
dat.push_back(s + r);
}
}
sort(ALL(dat));
cout << dat[n - 1] << endl;
}
return 0;
}
|
#include <algorithm>
#include <assert.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define ALL(s) begin(s), end(s)
#define ITE(c) typeof((c).begin())
#define VIEW(dat) \
for (auto v : dat) { \
cout << v << endl; \
}
#define clr(a) memset((a), 0, sizeof(a))
#define nclr(a) memset((a), -1, sizeof(a))
#define pb push_back
#define INRANGE(x, s, e) ((s) <= (x) && (x) < (e))
#define MP(a, b) make_pair((a), (b))
using namespace std;
int main() {
int m, S, s, y, n, t, c;
double p;
vector<int> dat;
// ifstream cin("in.txt");
cin >> m;
rep(I, m) {
cin >> S >> y >> n;
dat.clear();
dat.reserve(n);
rep(i, n) {
cin >> t >> p >> c;
s = S;
if (t) {
rep(j, y) {
double B = s * p;
s += B - c;
}
dat.push_back(s);
} else {
int r = 0;
rep(j, y) {
double B = s * p;
s -= c;
r += B;
}
dat.push_back(s + r);
}
}
sort(ALL(dat));
cout << dat[n - 1] << endl;
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 64, 9, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 64, 9, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 9, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 9, 0, 14, 8, 9, 0, 43, 39, 40]]
| 1
| 313
|
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int n, m;
int first, year, ver, fee;
double rate;
int result = 0;
vector<int> results;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> first;
cin >> year;
cin >> n;
int temp;
for (int j = 0; j < n; j++) {
cin >> ver >> rate >> fee;
temp = 0;
if (ver) {
temp = first;
for (int k = 0; k < year; k++) {
temp += int(temp * rate) - fee;
}
} else {
int first_temp = first;
for (int k = 0; k < year; k++) {
temp += int(first_temp * rate);
first_temp -= fee;
if (k == year - 1) {
temp += first_temp;
}
}
}
if (result < temp) {
result = temp;
}
}
results.push_back(result);
}
for (auto it = results.begin(); it != results.end(); it++) {
cout << *it << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int n, m;
int first, year, ver, fee;
double rate;
int result = 0;
vector<int> results;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> first;
cin >> year;
cin >> n;
int temp;
result = 0;
for (int j = 0; j < n; j++) {
cin >> ver >> rate >> fee;
temp = 0;
if (ver) {
temp = first;
for (int k = 0; k < year; k++) {
temp += int(temp * rate) - fee;
}
} else {
int first_temp = first;
for (int k = 0; k < year; k++) {
temp += int(first_temp * rate);
first_temp -= fee;
if (k == year - 1) {
temp += first_temp;
}
}
}
if (result < temp) {
result = temp;
}
}
results.push_back(result);
}
for (auto it = results.begin(); it != results.end(); it++) {
cout << *it << endl;
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 255
|
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void) {
int m;
std::cin >> m; //データセットの数
while (m--) {
double amt; //初期運用資金量
int year; //運用年数
int n; //運用方法の種類数
int ans = 0;
std::cin >> amt >> year >> n;
while (n--) {
int f; //単利0、複利1
double roi; //利率
double chg; //手数料
double itr = 0; //利子
double fin = 0; //最終資金
int amt_tmp = amt; //資金初期化
std::cin >> f >> roi >> chg;
if (f == 0) { //単利
rep(i, year) {
itr += amt_tmp * roi;
amt_tmp -= chg;
}
fin = amt_tmp + itr;
} else { //複利
rep(i, year) {
amt_tmp += amt_tmp * roi;
amt_tmp -= chg;
}
fin = amt_tmp;
}
if (ans < fin) {
ans = fin;
}
}
std::cout << ans << std::endl;
}
return 0;
}
|
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void) {
int m;
std::cin >> m; //データセットの数
while (m--) {
double amt; //初期運用資金量
int year; //運用年数
int n; //運用方法の種類数
int ans = 0;
std::cin >> amt >> year >> n;
while (n--) {
int f; //単利0、複利1
double roi; //利率
double chg; //手数料
int itr = 0; //利子
double fin = 0; //最終資金
int amt_tmp = amt; //資金初期化
std::cin >> f >> roi >> chg;
if (f == 0) { //単利
rep(i, year) {
itr += amt_tmp * roi;
amt_tmp -= chg;
}
fin = amt_tmp + itr;
} else { //複利
rep(i, year) {
amt_tmp += amt_tmp * roi;
amt_tmp -= chg;
}
fin = amt_tmp;
}
if (ans < fin) {
ans = fin;
}
}
std::cout << ans << std::endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40]]
| 1
| 192
|
#include <stdio.h>
int main() {
int m, fand, year, n, ri, nen, com;
int max, tmp, in;
scanf("%d", &m);
while (m--) {
scanf("%d%d%d", &fand, &year, &n);
max = 0;
while (n--) {
tmp = fand;
in = 0;
scanf("%d%lf%d", &ri, &nen, &com);
for (int i = 0; i < year; i++) {
if (ri == 1)
tmp += (int)((double)tmp * nen);
else
in += (int)((double)tmp * nen);
tmp -= com;
}
tmp += in;
if (max < tmp)
max = tmp;
}
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
int main() {
int m, fand, year, n, ri, com;
int max, tmp, in;
double nen;
scanf("%d", &m);
while (m--) {
scanf("%d%d%d", &fand, &year, &n);
max = 0;
while (n--) {
tmp = fand;
in = 0;
scanf("%d%lf%d", &ri, &nen, &com);
for (int i = 0; i < year; i++) {
if (ri == 1)
tmp += (int)((double)tmp * nen);
else
in += (int)((double)tmp * nen);
tmp -= com;
}
tmp += in;
// printf("tmp%d:%d\n",n,tmp);
// printf("in%d:%d\n",n,in);
if (max < tmp)
max = tmp;
}
printf("%d\n", max);
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22]]
| 1
| 180
|
#include <iostream>
using namespace std;
int main() {
int m;
int n;
int money, nowmoney, year;
int type, tesuu;
int sumrisi;
int ans;
double risi;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> money;
cin >> year;
cin >> n;
ans = -1;
for (int j = 0; j < n; j++) {
cin >> type >> risi >> tesuu;
nowmoney = money;
sumrisi = 0;
for (int k = 0; k < year; k++) {
if (type == 0) {
nowmoney += (nowmoney * risi) - tesuu;
} else {
sumrisi += (nowmoney * risi);
nowmoney -= tesuu;
}
}
if (type == 1)
nowmoney += sumrisi;
if (ans < nowmoney)
ans = nowmoney;
}
cout << ans << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m;
int n;
int money, nowmoney, year;
int type, tesuu;
int sumrisi;
int ans;
double risi;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> money;
cin >> year;
cin >> n;
ans = -1;
for (int j = 0; j < n; j++) {
cin >> type >> risi >> tesuu;
nowmoney = money;
sumrisi = 0;
for (int k = 0; k < year; k++) {
if (type == 1) {
nowmoney += (nowmoney * risi) - tesuu;
} else {
sumrisi += (nowmoney * risi);
nowmoney -= tesuu;
}
}
if (type == 0)
nowmoney += sumrisi;
if (ans < nowmoney)
ans = nowmoney;
}
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 185
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int k, m, g, y, n;
cin >> k;
for (int i = 0; i < k; i++) {
int mg = 0;
cin >> g >> y >> n;
for (int j = 0; j < n; j++) {
int ng = g;
int tf, q;
double p;
cin >> tf >> p >> q;
if (tf) { //単利
for (int ii = 0; ii < y; ii++)
ng += (int)(ng * p) - q;
} else { //複利
int r = 0;
for (int ii = 0; ii < y; ii++) {
r += (int)(ng * p);
ng -= q;
}
ng += r;
}
mg = max(mg, ng);
}
cout << "output" << mg << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int k, m, g, y, n;
cin >> k;
for (int i = 0; i < k; i++) {
int mg = 0;
cin >> g >> y >> n;
for (int j = 0; j < n; j++) {
int ng = g;
int tf, q;
double p;
cin >> tf >> p >> q;
if (tf) { //単利
for (int ii = 0; ii < y; ii++)
ng += (int)(ng * p) - q;
} else { //複利
int r = 0;
for (int ii = 0; ii < y; ii++) {
r += (int)(ng * p);
ng -= q;
}
ng += r;
}
mg = max(mg, ng);
}
cout << mg << endl;
}
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
| 1
| 195
|
import static java.lang.Integer.parseInt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Polygonal Line Search
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
String[] words;
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = parseInt(line);
if (n == 0)
break;
int[][] arc0 = null;
int[][] rev0 = null;
for (int i = 0; i <= n; i++) {
int m = parseInt(br.readLine());
int[][] arc = new int[m][2];
for (int j = 0; j < m; j++) {
line = br.readLine();
arc[j][0] = parseInt(line.substring(0, line.indexOf(' ')));
arc[j][1] = parseInt(line.substring(line.indexOf(' ') + 1));
}
arc = normalize(arc);
if (i == 0) {
arc0 = arc;
rev0 = normalize(reverse(arc0));
} else {
if (arc.length != arc0.length) {
continue;
} else {
for (int j = 0; j < 4; j++) {
if (congruent(arc0, arc) || congruent(rev0, arc)) {
System.out.println(i);
break;
} else {
arc = rotate(arc);
}
}
}
}
}
System.out.println("*****");
}
} // end main
static int[][] reverse(int[][] a) {
int[][] ret = new int[a.length][a[0].length];
for (int i = 0, j = a.length - 1; i < a.length; i++, j--) {
ret[i][0] = a[j][0];
ret[i][1] = a[j][1];
}
return ret;
}
static int[][] normalize(int[][] a) {
int[][] ret = new int[a.length][a[0].length];
int dx, dy;
dx = -a[0][0];
dy = -a[0][1];
for (int i = 0; i < a.length; i++) {
ret[i][0] = a[i][0] + dx;
ret[i][1] = a[i][1] + dy;
}
return ret;
}
static int[][] rotate(int[][] a) {
int[][] ret = new int[a.length][a[0].length];
for (int i = 0; i < a.length; i++) {
ret[i][0] = -a[i][1];
ret[i][1] = a[i][0];
}
return ret;
}
static boolean congruent(int[][] a1, int[][] a2) {
boolean ret = true;
for (int i = 0; i < a1.length; i++) {
ret &= (a1[i][0] == a2[i][0] && a1[i][1] == a2[i][1]);
if (!ret)
break;
}
return ret;
}
}
|
import static java.lang.Integer.parseInt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Polygonal Line Search
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
String[] words;
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = parseInt(line);
if (n == 0)
break;
int[][] arc0 = null;
int[][] rev0 = null;
for (int i = 0; i <= n; i++) {
int m = parseInt(br.readLine());
int[][] arc = new int[m][2];
for (int j = 0; j < m; j++) {
line = br.readLine();
arc[j][0] = parseInt(line.substring(0, line.indexOf(' ')));
arc[j][1] = parseInt(line.substring(line.indexOf(' ') + 1));
}
arc = normalize(arc);
if (i == 0) {
arc0 = arc;
rev0 = normalize(reverse(arc0));
} else {
if (arc.length != arc0.length) {
continue;
} else {
for (int j = 0; j < 4; j++) {
if (congruent(arc0, arc) || congruent(rev0, arc)) {
System.out.println(i);
break;
} else {
arc = rotate(arc);
}
}
}
}
}
System.out.println("+++++");
}
} // end main
static int[][] reverse(int[][] a) {
int[][] ret = new int[a.length][a[0].length];
for (int i = 0, j = a.length - 1; i < a.length; i++, j--) {
ret[i][0] = a[j][0];
ret[i][1] = a[j][1];
}
return ret;
}
static int[][] normalize(int[][] a) {
int[][] ret = new int[a.length][a[0].length];
int dx, dy;
dx = -a[0][0];
dy = -a[0][1];
for (int i = 0; i < a.length; i++) {
ret[i][0] = a[i][0] + dx;
ret[i][1] = a[i][1] + dy;
}
return ret;
}
static int[][] rotate(int[][] a) {
int[][] ret = new int[a.length][a[0].length];
for (int i = 0; i < a.length; i++) {
ret[i][0] = -a[i][1];
ret[i][1] = a[i][0];
}
return ret;
}
static boolean congruent(int[][] a1, int[][] a2) {
boolean ret = true;
for (int i = 0; i < a1.length; i++) {
ret &= (a1[i][0] == a2[i][0] && a1[i][1] == a2[i][1]);
if (!ret)
break;
}
return ret;
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 776
|
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
public class Main {
static PrintWriter out;
static InputReader ir;
static void solve() {
for (;;) {
int n = ir.nextInt();
if (n == 0)
return;
int[][][] p = new int[n + 1][][];
for (int i = 0; i <= n; i++) {
int m = ir.nextInt();
p[i] = new int[m][];
for (int j = 0; j < m; j++)
p[i][j] = ir.nextIntArray(2);
}
for (int i = 1; i <= n; i++) {
if (check(i, p))
out.println(i);
}
out.println("+++++");
}
}
public static boolean check(int cur, int[][][] p) {
if (p[0].length != p[cur].length)
return false;
int n = p[0].length;
boolean f =
Math.abs(p[0][1][0] - p[0][0][0] + p[0][1][1] - p[0][0][1]) ==
Math.abs(p[cur][1][0] - p[cur][0][0] + p[cur][1][1] - p[cur][0][1]);
for (int i = 0; i < n - 2; i++) {
f &= dir(p[0][i + 1][0] - p[0][i][0], p[0][i + 1][1] - p[0][i][1],
p[0][i + 2][0] - p[0][i + 1][0],
p[0][i + 2][1] - p[0][i + 1][1]) ==
dir(p[cur][i + 1][0] - p[cur][i][0], p[cur][i + 1][1] - p[cur][i][1],
p[cur][i + 2][0] - p[cur][i + 1][0],
p[cur][i + 2][1] - p[cur][i + 1][1]);
f &= Math.abs(p[0][i + 2][0] - p[0][i + 1][0] + p[0][i + 2][1] -
p[0][i + 1][1]) ==
Math.abs(p[cur][i + 2][0] - p[cur][i + 1][0] + p[cur][i + 2][1] -
p[cur][i + 1][1]);
}
if (f)
return true;
for (int i = 0; i < n / 2; i++) {
int[] t = p[cur][i];
p[cur][i] = p[cur][n - 1 - i];
p[cur][n - 1 - i] = t;
}
f = Math.abs(p[0][1][0] - p[0][0][0] + p[0][1][1] - p[0][0][1]) ==
Math.abs(p[cur][1][0] - p[cur][0][0] + p[cur][1][1] - p[cur][0][1]);
for (int i = 0; i < n - 2; i++) {
f &= dir(p[0][i + 1][0] - p[0][i][0], p[0][i + 1][1] - p[0][i][1],
p[0][i + 2][0] - p[0][i + 1][0],
p[0][i + 2][1] - p[0][i + 1][1]) ==
dir(p[cur][i + 1][0] - p[cur][i][0],
p[cur][i + 1][1] - p[cur][i + 1][1],
p[cur][i + 2][0] - p[cur][i + 1][0],
p[cur][i + 2][1] - p[cur][i + 1][1]);
f &= Math.abs(p[0][i + 2][0] - p[0][i + 1][0] + p[0][i + 2][1] -
p[0][i + 1][1]) ==
Math.abs(p[cur][i + 2][0] - p[cur][i + 1][0] + p[cur][i + 2][1] -
p[cur][i + 1][1]);
}
return f;
}
public static int dir(int a, int b, int c, int d) {
int sa = Integer.signum(a);
int sb = Integer.signum(b);
int sc = Integer.signum(c);
int sd = Integer.signum(d);
return sa * sd == -1 || sb * sc == 1 ? 1 : -1;
}
public static void main(String[] args) throws Exception {
ir = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() { return Double.parseDouble(next()); }
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
}
|
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
public class Main {
static PrintWriter out;
static InputReader ir;
static void solve() {
for (;;) {
int n = ir.nextInt();
if (n == 0)
return;
int[][][] p = new int[n + 1][][];
for (int i = 0; i <= n; i++) {
int m = ir.nextInt();
p[i] = new int[m][];
for (int j = 0; j < m; j++)
p[i][j] = ir.nextIntArray(2);
}
for (int i = 1; i <= n; i++) {
if (check(i, p))
out.println(i);
}
out.println("+++++");
}
}
public static boolean check(int cur, int[][][] p) {
if (p[0].length != p[cur].length)
return false;
int n = p[0].length;
boolean f =
Math.abs(p[0][1][0] - p[0][0][0] + p[0][1][1] - p[0][0][1]) ==
Math.abs(p[cur][1][0] - p[cur][0][0] + p[cur][1][1] - p[cur][0][1]);
for (int i = 0; i < n - 2; i++) {
f &= dir(p[0][i + 1][0] - p[0][i][0], p[0][i + 1][1] - p[0][i][1],
p[0][i + 2][0] - p[0][i + 1][0],
p[0][i + 2][1] - p[0][i + 1][1]) ==
dir(p[cur][i + 1][0] - p[cur][i][0], p[cur][i + 1][1] - p[cur][i][1],
p[cur][i + 2][0] - p[cur][i + 1][0],
p[cur][i + 2][1] - p[cur][i + 1][1]);
f &= Math.abs(p[0][i + 2][0] - p[0][i + 1][0] + p[0][i + 2][1] -
p[0][i + 1][1]) ==
Math.abs(p[cur][i + 2][0] - p[cur][i + 1][0] + p[cur][i + 2][1] -
p[cur][i + 1][1]);
}
if (f)
return true;
for (int i = 0; i < n / 2; i++) {
int[] t = p[cur][i];
p[cur][i] = p[cur][n - 1 - i];
p[cur][n - 1 - i] = t;
}
f = Math.abs(p[0][1][0] - p[0][0][0] + p[0][1][1] - p[0][0][1]) ==
Math.abs(p[cur][1][0] - p[cur][0][0] + p[cur][1][1] - p[cur][0][1]);
for (int i = 0; i < n - 2; i++) {
f &= dir(p[0][i + 1][0] - p[0][i][0], p[0][i + 1][1] - p[0][i][1],
p[0][i + 2][0] - p[0][i + 1][0],
p[0][i + 2][1] - p[0][i + 1][1]) ==
dir(p[cur][i + 1][0] - p[cur][i][0], p[cur][i + 1][1] - p[cur][i][1],
p[cur][i + 2][0] - p[cur][i + 1][0],
p[cur][i + 2][1] - p[cur][i + 1][1]);
f &= Math.abs(p[0][i + 2][0] - p[0][i + 1][0] + p[0][i + 2][1] -
p[0][i + 1][1]) ==
Math.abs(p[cur][i + 2][0] - p[cur][i + 1][0] + p[cur][i + 2][1] -
p[cur][i + 1][1]);
}
return f;
}
public static int dir(int a, int b, int c, int d) {
int sa = Integer.signum(a);
int sb = Integer.signum(b);
int sc = Integer.signum(c);
int sd = Integer.signum(d);
return sa * sd == -1 || sb * sc == 1 ? 1 : -1;
}
public static void main(String[] args) throws Exception {
ir = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() { return Double.parseDouble(next()); }
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
}
|
[["-", 0, 16, 12, 504, 516, 504, 71, 16, 17, 72], ["-", 0, 16, 12, 504, 516, 504, 71, 16, 12, 499]]
| 3
| 2,019
|
#include <math.h>
#include <stdio.h>
#define EPS 1e-5
typedef struct {
int x, y;
} vector_t;
typedef struct {
double x, y;
} vectord_t;
void complex_div(vector_t *a, vector_t *b, vectord_t *t) {
double d = a->x * a->x + a->y * a->y;
t->x = (double)(a->x * b->x + a->y * b->y) / d;
t->y = (double)(a->x * b->y - a->y * b->x) / d;
}
vector_t tmpl[10], poly[50][10];
vectord_t vec[10];
int main(void) {
int n, m, tm, i, j;
vector_t *tmpl, *p, v0, v1;
vectord_t v;
while (scanf("%d", &n) != EOF && n) {
scanf("%d", &tm);
for (i = 0; i < tm; i++) {
scanf("%d%d", &(tmpl[i].x), &(tmpl[i].y));
if (i >= 2) {
v0.x = tmpl[i - 1].x - tmpl[i - 2].x;
v0.y = tmpl[i - 1].y - tmpl[i - 2].y;
v1.x = tmpl[i].x - tmpl[i - 1].x;
v1.y = tmpl[i].y - tmpl[i - 1].y;
complex_div(&v0, &v1, &(vec[i]));
}
}
for (i = 0; i < n; i++) {
p = poly[i];
scanf("%d", &m);
for (j = 0; j < m; j++) {
scanf("%d%d", &(p[j].x), &(p[j].y));
}
for (j = 2; j < tm; j++) {
v0.x = p[j - 1].x - p[j - 2].x;
v0.y = p[j - 1].y - p[j - 2].y;
v1.x = p[j].x - p[j - 1].x;
v1.y = p[j].y - p[j - 1].y;
complex_div(&v0, &v1, &v);
if (fabs(v.x - vec[j].x) > EPS || fabs(v.y - vec[j].y) > EPS)
break;
}
if (j == tm) {
printf("%d\n", i + 1);
continue;
}
for (j = 2; j < tm; j++) {
v0.x = p[m - j].x - p[m - j + 1].x;
v0.y = p[m - j].y - p[m - j + 1].y;
v1.x = p[m - j - 1].x - p[m - j].x;
v1.y = p[m - j - 1].y - p[m - j].y;
complex_div(&v0, &v1, &v);
if (fabs(v.x - vec[j].x) > EPS || fabs(v.y - vec[j].y) > EPS)
break;
}
if (j == tm) {
printf("%d\n", i + 1);
}
}
puts("+++++");
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#define EPS 1e-5
typedef struct {
int x, y;
} vector_t;
typedef struct {
double x, y;
} vectord_t;
void complex_div(vector_t *a, vector_t *b, vectord_t *t) {
double d = a->x * a->x + a->y * a->y;
t->x = (double)(a->x * b->x + a->y * b->y) / d;
t->y = (double)(a->x * b->y - a->y * b->x) / d;
}
vector_t tmpl[10], poly[50][10];
vectord_t vec[10];
int main(void) {
int n, m, tm, i, j;
vector_t *p, v0, v1;
vectord_t v;
while (scanf("%d", &n) != EOF && n) {
scanf("%d", &tm);
for (i = 0; i < tm; i++) {
scanf("%d%d", &(tmpl[i].x), &(tmpl[i].y));
if (i >= 2) {
v0.x = tmpl[i - 1].x - tmpl[i - 2].x;
v0.y = tmpl[i - 1].y - tmpl[i - 2].y;
v1.x = tmpl[i].x - tmpl[i - 1].x;
v1.y = tmpl[i].y - tmpl[i - 1].y;
complex_div(&v0, &v1, &(vec[i]));
}
}
for (i = 0; i < n; i++) {
p = poly[i];
scanf("%d", &m);
for (j = 0; j < m; j++) {
scanf("%d%d", &(p[j].x), &(p[j].y));
}
for (j = 2; j < tm; j++) {
v0.x = p[j - 1].x - p[j - 2].x;
v0.y = p[j - 1].y - p[j - 2].y;
v1.x = p[j].x - p[j - 1].x;
v1.y = p[j].y - p[j - 1].y;
complex_div(&v0, &v1, &v);
if (fabs(v.x - vec[j].x) > EPS || fabs(v.y - vec[j].y) > EPS)
break;
}
if (j == tm) {
printf("%d\n", i + 1);
continue;
}
for (j = 2; j < tm; j++) {
v0.x = p[m - j].x - p[m - j + 1].x;
v0.y = p[m - j].y - p[m - j + 1].y;
v1.x = p[m - j - 1].x - p[m - j].x;
v1.y = p[m - j - 1].y - p[m - j].y;
complex_div(&v0, &v1, &v);
if (fabs(v.x - vec[j].x) > EPS || fabs(v.y - vec[j].y) > EPS)
break;
}
if (j == tm) {
printf("%d\n", i + 1);
}
}
puts("+++++");
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 84, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 14, 8, 9, 0, 43, 49, 84, 0, 48]]
| 0
| 782
|
#include <iostream>
using namespace std;
bool isPrime(int n) {
if (n < 2)
return false;
for (int i = 2; i * i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
int main() {
while (1) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
int i = 0;
int number = a;
while (1) {
if (isPrime(number))
i++;
if (i == n)
break;
number += d;
}
cout << number << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
bool isPrime(int n) {
if (n < 2)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
int main() {
while (1) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
int i = 0;
int number = a;
while (1) {
if (isPrime(number))
i++;
if (i == n)
break;
number += d;
}
cout << number << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 145
|
#coding: utf-8
l = list(range(0, 1001))
l[1] = 0
for i in range(0, 50):
if l[i] != 0:
for k in range(i + i, 1001, i):
l[k] = 0
continue
l = [x for x in l if x]
print(l)
while True:
l2 = list(map(int,input().split()))
if l2 == [0,0,0]:
break
a = l2[0]
d = l2[1]
n = l2[2]
c = 0
ch = 0
while True:
for p in l:
if (a != p and a % p == 0) or a == 1:#?´???°???????????????
ch = 1
break
if ch == 1:
a = a + d
ch = 0
continue
c = c + 1
if c == n:
break
a = a + d
print(a)
|
#coding: utf-8
l = list(range(0, 1001))
l[1] = 0
for i in range(0, 50):
if l[i] != 0:
for k in range(i + i, 1001, i):
l[k] = 0
continue
l = [x for x in l if x]
while True:
l2 = list(map(int,input().split()))
if l2 == [0,0,0]:
break
a = l2[0]
d = l2[1]
n = l2[2]
c = 0
ch = 0
while True:
for p in l:
if (a != p and a % p == 0) or a == 1:#?´???°???????????????
ch = 1
break
if ch == 1:
a = a + d
ch = 0
continue
c = c + 1
if c == n:
break
a = a + d
print(a)
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 192
|
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define EXISTch(s, c) \
((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1)
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define loop(n) FOR(i, 0, n)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007; // 10^9+7
const LL INF2 = (LL)100000000000000000; // 10^18
string getreverse(string str) {
reverse(str.begin(), str.end());
return str;
}
int main() {
int n;
cin >> n;
for (int t = 0; t < n; t++) {
string s;
cin >> s;
set<string> set;
for (int i = 1; i < s.size(); i++) {
string forward = s.substr(0, i);
string back = s.substr(i, s.size());
set.insert(forward + back);
set.insert(forward + getreverse(back));
set.insert(getreverse(forward + back));
set.insert(getreverse(forward) + getreverse(back));
set.insert(back + forward);
set.insert(back + getreverse(forward));
set.insert(getreverse(back) + forward);
set.insert(getreverse(back) + getreverse(forward));
}
cout << set.size() << endl;
}
return 0;
}
|
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define EXISTch(s, c) \
((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1)
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define loop(n) FOR(i, 0, n)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007; // 10^9+7
const LL INF2 = (LL)100000000000000000; // 10^18
string getreverse(string str) {
reverse(str.begin(), str.end());
return str;
}
int main() {
int n;
cin >> n;
for (int t = 0; t < n; t++) {
string s;
cin >> s;
set<string> set;
for (int i = 0; i < s.size(); i++) {
string forward = s.substr(0, i);
string back = s.substr(i, s.size());
set.insert(forward + back);
set.insert(forward + getreverse(back));
set.insert(getreverse(forward) + back);
set.insert(getreverse(forward) + getreverse(back));
set.insert(back + forward);
set.insert(back + getreverse(forward));
set.insert(getreverse(back) + forward);
set.insert(getreverse(back) + getreverse(forward));
}
cout << set.size() << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25], ["-", 0, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
| 1
| 528
|
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
string str;
set<string> S;
int main() {
int Tc;
cin >> Tc;
while (Tc > 0) {
Tc--;
cin >> str;
for (int i = 1; i < (int)str.size(); i++) {
string a = str.substr(0, i);
string b = str.substr(i);
string c = a;
string d = b;
reverse(c.begin(), c.end());
reverse(d.begin(), d.end());
string t[4] = {a, c, b, d};
for (int j = 0; j < 2; j++) {
for (int k = 2; k < 4; k++) {
S.insert(t[j] + t[k]);
S.insert(t[k] + t[j]);
}
}
}
cout << S.size() << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
string str;
set<string> S;
int main() {
int Tc;
cin >> Tc;
while (Tc > 0) {
Tc--;
S.clear();
cin >> str;
for (int i = 1; i < (int)str.size(); i++) {
string a = str.substr(0, i);
string b = str.substr(i);
string c = a;
string d = b;
reverse(c.begin(), c.end());
reverse(d.begin(), d.end());
string t[4] = {a, c, b, d};
for (int j = 0; j < 2; j++) {
for (int k = 2; k < 4; k++) {
S.insert(t[j] + t[k]);
S.insert(t[k] + t[j]);
}
}
}
cout << S.size() << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 223
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
string reverse(string st, int size) {
string reLine;
for (; size >= 0; size--) {
reLine.push_back(st[size]);
}
return reLine;
}
int main() {
int n;
string arrivalLine;
set<string> s;
cin >> n;
while (n--) {
string front, rear, reFront, reRear;
s.clear();
cin >> arrivalLine;
for (int i = 1; i < arrivalLine.size(); i++) {
front = arrivalLine.substr(0, i); // 前
rear = arrivalLine.substr(i); // 後ろ
// cout << front << " + " << rear << endl;
// 反転
reFront = reverse(front, front.size());
reRear = reverse(rear, rear.size());
s.insert(front + rear);
s.insert(rear + front);
s.insert(front + reRear);
s.insert(reRear + front);
s.insert(reFront + rear);
s.insert(rear + reFront);
s.insert(reFront + reRear);
s.insert(reRear + reFront);
}
// for(auto it : s){
// cout << it << endl;
// }
cout << s.size() << endl;
}
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
string reverse(string st, int size) {
string reLine;
for (; size > 0; size--) {
reLine.push_back(st[size - 1]);
}
return reLine;
}
int main() {
int n;
string arrivalLine;
set<string> s;
cin >> n;
while (n--) {
string front, rear, reFront, reRear;
s.clear();
cin >> arrivalLine;
for (int i = 1; i < arrivalLine.size(); i++) {
front = arrivalLine.substr(0, i); // 前
rear = arrivalLine.substr(i); // 後ろ
// cout << front << " + " << rear << endl;
// 反転
reFront = reverse(front, front.size());
reRear = reverse(rear, rear.size());
s.insert(front + rear);
s.insert(rear + front);
s.insert(front + reRear);
s.insert(reRear + front);
s.insert(reFront + rear);
s.insert(rear + reFront);
s.insert(reFront + reRear);
s.insert(reRear + reFront);
}
// for(auto it : s){
// cout << it << endl;
// }
cout << s.size() << endl;
}
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 20], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 252
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
int m;
string line, fr, sc;
cin >> m;
while (m--) {
cin >> line;
set<string> s;
s.insert(line);
for (int i = 1; i < line.size(); ++i) {
fr = line.substr(0, i);
sc = line.substr(i, line.size());
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 4; ++k) {
s.insert(fr + sc);
if (i % 2)
reverse(fr.begin(), fr.end());
else
reverse(sc.begin(), sc.end());
s.insert(fr + sc);
}
fr.swap(sc);
}
}
cout << s.size() << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
int m;
string line, fr, sc;
cin >> m;
while (m--) {
cin >> line;
set<string> s;
s.insert(line);
for (int i = 1; i < line.size(); ++i) {
fr = line.substr(0, i);
sc = line.substr(i, line.size());
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 4; ++k) {
s.insert(fr + sc);
if (k % 2)
reverse(fr.begin(), fr.end());
else
reverse(sc.begin(), sc.end());
s.insert(fr + sc);
}
fr.swap(sc);
}
}
cout << s.size() << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
| 1
| 217
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(int argc, const char *argv[]) {
int n;
cin >> n;
while (n--) {
set<string> kinds;
string str;
cin >> str;
for (int i = 1; i < str.size(); i++) {
string s1 = str.substr(i), s2 = str.substr(0, i);
string r1 = s1, r2 = s2;
reverse(r1.begin(), r1.end());
reverse(r2.begin(), r2.end());
string s[8] = {
s1 + s2, s1 + r2, r1 + s2, r1 + r2,
s2 + s1, r2 + s1, s2 + r1, r2 + r1,
};
for (int j = 0; j < 8; j++)
kinds.insert(s[i]);
}
cout << kinds.size() << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(int argc, const char *argv[]) {
int n;
cin >> n;
while (n--) {
set<string> kinds;
string str;
cin >> str;
for (int i = 1; i < str.size(); i++) {
string s1 = str.substr(i), s2 = str.substr(0, i);
string r1 = s1, r2 = s2;
reverse(r1.begin(), r1.end());
reverse(r2.begin(), r2.end());
string s[8] = {
s1 + s2, s1 + r2, r1 + s2, r1 + r2,
s2 + s1, r2 + s1, s2 + r1, r2 + r1,
};
for (int j = 0; j < 8; j++)
kinds.insert(s[j]);
}
cout << kinds.size() << endl;
}
}
|
[["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 22], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 22]]
| 1
| 209
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
int M;
cin >> M;
for (int i = 0; i < M; ++i) {
string S;
cin >> S;
typedef set<string> set_t;
set_t all;
all.insert(S);
for (int j = 1; j < S.size(); ++j) {
string L;
for (int k = 0; k <= j; ++k) {
L += S[k];
}
string R;
for (int k = j + 1; k < S.size(); ++k) {
R += S[k];
}
string L2 = L, R2 = R;
reverse(L2.begin(), L2.end());
reverse(R2.begin(), R2.end());
all.insert(L + R2);
all.insert(L2 + R);
all.insert(L2 + R2);
all.insert(R + L);
all.insert(R + L2);
all.insert(R2 + L2);
all.insert(R2 + L);
}
cout << all.size() << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
int M;
cin >> M;
for (int i = 0; i < M; ++i) {
string S;
cin >> S;
typedef set<string> set_t;
set_t all;
all.insert(S);
for (int j = 1; j < S.size(); ++j) {
string L;
for (int k = 0; k < j; ++k) {
L += S[k];
}
string R;
for (int k = j; k < S.size(); ++k) {
R += S[k];
}
string L2 = L, R2 = R;
reverse(L2.begin(), L2.end());
reverse(R2.begin(), R2.end());
all.insert(L + R2);
all.insert(L2 + R);
all.insert(L2 + R2);
all.insert(R + L);
all.insert(R + L2);
all.insert(R2 + L2);
all.insert(R2 + L);
}
cout << all.size() << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 255
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<string> set_t;
set_t A;
int organize(string str1, string str2) {
A.insert(str1 + str2);
A.insert(str2 + str1);
}
int main() {
int k;
cin >> k;
string train;
for (int i = 0; i < k; i++) {
cin >> train;
int len = train.length();
for (int j = 0; j < len - 1; j++) {
string str1;
string str2;
for (int l = 0; l <= j; l++) {
str1 += train[l];
}
for (int l = j + 1; l < len; l++) {
str2 += train[l];
}
organize(str1, str2);
reverse(str1.begin(), str1.end());
organize(str1, str2);
reverse(str2.begin(), str2.end());
organize(str1, str2);
reverse(str1.begin(), str1.end());
organize(str1, str2);
}
cout << A.size() << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<string> set_t;
set_t A;
int organize(string str1, string str2) {
A.insert(str1 + str2);
A.insert(str2 + str1);
}
int main() {
int k;
cin >> k;
string train;
for (int i = 0; i < k; i++) {
cin >> train;
int len = train.length();
for (int j = 0; j < len - 1; j++) {
string str1;
string str2;
for (int l = 0; l <= j; l++) {
str1 += train[l];
}
for (int l = j + 1; l < len; l++) {
str2 += train[l];
}
organize(str1, str2);
reverse(str1.begin(), str1.end());
organize(str1, str2);
reverse(str2.begin(), str2.end());
organize(str1, str2);
reverse(str1.begin(), str1.end());
organize(str1, str2);
}
cout << A.size() << endl;
A.clear();
}
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 251
|
// 2006à\IB ñÔÌÒ¬p[gII
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
inline string reverse(string s) {
reverse(s.begin(), s.end());
return s;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
set<string> S;
S.insert(s);
S.insert(reverse(s));
int n = s.size();
for (int i = 1; i < n - 1; i++) {
string a = s.substr(0, i);
string b = s.substr(i);
string ra = reverse(a);
string rb = reverse(b);
S.insert(a + rb);
S.insert(ra + b);
S.insert(ra + rb);
S.insert(b + a);
S.insert(b + ra);
S.insert(rb + a);
}
cout << S.size() << endl;
}
}
|
// 2006à\IB ñÔÌÒ¬p[gII
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
inline string reverse(string s) {
reverse(s.begin(), s.end());
return s;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
set<string> S;
S.insert(s);
S.insert(reverse(s));
int n = s.size();
for (int i = 1; i < n; i++) {
string a = s.substr(0, i);
string b = s.substr(i);
string ra = reverse(a);
string rb = reverse(b);
S.insert(a + rb);
S.insert(ra + b);
S.insert(ra + rb);
S.insert(b + a);
S.insert(b + ra);
S.insert(rb + a);
}
cout << S.size() << endl;
}
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 219
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int m;
vector<string> train;
bool input() {
cin >> m;
for (int i = 0; i < m; i++) {
string tmp;
cin >> tmp;
train.push_back(tmp);
}
return true;
}
string rev_str(string s) {
string ret;
for (int i = 0; i < s.size(); i++) {
ret += s[s.size() - 1 - i];
}
return ret;
}
int solve(int n) {
vector<string> mem;
for (int i = 1; i < train[n].size(); i++) {
string strage1, strage2;
string s[8];
for (int j = 0; j < i; j++) {
strage1 += train[n][j];
}
for (int j = i; j < train[n].size(); j++) {
strage2 += train[n][j];
}
s[0] = strage1 + strage2;
s[1] = rev_str(strage1) + strage2;
s[2] = strage1 + rev_str(strage2);
s[3] = strage2 + strage1;
s[4] = rev_str(strage2) + strage1;
s[5] = strage2 + rev_str(strage1);
s[6] = rev_str(strage1) + rev_str(strage2);
s[7] = rev_str(strage2) + rev_str(strage1);
s[8] = rev_str(s[0]);
s[9] = rev_str(s[3]);
for (int j = 0; j < 10; j++) {
bool flag = true;
for (int k = 0; k < mem.size(); k++) {
if (mem[k] == s[j]) {
flag = false;
break;
}
}
if (flag) {
mem.push_back(s[j]);
}
}
}
return mem.size();
}
int main(void) {
input();
for (int i = 0; i < m; i++) {
cout << solve(i) << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int m;
vector<string> train;
bool input() {
cin >> m;
for (int i = 0; i < m; i++) {
string tmp;
cin >> tmp;
train.push_back(tmp);
}
return true;
}
string rev_str(string s) {
string ret;
for (int i = 0; i < s.size(); i++) {
ret += s[s.size() - 1 - i];
}
return ret;
}
int solve(int n) {
vector<string> mem;
for (int i = 1; i < train[n].size(); i++) {
string strage1, strage2;
string s[10];
for (int j = 0; j < i; j++) {
strage1 += train[n][j];
}
for (int j = i; j < train[n].size(); j++) {
strage2 += train[n][j];
}
s[0] = strage1 + strage2;
s[1] = rev_str(strage1) + strage2;
s[2] = strage1 + rev_str(strage2);
s[3] = strage2 + strage1;
s[4] = rev_str(strage2) + strage1;
s[5] = strage2 + rev_str(strage1);
s[6] = rev_str(strage1) + rev_str(strage2);
s[7] = rev_str(strage2) + rev_str(strage1);
s[8] = rev_str(s[0]);
s[9] = rev_str(s[3]);
for (int j = 0; j < 10; j++) {
bool flag = true;
for (int k = 0; k < mem.size(); k++) {
if (mem[k] == s[j]) {
flag = false;
break;
}
}
if (flag) {
mem.push_back(s[j]);
}
}
}
return mem.size();
}
int main() {
input();
for (int i = 0; i < m; i++) {
cout << solve(i) << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 40]]
| 1
| 463
|
def sol( s )
l = s.length
a = Array.new
for i in 1..i
s1 = a[0, i]
s2 = a[i..l-1]
a.push( s1 + s2 )
a.push( s2 + s1 )
a.push( s1.reverse + s2 )
a.push( s2 + s1.reverse )
a.push( s1 + s2.reverse )
a.push( s2.reverse + s1 )
a.push( s1.reverse + s2.reverse )
a.push( s2.reverse + s1.reverse )
end
a.uniq.size
end
m = gets.chomp.to_i
m.times do
s = gets.chomp.to_s
puts sol( s )
end
|
def sol( s )
l = s.length
a = Array.new
for i in 1..l
s1 = s[0, i]
s2 = s[i..(l-1)]
a.push( s1 + s2 )
a.push( s2 + s1 )
a.push( s1.reverse + s2 )
a.push( s2 + s1.reverse )
a.push( s1 + s2.reverse )
a.push( s2.reverse + s1 )
a.push( s1.reverse + s2.reverse )
a.push( s2.reverse + s1.reverse )
end
a.uniq.size
end
m = gets.chomp.to_i
m.times do
s = gets.chomp.to_s
puts sol( s )
end
|
[["-", 8, 736, 0, 88, 51, 267, 0, 475, 444, 22], ["+", 8, 736, 0, 88, 51, 267, 0, 475, 444, 22], ["-", 0, 88, 8, 170, 0, 662, 12, 742, 500, 22], ["+", 0, 88, 8, 170, 0, 662, 12, 742, 500, 22], ["+", 0, 662, 12, 742, 0, 475, 444, 739, 0, 24], ["+", 0, 662, 12, 742, 0, 475, 444, 739, 0, 25]]
| 4
| 150
|
ls = []
def add(t):
if t not in ls:
ls.append(t)
n = int(input())
for i in range(n):
t = input()[:-1]
ls = [t]
for j in range(1,len(t)):
f, b = t[:j], t[j:]
add(f+b[::-1])
add(f[::-1]+b)
add(f[::-1]+b[::-1])
add(b+f)
add(b+f[::-1])
add(b[::-1]+f)
add(b[::-1]+f[::-1])
print(len(ls))
|
ls = []
def add(t):
if t not in ls:
ls.append(t)
n = int(input())
for i in range(n):
t = input()
ls = [t]
for j in range(1,len(t)):
f, b = t[:j], t[j:]
add(f+b[::-1])
add(f[::-1]+b)
add(f[::-1]+b[::-1])
add(b+f)
add(b+f[::-1])
add(b[::-1]+f)
add(b[::-1]+f[::-1])
print(len(ls))
|
[["-", 8, 196, 0, 1, 0, 662, 12, 206, 0, 70], ["-", 0, 1, 0, 662, 12, 206, 206, 663, 0, 102], ["-", 0, 662, 12, 206, 206, 663, 0, 664, 17, 33], ["-", 0, 662, 12, 206, 206, 663, 0, 664, 28, 612], ["-", 8, 196, 0, 1, 0, 662, 12, 206, 0, 73]]
| 5
| 178
|
#coding: utf-8
n = int(input())
for i in range(n):
s = input()
l = set([s])
for k in range(len(s)-1):
t1 = s[:k+1]
t2 = s[k+1:]
n1 = t1 + t2[::-1]
n2 = t1[::-1] + t2
n3 = t1[::-1] + t2[::-1]
n4 = t2 + t1[::-1]
n5 = t2[::-1] + t1
n6 = t2[::-1] + t1[::-1]
n7 = t2 + t1
l2 = set([n1,n2,n3,n4,n5,n6,n7])
l = l.union(l2)
print(len(l))
print(l)
|
#coding: utf-8
n = int(input())
for i in range(n):
s = input()
l = set([s])
for k in range(len(s)-1):
t1 = s[:k+1]
t2 = s[k+1:]
n1 = t1 + t2[::-1]
n2 = t1[::-1] + t2
n3 = t1[::-1] + t2[::-1]
n4 = t2 + t1[::-1]
n5 = t2[::-1] + t1
n6 = t2[::-1] + t1[::-1]
n7 = t2 + t1
l2 = set([n1,n2,n3,n4,n5,n6,n7])
l = l.union(l2)
print(len(l))
|
[["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 183
|
def main
n = gets.chomp.to_i
n.times do
mcxi1,mcxi2 = gets.chomp.split(' ').map{ |x| to_integer(x)}
puts to_mcxi(mcxi1 + mcxi2)
end
end
def to_integer mcxi
integer = 0
num = 1
mcxi.each_char do |c|
if c =~ /[2-9]/
num = c.to_i
next
end
integer += num * begin
case c
when 'm'; 1000
when 'c'; 100
when 'x'; 10
when 'i'; 1
end
end
num = 1
end
integer
end
def to_mcxi integer
mcxi = ''
m = integer / 1000
unless m == 0
mcxi << m.to_s unless m == 1
mcxi << m
end
c = integer % 1000 / 100
unless c == 0
mcxi << c.to_s unless c == 1
mcxi << c
end
x = integer % 100 / 10
unless x == 0
mcxi << x.to_s unless x == 1
mcxi << x
end
i = integer % 10 / 1
unless i == 0
mcxi << i.to_s unless i == 1
mcxi << i
end
mcxi
end
main
|
def main
n = gets.chomp.to_i
n.times do
mcxi1,mcxi2 = gets.chomp.split(' ').map{ |x| to_integer(x)}
puts to_mcxi(mcxi1 + mcxi2)
end
end
def to_integer mcxi
integer = 0
num = 1
mcxi.each_char do |c|
if c =~ /[2-9]/
num = c.to_i
next
end
integer += num * begin
case c
when 'm'; 1000
when 'c'; 100
when 'x'; 10
when 'i'; 1
end
end
num = 1
end
integer
end
def to_mcxi integer
mcxi = ''
m = integer / 1000
unless m == 0
mcxi << m.to_s unless m == 1
mcxi << 'm'
end
c = integer % 1000 / 100
unless c == 0
mcxi << c.to_s unless c == 1
mcxi << 'c'
end
x = integer % 100 / 10
unless x == 0
mcxi << x.to_s unless x == 1
mcxi << 'x'
end
i = integer % 10 / 1
unless i == 0
mcxi << i.to_s unless i == 1
mcxi << 'i'
end
mcxi
end
main
|
[["+", 0, 747, 64, 749, 0, 738, 12, 557, 0, 62]]
| 4
| 219
|
a={'m':1000,'c':100,'x':10,'i':1}
for _ in range(int(input())):
b,s,t=input(),0,1
for x in b:
if x==' ':continue
if x in a:s+=a[x]*t;t=1
else:t=int(x)
ans=''
for k in ['m','c','x','i']:
c,s=divmod(s,a[k])
if c:ans+=['',str(c)][c!=0]+k
print(ans)
|
a={'m':1000,'c':100,'x':10,'i':1}
for _ in range(int(input())):
b,s,t=input(),0,1
for x in b:
if x==' ':continue
if x in a:s+=a[x]*t;t=1
else:t=int(x)
ans=''
for k in ['m','c','x','i']:
c,s=divmod(s,a[k])
if c:ans+=['',str(c)][c!=1]+k
print(ans)
|
[["-", 0, 677, 12, 657, 31, 206, 206, 666, 0, 612], ["+", 0, 677, 12, 657, 31, 206, 206, 666, 0, 612]]
| 5
| 154
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define LDcout(x, n) fixed << setprecision(n) << x
#define MOD 1000000007LL
#define EPS 1e-8
static const int INF = 1 << 24;
int n, m, p, a, b;
void mainmain() {
while (cin >> n >> m >> p >> a >> b, n) {
VV(pii) vv(m);
vint v(n);
a--;
b--;
rep(i, n) cin >> v[i];
rep(i, p) {
int x, y, z;
cin >> x >> y >> z;
x--;
y--;
vv[x].PB(pii(y, z));
vv[y].PB(pii(x, z));
}
VV(double) dp;
initvv(dp, m, 1 << n, -1.0);
priority_queue<pair<double, pii>> pq;
pq.push(mkp(0.0, pii(a, (1 << n) - 1)));
while (!pq.empty()) {
auto top = pq.top();
pq.pop();
if (dp[top.S.F][top.S.S] >= 0)
continue;
dp[top.S.F][top.S.S] = -top.F;
for (pii x : vv[top.S.F]) {
rep(i, n) {
if ((1 << i) & top.S.S) {
auto tmp = top;
tmp.S.F = x.F;
tmp.S.S -= (1 << i);
tmp.F -= (double)x.S / v[i];
if (dp[tmp.S.F][tmp.S.S] >= 0)
continue;
pq.push(tmp);
}
}
}
}
double ans = 1e200;
rep(i, 1 << n) {
if (dp[b][i] >= 0)
ans = min(ans, dp[b][i]);
}
if (ans == 1e200) {
cout << "impossible" << endl;
} else {
cout << ans << endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
mainmain();
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define LDcout(x, n) fixed << setprecision(n) << x
#define MOD 1000000007LL
#define EPS 1e-8
static const int INF = 1 << 24;
int n, m, p, a, b;
void mainmain() {
while (cin >> n >> m >> p >> a >> b, n) {
VV(pii) vv(m);
vint v(n);
a--;
b--;
rep(i, n) cin >> v[i];
rep(i, p) {
int x, y, z;
cin >> x >> y >> z;
x--;
y--;
vv[x].PB(pii(y, z));
vv[y].PB(pii(x, z));
}
VV(double) dp;
initvv(dp, m, 1 << n, -1.0);
priority_queue<pair<double, pii>> pq;
pq.push(mkp(0.0, pii(a, (1 << n) - 1)));
while (!pq.empty()) {
auto top = pq.top();
pq.pop();
if (dp[top.S.F][top.S.S] >= 0)
continue;
dp[top.S.F][top.S.S] = -top.F;
for (pii x : vv[top.S.F]) {
rep(i, n) {
if ((1 << i) & top.S.S) {
auto tmp = top;
tmp.S.F = x.F;
tmp.S.S -= (1 << i);
tmp.F -= (double)x.S / v[i];
if (dp[tmp.S.F][tmp.S.S] >= 0)
continue;
pq.push(tmp);
}
}
}
}
double ans = 1e200;
rep(i, 1 << n) {
if (dp[b][i] >= 0)
ans = min(ans, dp[b][i]);
}
if (ans == 1e200) {
cout << "Impossible" << endl;
} else {
cout << ans << endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
mainmain();
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 779
|
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
bool isso(long long int a) {
if (a == 1 || a == 0)
return false;
for (long long int i = 2; i * i <= a; ++i) {
if ((a % i)) {
} else {
return false;
}
}
return true;
}
struct edge {
int from;
int to;
long double time;
};
struct aa {
int now;
long double time;
bitset<8> tickets;
};
class Compare {
public:
// keiroが昇順に並ぶ
bool operator()(const aa &l, const aa &r) { return l.time > r.time; }
};
int main() {
while (1) {
long double memo[32][1 << 8];
for (int i = 0; i < 32; ++i) {
for (int j = 0; j < 256; ++j) {
memo[i][j] = 1e20;
}
}
int n, m, p, a, d;
cin >> n >> m >> p >> a >> d;
if (!n)
break;
a--;
d--;
vector<int> horses;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
horses.push_back(t);
}
vector<vector<edge>> edges(m);
for (int i = 0; i < p; ++i) {
int x, y;
long double z;
cin >> x >> y >> z;
x--;
y--;
edges[x].push_back(edge{x, y, z});
edges[y].push_back(edge{y, x, z});
}
priority_queue<aa, vector<aa>, Compare> que;
for (int i = 0; i < (1 << n); ++i) {
memo[a][i] = 0;
}
que.push(aa{a, 0, bitset<8>(0)});
while (!que.empty()) {
aa atop(que.top());
if (atop.now == d)
break;
que.pop();
for (int i = 0; i < edges[atop.now].size(); ++i) {
long double basetime = edges[atop.now][i].time;
int to = edges[atop.now][i].to;
for (int j = 0; j < 1 << n; ++j) {
int usehorsesum = 0;
bitset<8> used = atop.tickets;
bool ok = true;
for (int k = 0; k < n; ++k) {
if (j & (1 << k)) {
if (!atop.tickets[k]) {
if (usehorsesum) {
ok = false;
break;
}
usehorsesum += horses[k];
used[k] = true;
}
}
}
if (!ok)
continue;
if (usehorsesum) {
long double realtime = basetime / usehorsesum;
if (memo[to][used.to_ulong()] > atop.time + realtime) {
que.push(aa{to, atop.time + realtime, used});
memo[to][used.to_ulong()] = atop.time + realtime;
}
} else {
continue;
}
}
}
}
long double ans = 1e19;
for (int i = 0; i < (1 << n); ++i) {
ans = min(ans, memo[d][i]);
}
if (ans > 1e19) {
cout << "Impossible" << endl;
} else {
cout << setprecision(11) << ans << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
bool isso(long long int a) {
if (a == 1 || a == 0)
return false;
for (long long int i = 2; i * i <= a; ++i) {
if ((a % i)) {
} else {
return false;
}
}
return true;
}
struct edge {
int from;
int to;
long double time;
};
struct aa {
int now;
long double time;
bitset<8> tickets;
};
class Compare {
public:
// keiroが昇順に並ぶ
bool operator()(const aa &l, const aa &r) { return l.time > r.time; }
};
int main() {
while (1) {
long double memo[32][1 << 8];
for (int i = 0; i < 32; ++i) {
for (int j = 0; j < 256; ++j) {
memo[i][j] = 1e20;
}
}
int n, m, p, a, d;
cin >> n >> m >> p >> a >> d;
if (!n)
break;
a--;
d--;
vector<int> horses;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
horses.push_back(t);
}
vector<vector<edge>> edges(m);
for (int i = 0; i < p; ++i) {
int x, y;
long double z;
cin >> x >> y >> z;
x--;
y--;
edges[x].push_back(edge{x, y, z});
edges[y].push_back(edge{y, x, z});
}
priority_queue<aa, vector<aa>, Compare> que;
for (int i = 0; i < (1 << n); ++i) {
memo[a][i] = 0;
}
que.push(aa{a, 0, bitset<8>(0)});
while (!que.empty()) {
aa atop(que.top());
if (atop.now == d)
break;
que.pop();
for (int i = 0; i < edges[atop.now].size(); ++i) {
long double basetime = edges[atop.now][i].time;
int to = edges[atop.now][i].to;
for (int j = 0; j < 1 << n; ++j) {
int usehorsesum = 0;
bitset<8> used = atop.tickets;
bool ok = true;
for (int k = 0; k < n; ++k) {
if (j & (1 << k)) {
if (!atop.tickets[k]) {
if (usehorsesum) {
ok = false;
break;
}
usehorsesum += horses[k];
used[k] = true;
}
}
}
if (!ok)
continue;
if (usehorsesum) {
long double realtime = basetime / usehorsesum;
if (memo[to][used.to_ulong()] > atop.time + realtime) {
que.push(aa{to, atop.time + realtime, used});
memo[to][used.to_ulong()] = atop.time + realtime;
}
} else {
continue;
}
}
}
}
long double ans = 1e20;
for (int i = 0; i < (1 << n); ++i) {
ans = min(ans, memo[d][i]);
}
if (ans > 1e19) {
cout << "Impossible" << endl;
} else {
cout << setprecision(11) << ans << endl;
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 815
|
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;
#define For(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Rep(i, n) For(i, 0, n)
#define Each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
#define INF INT_MAX / 3
#define MAX_N 8
#define MAX_M 30
int n, m, a, b, p;
int t[MAX_N];
int d[MAX_M][MAX_M];
double dp[1 << MAX_N][MAX_M];
void solve() {
Rep(i, 1 << n) fill(dp[i], dp[i] + m, INF);
dp[(1 << n) - 1][a] = 0;
double res = INF;
for (int S = (1 << n) - 1; S >= 0; S--) {
res = min(res, dp[S][b]);
Rep(v, m) Rep(i, n) {
if (S >> i & 1) {
Rep(u, m) {
if (d[v][u] >= 0) {
dp[S & ~(1 << i)][u] =
min(dp[S & ~(1 << i)][u], dp[S][v] + (double)d[v][u] / t[i]);
}
}
}
}
}
if (res == INF) {
printf("impossible\n");
} else {
printf("%.3f\n", res);
}
}
int main() {
while (1) {
scanf("%d %d %d %d %d", &n, &m, &p, &a, &b);
if (n == 0)
break;
a--;
b--;
Rep(i, n) { scanf("%d", &t[i]); }
Rep(i, m) Rep(j, m) {
d[i][j] = -1;
d[j][i] = -1;
}
Rep(i, p) {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
x--;
y--;
d[x][y] = z;
d[y][x] = z;
}
solve();
}
return 0;
}
|
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;
#define For(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Rep(i, n) For(i, 0, n)
#define Each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
#define INF INT_MAX / 3
#define MAX_N 8
#define MAX_M 30
int n, m, a, b, p;
int t[MAX_N];
int d[MAX_M][MAX_M];
double dp[1 << MAX_N][MAX_M];
void solve() {
Rep(i, 1 << n) fill(dp[i], dp[i] + m, INF);
dp[(1 << n) - 1][a] = 0;
double res = INF;
for (int S = (1 << n) - 1; S >= 0; S--) {
res = min(res, dp[S][b]);
Rep(v, m) Rep(i, n) {
if (S >> i & 1) {
Rep(u, m) {
if (d[v][u] >= 0) {
dp[S & ~(1 << i)][u] =
min(dp[S & ~(1 << i)][u], dp[S][v] + (double)d[v][u] / t[i]);
}
}
}
}
}
if (res == INF) {
printf("Impossible\n");
} else {
printf("%.3f\n", res);
}
}
int main() {
while (1) {
scanf("%d %d %d %d %d", &n, &m, &p, &a, &b);
if (n == 0)
break;
a--;
b--;
Rep(i, n) { scanf("%d", &t[i]); }
Rep(i, m) Rep(j, m) {
d[i][j] = -1;
d[j][i] = -1;
}
Rep(i, p) {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
x--;
y--;
d[x][y] = z;
d[y][x] = z;
}
solve();
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 525
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
class Edge {
public:
int to, len;
Edge(int to0, int len0) {
to = to0;
len = len0;
}
};
double INF = DBL_MAX / 2.0;
double EPS = 1.0e-7;
double solve(vector<int> &ticket, vector<vector<Edge>> &edges, int a, int b) {
int n = ticket.size();
int m = edges.size();
vector<vector<double>> minCost(m, vector<double>(1 << n, INF));
multimap<double, pair<int, int>> mm;
mm.insert(make_pair(0.0, make_pair(a, (1 << n) - 1)));
minCost[a][(1 << n) - 1] = 0.0;
while (!mm.empty()) {
multimap<double, pair<int, int>>::iterator it = mm.begin();
double cost = it->first;
int x = it->second.first;
int y = it->second.second;
mm.erase(it);
if (x == b)
return minCost[x][y];
if (cost < minCost[x][y] + EPS)
continue;
bitset<8> bs(y);
for (unsigned i = 0; i < edges[x].size(); ++i) {
int to = edges[x][i].to;
int len = edges[x][i].len;
for (int j = 0; j < n; ++j) {
if (!bs[j])
continue;
bs[j] = false;
double cost1 = cost + (double)len / ticket[j];
if (cost1 < minCost[to][bs.to_ulong()] - EPS) {
minCost[to][bs.to_ulong()] = cost1;
mm.insert(make_pair(cost1, make_pair(to, bs.to_ulong())));
}
bs[j] = true;
}
}
}
return INF;
}
int main() {
for (;;) {
int n, m, p, a, b;
cin >> n >> m >> p >> a >> b;
if (n == 0)
break;
vector<int> ticket(n);
for (int i = 0; i < n; ++i)
cin >> ticket[i];
vector<vector<Edge>> edges(m);
for (int i = 0; i < p; ++i) {
int x, y, z;
cin >> x >> y >> z;
edges[x - 1].push_back(Edge(y - 1, z));
edges[y - 1].push_back(Edge(x - 1, z));
}
double ret = solve(ticket, edges, a - 1, b - 1);
if (ret == INF)
cout << "Impossible" << endl;
else
printf("%.10f\n", ret);
}
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
class Edge {
public:
int to, len;
Edge(int to0, int len0) {
to = to0;
len = len0;
}
};
double INF = DBL_MAX / 2.0;
double EPS = 1.0e-7;
double solve(vector<int> &ticket, vector<vector<Edge>> &edges, int a, int b) {
int n = ticket.size();
int m = edges.size();
vector<vector<double>> minCost(m, vector<double>(1 << n, INF));
multimap<double, pair<int, int>> mm;
mm.insert(make_pair(0.0, make_pair(a, (1 << n) - 1)));
minCost[a][(1 << n) - 1] = 0.0;
while (!mm.empty()) {
multimap<double, pair<int, int>>::iterator it = mm.begin();
double cost = it->first;
int x = it->second.first;
int y = it->second.second;
mm.erase(it);
if (x == b)
return minCost[x][y];
if (cost > minCost[x][y] + EPS)
continue;
bitset<8> bs(y);
for (unsigned i = 0; i < edges[x].size(); ++i) {
int to = edges[x][i].to;
int len = edges[x][i].len;
for (int j = 0; j < n; ++j) {
if (!bs[j])
continue;
bs[j] = false;
double cost1 = cost + (double)len / ticket[j];
if (cost1 < minCost[to][bs.to_ulong()] - EPS) {
minCost[to][bs.to_ulong()] = cost1;
mm.insert(make_pair(cost1, make_pair(to, bs.to_ulong())));
}
bs[j] = true;
}
}
}
return INF;
}
int main() {
for (;;) {
int n, m, p, a, b;
cin >> n >> m >> p >> a >> b;
if (n == 0)
break;
vector<int> ticket(n);
for (int i = 0; i < n; ++i)
cin >> ticket[i];
vector<vector<Edge>> edges(m);
for (int i = 0; i < p; ++i) {
int x, y, z;
cin >> x >> y >> z;
edges[x - 1].push_back(Edge(y - 1, z));
edges[y - 1].push_back(Edge(x - 1, z));
}
double ret = solve(ticket, edges, a - 1, b - 1);
if (ret == INF)
cout << "Impossible" << endl;
else
printf("%.10f\n", ret);
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 662
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define INF (1 << 29)
using namespace std;
int main(void) {
int n, m, p, a, b, x, y, z, in;
double dp[(1 << 8)][31], graph[31][31];
vector<int> t;
while (cin >> n >> m >> p >> a >> b) {
if (!(n | m | p | a | b))
break;
t.clear();
fill(graph[0], graph[31], -1);
fill(dp[0], dp[(1 << 8)], INF);
for (int i = 0; i < n; i++) {
cin >> in;
t.push_back(in);
}
for (int i = 0; i < p; i++) {
cin >> x >> y >> z;
graph[x][y] = graph[y][x] = z;
}
dp[0][a] = 0;
double res = INF;
for (int S = 0; S < (1 << n) - 1; S++) {
res = min(res, dp[S][b]);
for (int v = 1; v <= m; v++) {
for (int i = 0; i < n; i++) {
if (!(S >> i & 1)) {
for (int u = 1; u <= m; u++) {
if (graph[v][u] < 0)
continue;
dp[S | (1 << i)][u] =
min(dp[S | (1 << i)][u], dp[S][v] + graph[v][u] / t[i]);
}
}
}
}
}
if (res == INF)
printf("Impossible\n");
else
printf("%.3f\n", res);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define INF (1 << 29)
using namespace std;
int main(void) {
int n, m, p, a, b, x, y, z, in;
double dp[(1 << 8)][31], graph[31][31];
vector<int> t;
while (cin >> n >> m >> p >> a >> b) {
if (!(n | m | p | a | b))
break;
t.clear();
fill(graph[0], graph[31], -1);
fill(dp[0], dp[(1 << 8)], INF);
for (int i = 0; i < n; i++) {
cin >> in;
t.push_back(in);
}
for (int i = 0; i < p; i++) {
cin >> x >> y >> z;
graph[x][y] = graph[y][x] = z;
}
dp[0][a] = 0;
double res = INF;
for (int S = 0; S < (1 << n); S++) {
res = min(res, dp[S][b]);
for (int v = 1; v <= m; v++) {
for (int i = 0; i < n; i++) {
if (!(S >> i & 1)) {
for (int u = 1; u <= m; u++) {
if (graph[v][u] < 0)
continue;
dp[S | (1 << i)][u] =
min(dp[S | (1 << i)][u], dp[S][v] + graph[v][u] / t[i]);
}
}
}
}
}
if (res == INF)
printf("Impossible\n");
else
printf("%.3f\n", res);
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 417
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m, p, a, b;
while (true) {
cin >> n >> m >> p >> a >> b;
if (!m && !n && !p && !a && !b) {
break;
}
vector<vector<double>> dp(1 << n, vector<double>(m + 1, INT_MAX / 4));
vector<int> t(n);
vector<vector<int>> map(m + 1, vector<int>(m + 1, INT_MAX / 4));
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < p; i++) {
int x, y, z;
cin >> x >> y >> z;
map[x][y] = z;
map[y][x] = z;
}
dp[0][a] = 0;
for (int s = 0; s < (1 << n); s++) {
for (int i = 0; i < n; i++) {
for (int j = 1; j <= m; j++) {
for (int k = 1; k <= m; k++) {
if (map[j][k] == INT_MAX / 4) {
continue;
}
if (!(s >> i & 1)) {
int next = s | (1 << i);
dp[next][k] =
min(dp[next][k], dp[s][j] + ((double)map[j][k] / t[i]));
}
}
}
}
}
double ans = INT_MAX / 4;
for (int s = 0; s < (1 << n); s++) {
ans = min(ans, dp[s][b]);
}
cout << setprecision(3) << fixed;
if (ans == INT_MAX / 4) {
cout << "Inmpossible" << endl;
} else {
cout << ans << endl;
}
}
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m, p, a, b;
while (true) {
cin >> n >> m >> p >> a >> b;
if (!m && !n && !p && !a && !b) {
break;
}
vector<vector<double>> dp(1 << n, vector<double>(m + 1, INT_MAX / 4));
vector<int> t(n);
vector<vector<int>> map(m + 1, vector<int>(m + 1, INT_MAX / 4));
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < p; i++) {
int x, y, z;
cin >> x >> y >> z;
map[x][y] = z;
map[y][x] = z;
}
dp[0][a] = 0;
for (int s = 0; s < (1 << n); s++) {
for (int i = 0; i < n; i++) {
for (int j = 1; j <= m; j++) {
for (int k = 1; k <= m; k++) {
if (map[j][k] == INT_MAX / 4) {
continue;
}
if (!(s >> i & 1)) {
int next = s | (1 << i);
dp[next][k] =
min(dp[next][k], dp[s][j] + ((double)map[j][k] / t[i]));
}
}
}
}
}
double ans = INT_MAX / 4;
for (int s = 0; s < (1 << n); s++) {
ans = min(ans, dp[s][b]);
}
cout << setprecision(3) << fixed;
if (ans == INT_MAX / 4) {
cout << "Impossible" << endl;
} else {
cout << ans << endl;
}
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 456
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#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;
using namespace std;
const int MAX = 500000;
int list[MAX];
int main() {
for (int i = 2; i < MAX; i++) {
list[i] = 0;
}
// 1が素数-1は除外された数;
for (int i = 2; i < MAX; i++) {
if (list[i] != -1)
list[i] = 1;
{
for (int k = 2; k < MAX; k++) {
if (i * k >= MAX)
break;
list[i * k] = -1;
}
}
// cout << i << "=" << list[i] << endl << endl;
}
while (true) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
int count = 0;
for (int i = 0; (a + d * i) < MAX; i++) {
if (list[a + d * i] == 1)
count++;
if (count == n) {
cout << a + d * i << endl;
break;
}
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#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;
using namespace std;
const int MAX = 1000000;
int list[MAX];
int main() {
for (int i = 2; i < MAX; i++) {
list[i] = 0;
}
// 1が素数-1は除外された数;
for (int i = 2; i < MAX; i++) {
if (list[i] != -1)
list[i] = 1;
{
for (int k = 2; k < MAX; k++) {
if (i * k >= MAX)
break;
list[i * k] = -1;
}
}
// cout << i << "=" << list[i] << endl << endl;
}
while (true) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
int count = 0;
for (int i = 0; (a + d * i) < MAX; i++) {
if (list[a + d * i] == 1)
count++;
if (count == n) {
cout << a + d * i << endl;
break;
}
}
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
| 1
| 266
|
#include <iostream>
using namespace std;
int main() {
int a, d, n;
while (cin >> a >> d >> n, n) {
int cnt = 0, f;
while (1) {
f = 0;
for (int i = 2; i * i <= a; i++) {
if (a & i == 0) {
f = 1;
break;
}
}
if (f == 0 && a != 1) {
cnt++;
}
if (cnt == n) {
cout << a << endl;
;
break;
}
a += d;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, d, n;
while (cin >> a >> d >> n, n) {
int cnt = 0, f;
while (1) {
f = 0;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
f = 1;
break;
}
}
if (f == 0 && a != 1) {
cnt++;
}
if (cnt == n) {
cout << a << endl;
;
break;
}
a += d;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 67], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 109]]
| 1
| 123
|
#include <iostream>
#include <queue>
using namespace std;
bool flug[1000001]; // false???????´???°
int main() {
int a, b, n;
for (int i = 2; i * i <= 1000000; i++) {
if (!flug[i]) {
for (int j = i * 2; j <= 1000000; j += i) {
flug[j] = true;
}
}
}
while (cin >> a >> b >> n, a + b + n) {
queue<int> que;
flug[1] = true;
for (int i = 1; i <= 1000000; i += 2) {
if (!flug[i]) {
if (i - a >= 0) {
if ((i - a) % b == 0) {
que.push(i);
}
}
}
}
for (int i = 0; i < n - 1; i++) {
que.pop();
}
cout << que.front() << endl;
}
return 0;
}
|
#include <iostream>
#include <queue>
using namespace std;
bool flug[1000001]; // false???????´???°
int main() {
int a, b, n;
for (int i = 2; i * i <= 1000000; i++) {
if (!flug[i]) {
for (int j = i * 2; j <= 1000000; j += i) {
flug[j] = true;
}
}
}
while (cin >> a >> b >> n, a + b + n) {
queue<int> que;
flug[1] = true;
for (int i = 1; i <= 1000000; i++) {
if (!flug[i]) {
if (i - a >= 0) {
if ((i - a) % b == 0) {
que.push(i);
}
}
}
}
for (int i = 0; i < n - 1; i++) {
que.pop();
}
cout << que.front() << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 26, 11, 17, 107], ["-", 0, 52, 8, 9, 0, 7, 26, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 17, 29]]
| 1
| 208
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
while (cin >> a >> b >> n && n) {
int count = 0, flag = 0;
for (int i = a; i < 1000000; i += b) {
for (int j = 2; j < sqrt(i); j++) {
if (i % j == 0 && i != j) {
flag++;
break;
}
}
if (!flag && i >= 2)
count++;
if (count == n) {
cout << i << endl;
break;
}
flag = 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
while (cin >> a >> b >> n && n) {
int count = 0, flag = 0;
for (int i = a; i <= 1000000; i += b) {
for (int j = 2; j <= sqrt(i); j++) {
if (i % j == 0 && i != j) {
flag++;
break;
}
}
if (!flag && i >= 2)
count++;
if (count == n) {
cout << i << endl;
break;
}
flag = 0;
}
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 129
|
#include <cmath>
#include <iostream>
#define N 1000000
using namespace std;
int arr[N];
//??¨????????????????????????
void Eratosthenes() {
for (int i = 0; i < N; i++) {
arr[i] = 1;
}
for (int i = 2; i < sqrt(N); i++) {
if (arr[i]) {
for (int j = 0; i * (j + 2) < N; j++) {
arr[i * (j + 2)] = 0;
}
}
}
}
int main(void) {
Eratosthenes();
while (1) {
int a, d, n;
cin >> a >> d >> n;
// cout << a << d << n;
if (a == 0 && d == 0 && n == 0)
break;
int x, i = 0, j = 0;
while (1) {
if (j == n)
break;
x = a + i * d;
if (arr[x])
j++;
i++;
}
cout << x << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
#define N 1000000
using namespace std;
int arr[N];
//??¨????????????????????????
void Eratosthenes() {
for (int i = 0; i < N; i++) {
arr[i] = 1;
}
for (int i = 2; i < sqrt(N); i++) {
if (arr[i]) {
for (int j = 0; i * (j + 2) < N; j++) {
arr[i * (j + 2)] = 0;
}
}
}
}
int main(void) {
Eratosthenes();
while (1) {
int a, d, n;
cin >> a >> d >> n;
// cout << a << d << n;
if (a == 0 && d == 0 && n == 0)
break;
int x, i = 0, j = 0;
while (1) {
if (j == n)
break;
x = a + i * d;
if (x > 1 && arr[x])
j++;
i++;
}
cout << x << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 214
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, n;
while (true) {
cin >> a >> b >> n;
if (a == 0 && b == 0 && n == 0)
break;
int count = 0, s = a;
if (a < 2)
a += b;
while (true) {
bool t = true;
for (int j = 2; j * j <= s; j++) {
if (s % j == 0)
t = false;
}
if (t == true)
count++;
if (count == n)
break;
s += b;
}
cout << s << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, n;
while (true) {
cin >> a >> b >> n;
if (a == 0 && b == 0 && n == 0)
break;
int count = 0, s = a;
while (s < 2)
s += b;
while (true) {
bool t = true;
for (int j = 2; j * j <= s; j++) {
if (s % j == 0)
t = false;
}
if (t == true)
count++;
if (count == n)
break;
s += b;
}
cout << s << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 57, 0, 121], ["+", 8, 9, 0, 52, 8, 9, 0, 52, 0, 89], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 9, 0, 52, 8, 1, 0, 11, 31, 22]]
| 1
| 141
|
#include <iostream>
#include <vector>
using namespace std;
bool isPrime(int x) {
if (x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (x % 2 == 0) {
return false;
}
for (int i = 3; i * i < x; i += 2) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
while (1) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0) {
break;
}
int count = 0;
for (int i = a; count < n; i += d) {
if (isPrime(i)) {
++count;
if (count == n) {
cout << i << endl;
break;
}
}
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
bool isPrime(int x) {
if (x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (x % 2 == 0) {
return false;
}
for (int i = 3; i * i <= x; i += 2) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
while (1) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0) {
break;
}
int count = 0;
for (int i = a; count < n; i += d) {
if (isPrime(i)) {
++count;
if (count == n) {
cout << i << endl;
break;
}
}
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 184
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
const int INF = 1 << 28;
const int MAX = 1000000 + 1;
bool prime[MAX];
void sieve() {
memset(prime, true, sizeof(prime));
prime[0] = false;
FOR(i, 2, MAX) {
if (prime[i]) {
for (int j = i; j < MAX; j += i) {
if (j == i)
continue;
prime[j] = false;
}
}
}
}
int main() {
sieve();
int a, d, n;
while (cin >> a >> d >> n, a | d | n) {
int cnt = 0;
REP(i, MAX) {
if (prime[a + d * i])
cnt++;
if (cnt == n) {
cout << a + d * i << endl;
break;
}
}
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
const int INF = 1 << 28;
const int MAX = 1000000 + 1;
bool prime[MAX];
void sieve() {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
FOR(i, 2, MAX) {
if (prime[i]) {
for (int j = i; j < MAX; j += i) {
if (j == i)
continue;
prime[j] = false;
}
}
}
}
int main() {
sieve();
int a, d, n;
while (cin >> a >> d >> n, a | d | n) {
int cnt = 0;
REP(i, MAX) {
if (prime[a + d * i])
cnt++;
if (cnt == n) {
cout << a + d * i << endl;
break;
}
}
}
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 11, 31, 69, 28, 22], ["+", 0, 11, 12, 11, 31, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 11, 31, 69, 341, 342, 0, 13], ["+", 0, 11, 12, 11, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 17, 32]]
| 1
| 242
|
#include <iostream>
using namespace std;
int main() {
int a[100000] = {0, 0, 1, 1}, n, k = 0;
for (int i = 4; i < 100000; i++) {
for (int j = 2; j * j <= i; j++) {
if (i % j == 0) {
k++;
break;
}
}
if (!k)
a[i]++;
k = 0;
}
int b, c, d, x, s, q;
while (cin >> b >> c >> d, b != 0 && c != 0 && d != 0) {
s = x = q = 0;
while (1) {
x = b + c * s;
if (a[x] == 1)
q++;
if (q == d)
break;
s++;
}
cout << x << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a[1000000] = {0, 0, 1, 1}, n, k = 0;
for (int i = 4; i < 1000000; i++) {
for (int j = 2; j * j <= i; j++) {
if (i % j == 0) {
k++;
break;
}
}
if (!k)
a[i]++;
k = 0;
}
int b, c, d, x, s, q;
while (cin >> b >> c >> d, b != 0 && c != 0 && d != 0) {
s = x = q = 0;
while (1) {
x = b + c * s;
if (a[x] == 1)
q++;
if (q == d)
break;
s++;
}
cout << x << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 189
|
#include <iostream>
using namespace std;
int main() {
int max = 1000000;
bool *pt;
pt = new bool[max];
pt[1] = false;
pt[2] = true;
for (int i = 3; i < max; i++) {
pt[i] = true;
if (i % 2 == 0) {
pt[i] = false;
continue;
} else {
for (int l = 3; l * l < i; l += 2) {
if (i % l == 0) {
pt[i] = false;
break;
}
}
}
}
while (1) {
int a, d, n, c = 0;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
for (int i = a;; i += d) {
if (pt[i] == true) {
c++;
}
if (c == n) {
cout << i << endl;
break;
}
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int max = 1000000;
bool *pt;
pt = new bool[max];
pt[1] = false;
pt[2] = true;
for (int i = 3; i < max; i++) {
pt[i] = true;
if (i % 2 == 0) {
pt[i] = false;
continue;
} else {
for (int l = 3; l * l <= i; l += 2) {
if (i % l == 0) {
pt[i] = false;
break;
}
}
}
}
while (1) {
int a, d, n, c = 0;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
for (int i = a;; i += d) {
if (pt[i] == true) {
c++;
}
if (c == n) {
cout << i << endl;
break;
}
}
}
return 0;
}
|
[["-", 75, 76, 0, 9, 0, 7, 15, 16, 17, 18], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 214
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PA;
using namespace std;
#define MAX 9999999
int main() {
// ?´???°??????sqrt(max)??§??????
vector<bool> check(MAX + 1);
rep(i, MAX + 1) check[i] = true;
vector<int> Primenumber(MAX + 1, 0); // Primearray
int counter = 0; // Primearray counter;
for (int i = 2; i < MAX + 1; i++) {
if (check[i]) {
for (int j = 2; i * j < MAX; j++)
check[i * j] =
false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
Primenumber[counter] = i;
counter++;
}
}
int a, d, n;
while (cin >> a >> d >> n, a + d + n) {
int count = 0;
int ans = 0;
while (true) {
if (check[a])
count++;
if (count == n) {
ans = a;
break;
}
a += d;
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PA;
using namespace std;
#define MAX 999999
int main() {
// ?´???°??????sqrt(max)??§??????
vector<bool> check(MAX + 1);
rep(i, MAX + 1) check[i] = true;
vector<int> Primenumber(MAX + 1, 0); // Primearray
int counter = 0; // Primearray counter;
for (int i = 2; i < MAX + 1; i++) {
if (check[i]) {
for (int j = 2; i * j < MAX; j++)
check[i * j] =
false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
Primenumber[counter] = i;
counter++;
}
}
int a, d, n;
while (cin >> a >> d >> n, a + d + n) {
int count = 0;
int ans = 0;
while (true) {
if (check[a] && a != 1)
count++;
if (count == n) {
ans = a;
break;
}
a += d;
}
cout << ans << endl;
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 277
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define pb push_back
#define N 100000000
#define int long long
int arr[N];
void eratosthenes() {
rep(i, N) { arr[i] = 1; }
for (int i = 2; i < sqrt(N); i++) {
if (arr[i]) {
for (int j = 0; i * (j + 2) < N; j++) {
arr[i * (j + 2)] = 0;
}
}
}
arr[0] = 0;
arr[1] = 0;
}
signed main() {
eratosthenes();
// for(int i=0;i<100;i++){
// cout<<i<<" "<<arr[i]<<endl;
// }
int count;
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
count = 0;
for (int i = a; i < 100000000; i += d) {
// if(count>220)break;
if (arr[i] == 1) {
// cout<<arr[i]<<":"<<count<<":"<<i<<endl;
if (count == n - 1) {
cout << i << endl;
break;
}
count++;
}
}
// rep(i,100){
// cout<<i<<" "<<v[i]<<endl;
// }
// cout<<v[n-1]<<endl;
// rep(i,100){
// cout<<v[i]<<endl;
// }
// cout<<v[n-1]<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define pb push_back
#define N 1000000
#define int long long
int arr[N];
void eratosthenes() {
rep(i, N) { arr[i] = 1; }
for (int i = 2; i < sqrt(N); i++) {
if (arr[i]) {
for (int j = 0; i * (j + 2) < N; j++) {
arr[i * (j + 2)] = 0;
}
}
}
arr[0] = 0;
arr[1] = 0;
}
signed main() {
eratosthenes();
// for(int i=0;i<100;i++){
// cout<<i<<" "<<arr[i]<<endl;
// }
int count;
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
count = 0;
for (int i = a; i < 1000000; i += d) {
// if(count>220)break;
if (arr[i] == 1) {
// cout<<arr[i]<<":"<<count<<":"<<i<<endl;
if (count == n - 1) {
cout << i << endl;
break;
}
count++;
}
}
// rep(i,100){
// cout<<i<<" "<<v[i]<<endl;
// }
// cout<<v[n-1]<<endl;
// rep(i,100){
// cout<<v[i]<<endl;
// }
// cout<<v[n-1]<<endl;
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 253
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
#define INF 1 << 21
#define MOD 1000000007
#define MAX 1000000
int main() {
int p[MAX];
memset(p, 1, sizeof(p));
p[0] = 0;
p[1] = 0;
for (int i = 2; i <= sqrt(MAX) + 1; i++) {
if (p[i] == 1) {
for (int j = 2 * i; j <= MAX; j += i) {
p[j] = 0;
}
}
}
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
return 0;
while (1) {
if (p[a] == 1)
n--;
if (n == 0) {
cout << a << endl;
break;
}
a += d;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
#define INF 1 << 21
#define MOD 1000000007
#define MAX 1000000
int main() {
char p[MAX];
memset(p, 1, sizeof(p));
p[0] = 0;
p[1] = 0;
for (int i = 2; i <= sqrt(MAX) + 1; i++) {
if (p[i] == 1) {
for (int j = 2 * i; j <= MAX; j += i) {
p[j] = 0;
}
}
}
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
return 0;
while (1) {
if (p[a] == 1)
n--;
if (n == 0) {
cout << a << endl;
break;
}
a += d;
}
}
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40]]
| 1
| 203
|
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define M 1e6
int main() {
vector<bool> hurui(M, true);
hurui[1] = true;
for (int i = 2; i <= sqrt(M); i++) {
if (hurui[i]) {
for (int j = 2 * i; j < M; j += i) {
hurui[j] = false;
}
}
}
int a, d, n;
while (true) {
cin >> a >> d >> n;
if (a == 0)
break;
for (int i = a; i < M; i += d) {
if (hurui[i])
n--;
if (n == 0) {
cout << i << endl;
break;
}
}
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define M 1e6
int main() {
vector<bool> hurui(M, true);
hurui[1] = false;
for (int i = 2; i <= sqrt(M); i++) {
if (hurui[i]) {
for (int j = 2 * i; j < M; j += i) {
hurui[j] = false;
}
}
}
int a, d, n;
while (true) {
cin >> a >> d >> n;
if (a == 0)
break;
for (int i = a; i < M; i += d) {
if (hurui[i])
n--;
if (n == 0) {
cout << i << endl;
break;
}
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 146], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 147]]
| 1
| 166
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int main(void) {
int p = 0;
for (int i = 0; i <= 100000; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= 100000; i++) {
if (is_prime[i]) {
prime[p] = i;
p++;
for (int j = 2 * i; j <= 100000; j += i)
is_prime[j] = false;
}
}
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (!n)
break;
int i = a;
int j = 0;
while (1) {
if (is_prime[i + j * d])
n--;
if (n == 0) {
cout << i + j * d << endl;
break;
}
j++;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int main(void) {
int p = 0;
for (int i = 0; i <= 1000000; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= 1000000; i++) {
if (is_prime[i]) {
prime[p] = i;
p++;
for (int j = 2 * i; j <= 1000000; j += i)
is_prime[j] = false;
}
}
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (!n)
break;
int i = a;
int j = 0;
while (1) {
if (is_prime[i + j * d])
n--;
if (n == 0) {
cout << i + j * d << endl;
break;
}
j++;
}
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 214
|
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
/* cpp template {{{ */
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()
/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto &&i : n)
/* debug */
#define debug(x) \
cerr << x << " " \
<< "(L:" << __LINE__ << ")" << '\n';
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* func */
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline int in() {
int x;
cin >> x;
return x;
}
inline ll IN() {
ll x;
cin >> x;
return x;
}
inline vs split(const string &t, char c) {
vs v;
stringstream s(t);
string b;
while (getline(s, b, c))
v.eb(b);
return v;
}
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
a = b;
return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
a = b;
return a < b;
}
template <typename T, typename S> inline void print(const pair<T, S> &p) {
cout << p.first << " " << p.second << endl;
}
template <typename T> inline void print(const T &x) { cout << x << '\n'; }
template <typename T, typename S>
inline void print(const vector<pair<T, S>> &v) {
for (auto &&p : v)
print(p);
}
template <typename T> inline void print(const vector<T> &v, string s = " ") {
rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");
}
//素数判定
bool isPrime(int n) {
if (n <= 1)
return false;
for (int i = 2; i < sqrt(double(n)); ++i) {
if (!(n % i))
return false;
}
return true;
}
signed main() {
int a, d, n;
vi ans;
while (cin >> a >> d >> n, a || d || n) {
int cnt = 0;
while (1) {
if (isPrime(a)) {
++cnt;
if (cnt == n)
break;
}
a += d;
}
ans.pb(a);
}
EACH(e, ans) print(e);
return 0;
}
|
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
/* cpp template {{{ */
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()
/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto &&i : n)
/* debug */
#define debug(x) \
cerr << x << " " \
<< "(L:" << __LINE__ << ")" << '\n';
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* func */
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline int in() {
int x;
cin >> x;
return x;
}
inline ll IN() {
ll x;
cin >> x;
return x;
}
inline vs split(const string &t, char c) {
vs v;
stringstream s(t);
string b;
while (getline(s, b, c))
v.eb(b);
return v;
}
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
a = b;
return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
a = b;
return a < b;
}
template <typename T, typename S> inline void print(const pair<T, S> &p) {
cout << p.first << " " << p.second << endl;
}
template <typename T> inline void print(const T &x) { cout << x << '\n'; }
template <typename T, typename S>
inline void print(const vector<pair<T, S>> &v) {
for (auto &&p : v)
print(p);
}
template <typename T> inline void print(const vector<T> &v, string s = " ") {
rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");
}
//素数判定
bool isPrime(int n) {
if (n <= 1)
return false;
for (int i = 2; i <= sqrt(double(n)); ++i) {
if (!(n % i))
return false;
}
return true;
}
signed main() {
int a, d, n;
vi ans;
while (cin >> a >> d >> n, a || d || n) {
int cnt = 0;
while (1) {
if (isPrime(a)) {
++cnt;
if (cnt == n)
break;
}
a += d;
}
ans.pb(a);
}
EACH(e, ans) print(e);
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 818
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
int a, b, n;
cin >> a >> b >> n;
if (a == 0 && b == 0 && n == 0)
break;
int count = 0, s = 0, ans;
for (int j = a; count != n; j += b) {
s = 0;
for (int k = 2; k < sqrt(j) + 1; k++) {
if (j == 1) {
s = 1;
break;
}
if (j == 2) {
break;
}
if (j % k == 0) {
s = 1;
break;
}
}
if (s == 0) {
count++;
ans = j;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
int a, b, n;
cin >> a >> b >> n;
if (a == 0 && b == 0 && n == 0)
break;
int count = 0, s = 0, ans;
for (int j = a; count != n; j += b) {
s = 0;
for (int k = 2; k <= sqrt(j) + 1; k++) {
if (j == 1) {
s = 1;
break;
}
if (j == 2) {
break;
}
if (j % k == 0) {
s = 1;
break;
}
}
if (s == 0) {
count++;
ans = j;
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 166
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<bool> isprime(500000, true);
isprime[0] = isprime[1] = false;
for (int i = 2; i < 500000; i++) {
if (isprime[i]) {
for (int j = 2; i * j < 500000; j++) {
isprime[i * j] = false;
}
}
}
vector<int> p;
for (int i = 0; i < 500000; i++) {
if (isprime[i])
p.push_back(i);
}
while (true) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0)
break;
int cnt = 0;
for (int i = a; i < 500000; i += d) {
if (*lower_bound(p.begin(), p.end(), i) == i) {
cnt++;
if (cnt == n) {
cout << i << endl;
break;
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<bool> isprime(1000000, true);
isprime[0] = isprime[1] = false;
for (int i = 2; i < 1000000; i++) {
if (isprime[i]) {
for (int j = 2; i * j < 1000000; j++) {
isprime[i * j] = false;
}
}
}
vector<int> p;
for (int i = 0; i < 1000000; i++) {
if (isprime[i])
p.push_back(i);
}
while (true) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0)
break;
int cnt = 0;
for (int i = a; i < 1000000; i += d) {
if (*lower_bound(p.begin(), p.end(), i) == i) {
cnt++;
if (cnt == n) {
cout << i << endl;
break;
}
}
}
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 220
|
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
const int N = 1000001;
vector<bool> prime(N, true);
prime[0] = false;
prime[1] = false;
for (int i = 2; i < N; i++) {
if (prime[i]) {
for (int j = i + i; j < N; j += i) {
prime[j] = false;
}
}
}
for (;;) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0)
break;
for (;;) {
while (!prime[a]) {
a += d;
}
if (n == 0)
break;
a += d;
}
cout << a << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
const int N = 1000001;
vector<bool> prime(N, true);
prime[0] = false;
prime[1] = false;
for (int i = 2; i < N; i++) {
if (prime[i]) {
for (int j = i + i; j < N; j += i) {
prime[j] = false;
}
}
}
for (;;) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0)
break;
for (;;) {
while (!prime[a]) {
a += d;
}
n--;
if (n == 0)
break;
a += d;
}
cout << a << endl;
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 68], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 176
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_SIZE = 100000;
int prime[MAX_SIZE];
bool isPrime[MAX_SIZE];
int p;
int main() {
fill(isPrime, isPrime + MAX_SIZE, true);
p = 0;
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= MAX_SIZE; i++) {
if (isPrime[i]) {
prime[p++] = i;
} else
continue;
for (int j = 2 * i; j <= MAX_SIZE; j += i) {
isPrime[j] = false;
}
}
int a, d, n;
while (cin >> a >> d >> n && !(a == 0 && d == 0 && n == 0)) {
int cnt = 0;
for (int i = 0;; i++) {
int num = a + i * d;
if (isPrime[num]) {
cnt++;
}
if (cnt == n) {
cout << num << endl;
break;
}
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_SIZE = 1000000;
int prime[MAX_SIZE];
bool isPrime[MAX_SIZE];
int p;
int main() {
fill(isPrime, isPrime + MAX_SIZE, true);
p = 0;
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= MAX_SIZE; i++) {
if (isPrime[i]) {
prime[p++] = i;
} else
continue;
for (int j = 2 * i; j <= MAX_SIZE; j += i) {
isPrime[j] = false;
}
}
int a, d, n;
while (cin >> a >> d >> n && !(a == 0 && d == 0 && n == 0)) {
int cnt = 0;
for (int i = 0;; i++) {
int num = a + i * d;
if (isPrime[num]) {
cnt++;
}
if (cnt == n) {
cout << num << endl;
break;
}
}
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
| 1
| 220
|
#include <cstring>
#include <iostream>
using namespace std;
bool t[1000000];
int main() {
memset(t, true, sizeof(t));
t[0] = false;
t[1] = false;
for (int i = 2; i < 1000000; i += 2) {
t[i] = false;
}
for (int i = 3; i * 2 < 1000000; i += 2) {
if (!t[i])
continue;
for (int j = i * 2; j < 1000000; j += i) {
t[j] = false;
}
}
for (;;) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
for (;;) {
if (t[a])
n--;
if (n == 0) {
cout << a << endl;
break;
}
a += d;
}
}
return 0;
}
|
#include <cstring>
#include <iostream>
using namespace std;
bool t[1000000];
int main() {
memset(t, true, sizeof(t));
t[0] = false;
t[1] = false;
for (int i = 4; i < 1000000; i += 2) {
t[i] = false;
}
for (int i = 3; i * 2 < 1000000; i += 2) {
if (!t[i])
continue;
for (int j = i * 2; j < 1000000; j += i) {
t[j] = false;
}
}
for (;;) {
int a, d, n;
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)
break;
for (;;) {
if (t[a])
n--;
if (n == 0) {
cout << a << endl;
break;
}
a += d;
}
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 203
|
import static java.util.Arrays.sort;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n != 0) {
int[] score = new int[n];
for (int i = 0; i < n; i++)
score[i] = sc.nextInt();
sort(score);
int ave = 0;
for (int i = 1; i < score.length - 1; i++)
ave += score[i];
ave /= n;
System.out.println(ave);
n = sc.nextInt();
}
sc.close();
}
}
|
import static java.util.Arrays.sort;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n != 0) {
int[] score = new int[n];
for (int i = 0; i < n; i++)
score[i] = sc.nextInt();
sort(score);
int ave = 0;
for (int i = 1; i < score.length - 1; i++)
ave += score[i];
ave /= n - 2;
System.out.println(ave);
n = sc.nextInt();
}
sc.close();
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 499]]
| 3
| 160
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] array = new int[20];
int c = 0;
for (int i = 0;; i++) {
int n = sc.nextInt();
int[] array2 = new int[n];
if (n == 0) {
break;
}
int min = 1001;
int max = -1;
int cmin = 0, cmax = 0;
int S = 0;
for (int j = 0; j <= n - 1; j++) {
array2[j] = sc.nextInt();
if (array2[j] < min) {
cmin = j;
min = array2[j];
}
if (array2[j] > max) {
cmax = j;
max = array2[j];
}
}
for (int j = 0; j <= n - 1; j++) {
if ((j == cmin) || (j == cmax)) {
continue;
} else {
S += array2[j];
}
}
array[i] = (int)S / n;
S = 0;
c++;
}
for (int i = 0; i < c; i++) {
System.out.println(array[i]);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] array = new int[20];
int c = 0;
for (int i = 0;; i++) {
int n = sc.nextInt();
int[] array2 = new int[n];
if (n == 0) {
break;
}
int min = 1001;
int max = -1;
int cmin = 0, cmax = 0;
int S = 0;
for (int j = 0; j <= n - 1; j++) {
array2[j] = sc.nextInt();
if (array2[j] < min) {
cmin = j;
min = array2[j];
}
if (array2[j] > max) {
cmax = j;
max = array2[j];
}
}
for (int j = 0; j <= n - 1; j++) {
if ((j == cmin) || (j == cmax)) {
continue;
} else {
S += array2[j];
}
}
array[i] = (int)S / (n - 2);
S = 0;
c++;
}
for (int i = 0; i < c; i++) {
System.out.println(array[i]);
}
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 499], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 3
| 285
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i;
int n, max = 0, min = 1000, sum = 0, ave;
while (true) {
n = sc.nextInt();
if (n == 0) {
break;
}
max = 0;
min = 1000;
sum = 0;
for (i = 0; i < n; i++) {
int p = sc.nextInt();
if (p > max) {
max = p;
} else if (p < min) {
min = p;
}
sum += p;
}
sum -= max;
sum -= min;
ave = sum / (n - 2);
System.out.println(ave + "");
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i;
int n, max = 0, min = 1000, sum = 0, ave;
while (true) {
n = sc.nextInt();
if (n == 0) {
break;
}
max = 0;
min = 1000;
sum = 0;
for (i = 0; i < n; i++) {
int p = sc.nextInt();
if (p > max) {
max = p;
}
if (p < min) {
min = p;
}
sum += p;
}
sum -= max;
sum -= min;
ave = sum / (n - 2);
System.out.println(ave + "");
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 3
| 174
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n;
while ((n = in.nextInt()) != 0) {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
int point = 0;
for (int i = 0; i < n; i++) {
int judge = in.nextInt();
max = Math.max(max, judge);
min = Math.min(min, judge);
point += judge;
}
point -= max + min;
System.out.println(point / n);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n;
while ((n = in.nextInt()) != 0) {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
int point = 0;
for (int i = 0; i < n; i++) {
int judge = in.nextInt();
max = Math.max(max, judge);
min = Math.min(min, judge);
point += judge;
}
point -= max + min;
System.out.println(point / (n - 2));
}
}
}
|
[["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 12, 499], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 25]]
| 3
| 141
|
#include <stdio.h>
int main() {
int i, j, n[i], s[i], t, a, b, r[i];
i = 0;
while (1) {
scanf("%d", &n[i]);
if (n[i] == 0)
break;
t = 0;
a = 0;
b = 1000;
for (j = 0; j < n[i]; j++) {
scanf("%d", &s[j]);
t += s[j];
if (a < s[j]) {
a = s[j];
}
if (b > s[j]) {
b = s[j];
}
}
r[i] = t - a - b;
i++;
}
for (j = 0; j < i; j++) {
printf("%d\n", (r[j] / (n[j] - 2)));
}
return 0;
}
|
#include <stdio.h>
int main() {
int i, j, n[21], s[100], t, a, b, r[100];
i = 0;
while (1) {
scanf("%d", &n[i]);
if (n[i] == 0)
break;
t = 0;
a = 0;
b = 1000;
for (j = 0; j < n[i]; j++) {
scanf("%d", &s[j]);
t += s[j];
if (a < s[j]) {
a = s[j];
}
if (b > s[j]) {
b = s[j];
}
}
r[i] = t - a - b;
i++;
}
for (j = 0; j < i; j++) {
printf("%d\n", (r[j] / (n[j] - 2)));
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
| 0
| 210
|
#include <stdio.h>
int main(void) {
int h, max, min, t = 0, ave, i, sc;
while (scanf("%d", &h), h != 0) {
for (i = 1; i <= h; i++) {
scanf("%d", &sc);
t = t + sc;
if (i == 1) {
max = sc;
min = sc;
} else if (max < sc) {
max = sc;
} else if (min > sc) {
min = sc;
}
}
t = t - min - max;
h = h - 2;
ave = t / h;
printf("%d\n", ave);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int h, max, min, t = 0, ave, i, sc;
while (scanf("%d", &h), h != 0) {
t = 0;
for (i = 1; i <= h; i++) {
scanf("%d", &sc);
t = t + sc;
if (i == 1) {
max = sc;
min = sc;
} else if (max < sc) {
max = sc;
} else if (min > sc) {
min = sc;
}
}
t = t - min - max;
h = h - 2;
ave = t / h;
printf("%d\n", ave);
}
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
| 150
|
#include <stdio.h>
int main(void) {
int n, sum, ave, max, min;
int num;
int i;
scanf("%d", &n);
while (n != 0) {
sum = 0;
ave = 0;
min = 1001;
max = -1;
for (i = 0; i < n; i++) {
scanf("%d", &num);
sum += num;
if (max <= num) {
max = num;
}
if (min >= num) {
min = num;
}
}
sum = sum - max - min;
ave = sum / n;
printf("%d\n", ave);
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, sum, ave, max, min;
int num;
int i;
scanf("%d", &n);
while (n != 0) {
sum = 0;
ave = 0;
min = 1001;
max = -1;
for (i = 0; i < n; i++) {
scanf("%d", &num);
sum += num;
if (max <= num) {
max = num;
}
if (min >= num) {
min = num;
}
}
sum = sum - max - min;
ave = sum / (n - 2);
printf("%d\n", ave);
scanf("%d", &n);
}
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 0
| 150
|
#include <stdio.h>
int sumSB(int n, int s[]) {
int i, re, min = s[0], max = s[0];
for (i = 0; i < n; i++) {
if (min > s[i]) {
min = s[i];
}
else if (max < s[i]) {
max = s[i];
}
}
return (min + max);
}
int main(void) {
int n, i, sum = 0, score[128], ave;
while (1) {
sum = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &score[i]);
sum += score[i];
}
sum -= sumSB(n, score);
ave = sum / (n - 2);
printf("%d", ave);
}
return 0;
}
|
#include <stdio.h>
int sumSB(int n, int s[]) {
int i, re, min = s[0], max = s[0];
for (i = 0; i < n; i++) {
if (min > s[i]) {
min = s[i];
}
else if (max < s[i]) {
max = s[i];
}
}
return (min + max);
}
int main(void) {
int n, i, sum = 0, score[128], ave;
while (1) {
sum = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &score[i]);
sum += score[i];
}
sum -= sumSB(n, score);
ave = sum / (n - 2);
printf("%d\n", ave);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 210
|
#include <stdio.h>
int main() {
int n;
int i;
int max, min, sum;
int score[101];
while (1) {
scanf("%d", &n);
if (n == 0)
break;
sum = 0;
for (i = 0; i < n; i++) {
scanf("%d", &score[i]);
sum += score[i];
if (i == 0) {
max = score[i];
min = score[i];
}
if (score[i] > max)
max = score[i];
if (score[i] < min)
min = score[i];
}
printf("%d\n", sum - max - min / n - 2);
}
return 0;
}
|
#include <stdio.h>
int main() {
int n;
int i;
int max, min, sum;
int score[101];
while (1) {
scanf("%d", &n);
if (n == 0)
break;
sum = 0;
for (i = 0; i < n; i++) {
scanf("%d", &score[i]);
sum += score[i];
if (i == 0) {
max = score[i];
min = score[i];
}
if (score[i] > max)
max = score[i];
if (score[i] < min)
min = score[i];
}
printf("%d\n", (sum - max - min) / (n - 2));
}
return 0;
}
|
[["+", 0, 2, 3, 4, 0, 16, 31, 23, 0, 24], ["+", 0, 2, 3, 4, 0, 16, 31, 23, 0, 25], ["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
| 0
| 165
|
#include <stdio.h>
int getfinalscore(int, int scores[]);
int main(void) {
int i = 0, j = 0, k = 0;
int n[20];
int s[20][100];
int finalscore[20];
for (i = 0;; i++) {
scanf("%d", &n[i]);
if (n[i] == 0)
break;
for (j = 0; j < n[i]; j++) {
scanf("%d", &s[i][j]);
}
}
/*i?????????????????§???performance?????°+1?????????*/
/*j??????????????????*/
for (k = 0; k < i; k++) {
finalscore[k] = getfinalscore(n[k], s[k]);
printf("%d\n", finalscore[k]);
}
return 0;
}
int getfinalscore(int judges, int scores[]) {
int max = 0, min = 1000, sum = 0, average, m;
for (m = 0; m < judges; m++) { /*m??????????????????*/
sum += scores[m];
if (scores[m] > max) {
max = scores[m];
} else if (scores[m] < min) {
min = scores[m];
}
}
average = (sum - max - min) / (judges - 2);
return average;
}
|
#include <stdio.h>
int getfinalscore(int, int scores[]);
int main(void) {
int i = 0, j = 0, k = 0;
int n[20];
int s[20][100];
int finalscore[20];
for (i = 0;; i++) {
scanf("%d", &n[i]);
if (n[i] == 0)
break;
for (j = 0; j < n[i]; j++) {
scanf("%d", &s[i][j]);
}
}
/*i?????????????????§???performance?????°?????????*/
/*j??????????????????*/
for (k = 0; k < i; k++) {
finalscore[k] = getfinalscore(n[k], s[k]);
printf("%d\n", finalscore[k]);
}
return 0;
}
int getfinalscore(int judges, int scores[]) {
int max = 0, min = 1000, sum = 0, average, m;
for (m = 0; m < judges; m++) { /*m??????????????????*/
sum += scores[m];
if (scores[m] > max) {
max = scores[m];
}
if (scores[m] < min) {
min = scores[m];
}
}
average = (sum - max - min) / (judges - 2);
return average;
}
|
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 0
| 284
|
#include <stdio.h>
#define S_MAX 1000
int main(void) {
int sum, min, max, n, t, i;
while (scanf("%d", &n), n != 0) {
sum = min = 0, max = S_MAX;
for (i = 0; i < n; i++) {
scanf("%d", &t);
if (min > t)
min = t;
if (max < t)
max = t;
sum += t;
}
printf("%d\n", (sum - min - max) / (n - 2));
}
return 0;
}
|
#include <stdio.h>
#define S_MAX 1000
int main(void) {
int sum, min, max, n, t, i;
while (scanf("%d", &n), n != 0) {
sum = max = 0, min = S_MAX;
for (i = 0; i < n; i++) {
scanf("%d", &t);
if (min > t)
min = t;
if (max < t)
max = t;
sum += t;
}
printf("%d\n", (sum - min - max) / (n - 2));
}
return 0;
}
|
[["-", 0, 1, 0, 34, 31, 11, 12, 11, 31, 22], ["+", 0, 1, 0, 34, 31, 11, 12, 11, 31, 22], ["-", 8, 9, 0, 1, 0, 34, 12, 11, 31, 22], ["+", 8, 9, 0, 1, 0, 34, 12, 11, 31, 22]]
| 0
| 127
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n) {
vector<int> score(n, 0);
for (int i = 0; i < n; i++)
cin >> score[i];
sort(score.begin(), score.end());
int total = 0;
for (int i = 1; i < n - 1; i++)
total += score[i];
cout << total / (n - 2) << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n != 0) {
vector<int> score(n, 0);
for (int i = 0; i < n; i++)
cin >> score[i];
sort(score.begin(), score.end());
int total = 0;
for (int i = 1; i < n - 1; i++)
total += score[i];
cout << total / (n - 2) << endl;
}
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 79], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 13]]
| 1
| 114
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
void mainmain() {
int n;
while (cin >> n, n) {
vint v(n);
rep(i, n) cin >> v[i];
sort(ALL(v));
ll sum = 0;
reep(i, 1, n - 1) { sum += v[i]; }
cout << sum / n - 2 << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
mainmain();
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
void mainmain() {
int n;
while (cin >> n, n) {
vint v(n);
rep(i, n) cin >> v[i];
sort(ALL(v));
ll sum = 0;
reep(i, 1, n - 1) { sum += v[i]; }
// cout<<sum<<endl;
cout << sum / (n - 2) << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
mainmain();
}
|
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
| 1
| 444
|
#include <algorithm>
#include <iostream>
#define rep(i, a) for (int i = 0; i < (a); ++i)
int n;
int main() {
while (std::cin >> n, n) {
int ma = 0, mi = 1001, S = 0;
rep(i, n) {
int a;
std::cin >> a;
ma = std::max(ma, a);
mi = std::min(mi, a);
S += a;
}
std::cout << (S - ma - mi) / n << std::endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#define rep(i, a) for (int i = 0; i < (a); ++i)
int n;
int main() {
while (std::cin >> n, n) {
int ma = 0, mi = 1001, S = 0;
rep(i, n) {
int a;
std::cin >> a;
ma = std::max(ma, a);
mi = std::min(mi, a);
S += a;
}
std::cout << (S - ma - mi) / (n - 2) << std::endl;
}
return 0;
}
|
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 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
| 110
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8 fixed << setprecision(8)
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
using namespace std;
int main(void) {
for (;;) {
int n;
cin >> n;
if (!n)
return 0;
int sum = 0, M = 0, m = 0;
REP(i, n) {
int tmp;
cin >> tmp;
sum += tmp;
if (M < tmp)
M = tmp;
if (m > tmp)
m = tmp;
}
cout << (sum - M - m) / (n - 2) << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8 fixed << setprecision(8)
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
using namespace std;
int main(void) {
for (;;) {
int n;
cin >> n;
if (!n)
return 0;
int sum = 0, M = 0, m = 10000;
REP(i, n) {
int tmp;
cin >> tmp;
sum += tmp;
if (M < tmp)
M = tmp;
if (m > tmp)
m = tmp;
}
cout << (sum - M - m) / (n - 2) << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 250
|
#include <iostream>
using namespace std;
int main() {
int a[2020];
int x, i = 0;
while (cin >> x) {
a[i++] = x;
}
void saiten(int *a, int b);
saiten(a, 0);
}
void saiten(int *a, int j) {
int max = 0, min = 0, ave = 0;
if (a[j] != 0) {
for (int k = j + 1; k <= j + a[j]; k++) {
if (max < a[k])
max = a[k];
if (min > a[k])
min = a[k];
ave += a[k];
}
ave = (ave - max - min) / (a[j] - 2);
cout << ave << endl;
saiten(a, j + a[j] + 1);
}
}
|
#include <iostream>
using namespace std;
int main() {
int a[2020];
int x, i = 0;
while (cin >> x) {
a[i++] = x;
}
void saiten(int *a, int b);
saiten(a, 0);
}
void saiten(int *a, int j) {
int max = 0, min = 1000, ave = 0;
if (a[j] != 0) {
for (int k = j + 1; k <= j + a[j]; k++) {
if (max < a[k])
max = a[k];
if (min > a[k])
min = a[k];
ave += a[k];
}
ave = (ave - max - min) / (a[j] - 2);
cout << ave << endl;
saiten(a, j + a[j] + 1);
}
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 196
|
#include <cstdio>
using namespace std;
int main() {
int min, max, sum, n, score;
while (1) {
scanf("%d", &n);
if (!n)
break;
max = 0;
min = 10000;
sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &score);
if (max < score)
max = score;
if (min > score)
min = score;
sum += score;
}
printf("%d\n", (score - max - min) / (n - 2));
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main() {
int min, max, sum, n, score;
while (1) {
scanf("%d", &n);
if (!n)
break;
max = 0;
min = 10000;
sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &score);
if (max < score)
max = score;
if (min > score)
min = score;
sum += score;
}
printf("%d\n", (sum - max - min) / (n - 2));
}
return 0;
}
|
[["-", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22]]
| 1
| 133
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int par[123];
int find(int x) { return (par[x] == x) ? x : par[x] = find(par[x]); }
void unite(int a, int b) { par[find(a)] = find(b); }
int ex[123][1234], ey[123][1234];
int evx[123][1234], evy[123][1234];
double sqr(double x) { return x * x; }
int main() {
for (int N, T, R; cin >> N >> T >> R, N | T | R;) {
char nicknames[123][12];
vector<int> t[123], x[123], y[123], vx[123], vy[123];
vector<double> ev;
for (int i = 0; i < N; i++) {
cin >> nicknames[i];
for (int j = 0;; j++) {
int ti, xi, yi;
cin >> ti >> xi >> yi;
ev.push_back(ti);
t[i].push_back(ti);
int cx, cy;
if (j) {
vx[i].push_back(xi);
vy[i].push_back(yi);
for (int k = t[i][j - 1] + 1; k <= ti; k++) {
ey[i][k] = ey[i][k - 1] + yi;
ex[i][k] = ex[i][k - 1] + xi;
evy[i][k - 1] = yi;
evx[i][k - 1] = xi;
}
cx = ey[i][ti];
cy = ex[i][ti];
} else {
cx = xi;
cy = yi;
ex[i][0] = cx;
ey[i][0] = cy;
}
x[i].push_back(cx);
y[i].push_back(cy);
if (ti == T)
break;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < vx[i].size(); j++) {
int y1 = y[i][j] - t[i][j] * vy[i][j];
int x1 = x[i][j] - t[i][j] * vx[i][j];
for (int k = 0; k < i; k++) {
for (int l = 0; l < vx[k].size(); l++) {
int y2 = y[k][l] - t[k][l] * vy[k][l];
int x2 = x[k][l] - t[k][l] * vx[k][l];
long long X = x1 - x2;
long long Y = y1 - y2;
long long VX = vx[i][j] - vx[k][l];
long long VY = vy[i][j] - vy[k][l];
long long a = VX * VX + VY * VY;
long long b = X * VX + Y * VY;
long long c = X * X + Y * Y - R * R;
long long inr = b * b - a * c;
if (inr >= 0 && a) {
ev.push_back((-b - sqrt(inr)) / a);
ev.push_back((-b + sqrt(inr)) / a);
}
}
}
}
}
sort(begin(ev), end(ev));
bool has[123] = {true};
for (int k = 0; k < ev.size() - 1; k++) {
double e = (ev[k] + ev[k + 1]) / 2;
if (e < 0 || T < e)
continue;
iota(begin(par), end(par), 0);
int g = e;
double f = e - g;
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
if (sqr(ey[i][g] + evy[i][g] * f - (ey[j][g] + evy[j][g] * f)) +
sqr(ex[i][g] + evx[i][g] * f - (ex[j][g] + evx[j][g] * f)) <=
R * R) {
unite(i, j);
}
}
}
for (int i = 0; i < N; i++) {
has[find(i)] |= has[i];
}
for (int i = 0; i < N; i++) {
has[i] |= has[find(i)];
}
}
vector<string> ans;
for (int i = 0; i < N; i++) {
if (has[i]) {
ans.push_back(nicknames[i]);
}
}
sort(begin(ans), end(ans));
for (auto e : ans) {
cout << e << endl;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int par[123];
int find(int x) { return (par[x] == x) ? x : par[x] = find(par[x]); }
void unite(int a, int b) { par[find(a)] = find(b); }
int ex[123][1234], ey[123][1234];
int evx[123][1234], evy[123][1234];
double sqr(double x) { return x * x; }
int main() {
for (int N, T, R; cin >> N >> T >> R, N | T | R;) {
char nicknames[123][12];
vector<int> t[123], x[123], y[123], vx[123], vy[123];
vector<double> ev;
for (int i = 0; i < N; i++) {
cin >> nicknames[i];
for (int j = 0;; j++) {
int ti, xi, yi;
cin >> ti >> xi >> yi;
ev.push_back(ti);
t[i].push_back(ti);
int cx, cy;
if (j) {
vx[i].push_back(xi);
vy[i].push_back(yi);
for (int k = t[i][j - 1] + 1; k <= ti; k++) {
ey[i][k] = ey[i][k - 1] + yi;
ex[i][k] = ex[i][k - 1] + xi;
evy[i][k - 1] = yi;
evx[i][k - 1] = xi;
}
cy = ey[i][ti];
cx = ex[i][ti];
} else {
cx = xi;
cy = yi;
ex[i][0] = cx;
ey[i][0] = cy;
}
x[i].push_back(cx);
y[i].push_back(cy);
if (ti == T)
break;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < vx[i].size(); j++) {
int y1 = y[i][j] - t[i][j] * vy[i][j];
int x1 = x[i][j] - t[i][j] * vx[i][j];
for (int k = 0; k < i; k++) {
for (int l = 0; l < vx[k].size(); l++) {
int y2 = y[k][l] - t[k][l] * vy[k][l];
int x2 = x[k][l] - t[k][l] * vx[k][l];
long long X = x1 - x2;
long long Y = y1 - y2;
long long VX = vx[i][j] - vx[k][l];
long long VY = vy[i][j] - vy[k][l];
long long a = VX * VX + VY * VY;
long long b = X * VX + Y * VY;
long long c = X * X + Y * Y - R * R;
long long inr = b * b - a * c;
if (inr >= 0 && a) {
ev.push_back((-b - sqrt(inr)) / a);
ev.push_back((-b + sqrt(inr)) / a);
}
}
}
}
}
sort(begin(ev), end(ev));
bool has[123] = {true};
for (int k = 0; k < ev.size() - 1; k++) {
double e = (ev[k] + ev[k + 1]) / 2;
// cerr<<e<<endl;
if (e < 0 || T < e)
continue;
iota(begin(par), end(par), 0);
int g = e;
double f = e - g;
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
if (sqr(ey[i][g] + evy[i][g] * f - (ey[j][g] + evy[j][g] * f)) +
sqr(ex[i][g] + evx[i][g] * f - (ex[j][g] + evx[j][g] * f)) <=
R * R) {
unite(i, j);
}
}
}
for (int i = 0; i < N; i++) {
has[find(i)] |= has[i];
}
for (int i = 0; i < N; i++) {
has[i] |= has[find(i)];
}
}
vector<string> ans;
for (int i = 0; i < N; i++) {
if (has[i]) {
ans.push_back(nicknames[i]);
}
}
sort(begin(ans), end(ans));
for (auto e : ans) {
cout << e << endl;
}
}
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22]]
| 1
| 1,167
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define bit(i) static_cast<bitset<8>>(i)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
struct edge {
int to, cost;
};
void begin() {
cin.tie(0);
ios::sync_with_stdio(false);
};
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
};
int lcm(int m, int n) {
if ((0 == m) || (0 == n)) {
return 0;
}
return ((m / gcd(m, n)) * n);
};
unsigned long long comb(long n, long m) {
unsigned long long c = 1;
m = (n - m < m ? n - m : m);
for (long ns = n - m + 1, ms = 1; ms <= m; ns++, ms++) {
c *= ns;
c /= ms;
}
return c;
};
void cp(int a1[], int a2[], int l) { FOR(i, l) a2[i] = a1[i]; };
double sq(double d) { return d * d; };
int sq(int i) { return i * i; };
double sqdist(int x1, int y1, int x2, int y2) {
double dx = x1 - x2, dy = y1 - y2;
return dx * dx + dy * dy;
};
// ワーシャルフロイド法
void warshallFloyd(int d[100][100], int n) {
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (d[i][k] != -1 && d[k][j] != -1) {
if (d[i][j] == -1) {
d[i][j] = d[i][k] + d[k][j];
} else {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
};
// d:隣接行列 n:グラフのサイズ s:始点 dist:始点からの距離が入る配列
void dijkstra(int d[1000][1000], int n, int s, int dist[1000]) {
FOR(i, n) dist[i] = -1;
dist[s] = 0;
priority_queue<PII, vector<PII>, greater<PII>> q;
q.push(PII(0, s));
while (!q.empty()) {
PII p = q.top();
q.pop();
int i = p.second;
if (dist[i] < p.first)
continue;
for (int j = 0; j < n; j++) {
if (d[i][j] == -1)
continue;
if (dist[j] == -1) {
dist[j] = dist[i] + d[i][j];
q.push(PII(dist[j], j));
} else if (dist[j] > dist[i] + d[i][j]) {
dist[j] = dist[i] + d[i][j];
q.push(PII(dist[j], j));
}
}
}
};
// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
// 並行な場合
int m = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3);
if (m == 0)
return false;
// 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
double r = (double)((y4 - y3) * (x3 - x1) - (x4 - x3) * (y3 - y1)) / m;
double s = (double)((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / m;
return (0 < r && r <= 1 && 0 < s && s <= 1);
};
// 外積の計算 AB CD の内積を求める
int crossProdct(int ax, int ay, int bx, int by, int cx, int cy, int dx,
int dy) {
int abx = bx - ax;
int aby = by - ay;
int cdx = dx - cx;
int cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double crossProdct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double innerProduct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdx + aby * cdy;
};
// 三角形の内部判定 ABCの中にPがあるか判定
bool inTriangle(int ax, int ay, int bx, int by, int cx, int cy, int px,
int py) {
int c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
int c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
int c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
bool inTriangle(double ax, double ay, double bx, double by, double cx,
double cy, double px, double py) {
double c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
double c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
double c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
// 三角形の外心
void circumcenter(double ax, double ay, double bx, double by, double cx,
double cy, double res[3]) {
// AB AC を求める
double abx = bx - ax;
double aby = by - ay;
double acx = cx - ax;
double acy = cy - ay;
double m =
abx * acy - acx * aby; // 分母 m = 0 となるのは3点が一直線になるとき
double s = (abx * acx + aby * acy - sq(acx) - sq(acy)) / m; // 媒介変数s
res[0] = abx / 2 + s * aby / 2;
res[1] = aby / 2 - s * abx / 2;
// cout << res[0] << " " << res[1] << endl;
res[2] = sqrt(sqdist(0, 0, res[0], res[1]));
res[0] += ax;
res[1] += ay;
};
/**
* start
* @author yoshikyoto
*/
int w, h;
string tile[20];
int dist[20][20];
int g[11][11];
int sx[11], sy[11];
int dp[1024][11];
int vy[4] = {-1, 1, 0, 0}, vx[4] = {0, 0, -1, 1};
int dcount = 1;
int p[11];
void dfs(int hist, int curr) {
for (int next = 1; next < dcount; next++) {
if (hist & p[next])
continue; // 既に訪れている
// 訪れていない
int next_hist = hist | p[next];
int cost = dp[hist][curr] + g[curr][next];
if (cost < dp[next_hist][next] || dp[next_hist][next] == -1) {
dp[next_hist][next] = cost;
dfs(next_hist, next);
}
}
};
void solve() {
FOR(i, h) cin >> tile[i];
// 配列をなめて汚れたタイルの位置を獲得、汚れに番号をつける
FOR(i, h) FOR(j, w) {
if (tile[i][j] == '*') {
sy[dcount] = i;
sx[dcount] = j;
tile[i][j] = (char)('0' + dcount); // 汚れに番号を付ける
dcount++;
} else if (tile[i][j] == 'o') {
// 自分の位置
sy[0] = i;
sx[0] = j;
tile[i][j] = '0';
}
}
// グラフの初期化
FOR(i, dcount) FOR(j, dcount) g[i][j] = -1;
// FOR(i, h) cout << tile[i] << endl;
// まずはbfsしてグラフを生成する
FOR(i, dcount) {
FOR(k, h) FOR(l, w) dist[k][l] = -1;
dist[sy[i]][sx[i]] = 0;
QI yq, xq;
yq.push(sy[i]);
xq.push(sx[i]);
int checked = 1;
while (checked < dcount && !yq.empty()) {
int y = yq.front();
yq.pop();
int x = xq.front();
xq.pop();
// 上下左右を見る
FOR(j, 4) {
int ny = y + vy[j], nx = x + vx[j]; // nexty, nextx;
if (dist[ny][nx] > -1)
continue; // 既に訪れた場合
if (ny < 0 || ny > h - 1 || nx < 0 || nx > w - 1)
continue; // 部屋を出てしまう場合
int dnum = (int)tile[ny][nx] - '0';
if (tile[ny][nx] != 'x') {
// 障害物でない場合
yq.push(ny);
xq.push(nx);
dist[ny][nx] = dist[y][x] + 1;
// グラフに追加したい場
if (0 <= dnum && dnum < dcount) {
g[i][dnum] = dist[ny][nx];
checked++;
}
}
}
}
}
/*
FOR(i, dcount){
FOR(j, dcount){
cout << g[i][j] << " ";
}
cout << endl;
}
*/
// 行けないところがあったらダメ
for (int i = 1; i < dcount; i++)
if (g[0][i] == -1) {
cout << -1 << endl;
return;
}
// メモ化再帰
FOR(i, 1024) FOR(j, 11) dp[i][j] = -1;
FOR(i, dcount) p[i] = (int)pow(2, i);
dp[1][0] = 0;
dfs(1, 0);
int final = 1;
for (int i = 1; i < dcount; i++)
final += p[i];
int ans = dp[final][1];
for (int i = 2; i < dcount; i++) {
ans = min(ans, dp[final][i]);
}
cout << ans << endl;
};
int main(int argc, const char *argv[]) {
begin();
while (true) {
cin >> w >> h;
if (w == 0 && h == 0)
break;
solve();
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define bit(i) static_cast<bitset<8>>(i)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
struct edge {
int to, cost;
};
void begin() {
cin.tie(0);
ios::sync_with_stdio(false);
};
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
};
int lcm(int m, int n) {
if ((0 == m) || (0 == n)) {
return 0;
}
return ((m / gcd(m, n)) * n);
};
unsigned long long comb(long n, long m) {
unsigned long long c = 1;
m = (n - m < m ? n - m : m);
for (long ns = n - m + 1, ms = 1; ms <= m; ns++, ms++) {
c *= ns;
c /= ms;
}
return c;
};
void cp(int a1[], int a2[], int l) { FOR(i, l) a2[i] = a1[i]; };
double sq(double d) { return d * d; };
int sq(int i) { return i * i; };
double sqdist(int x1, int y1, int x2, int y2) {
double dx = x1 - x2, dy = y1 - y2;
return dx * dx + dy * dy;
};
// ワーシャルフロイド法
void warshallFloyd(int d[100][100], int n) {
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (d[i][k] != -1 && d[k][j] != -1) {
if (d[i][j] == -1) {
d[i][j] = d[i][k] + d[k][j];
} else {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
};
// d:隣接行列 n:グラフのサイズ s:始点 dist:始点からの距離が入る配列
void dijkstra(int d[1000][1000], int n, int s, int dist[1000]) {
FOR(i, n) dist[i] = -1;
dist[s] = 0;
priority_queue<PII, vector<PII>, greater<PII>> q;
q.push(PII(0, s));
while (!q.empty()) {
PII p = q.top();
q.pop();
int i = p.second;
if (dist[i] < p.first)
continue;
for (int j = 0; j < n; j++) {
if (d[i][j] == -1)
continue;
if (dist[j] == -1) {
dist[j] = dist[i] + d[i][j];
q.push(PII(dist[j], j));
} else if (dist[j] > dist[i] + d[i][j]) {
dist[j] = dist[i] + d[i][j];
q.push(PII(dist[j], j));
}
}
}
};
// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
// 並行な場合
int m = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3);
if (m == 0)
return false;
// 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
double r = (double)((y4 - y3) * (x3 - x1) - (x4 - x3) * (y3 - y1)) / m;
double s = (double)((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / m;
return (0 < r && r <= 1 && 0 < s && s <= 1);
};
// 外積の計算 AB CD の内積を求める
int crossProdct(int ax, int ay, int bx, int by, int cx, int cy, int dx,
int dy) {
int abx = bx - ax;
int aby = by - ay;
int cdx = dx - cx;
int cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double crossProdct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double innerProduct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdx + aby * cdy;
};
// 三角形の内部判定 ABCの中にPがあるか判定
bool inTriangle(int ax, int ay, int bx, int by, int cx, int cy, int px,
int py) {
int c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
int c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
int c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
bool inTriangle(double ax, double ay, double bx, double by, double cx,
double cy, double px, double py) {
double c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
double c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
double c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
// 三角形の外心
void circumcenter(double ax, double ay, double bx, double by, double cx,
double cy, double res[3]) {
// AB AC を求める
double abx = bx - ax;
double aby = by - ay;
double acx = cx - ax;
double acy = cy - ay;
double m =
abx * acy - acx * aby; // 分母 m = 0 となるのは3点が一直線になるとき
double s = (abx * acx + aby * acy - sq(acx) - sq(acy)) / m; // 媒介変数s
res[0] = abx / 2 + s * aby / 2;
res[1] = aby / 2 - s * abx / 2;
// cout << res[0] << " " << res[1] << endl;
res[2] = sqrt(sqdist(0, 0, res[0], res[1]));
res[0] += ax;
res[1] += ay;
};
/**
* start
* @author yoshikyoto
*/
int w, h;
string tile[20];
int dist[20][20];
int g[11][11];
int sx[11], sy[11];
int dp[1024][11];
int vy[4] = {-1, 1, 0, 0}, vx[4] = {0, 0, -1, 1};
int dcount = 1;
int p[11];
void dfs(int hist, int curr) {
for (int next = 1; next < dcount; next++) {
if (hist & p[next])
continue; // 既に訪れている
// 訪れていない
int next_hist = hist | p[next];
int cost = dp[hist][curr] + g[curr][next];
if (cost < dp[next_hist][next] || dp[next_hist][next] == -1) {
dp[next_hist][next] = cost;
dfs(next_hist, next);
}
}
};
void solve() {
FOR(i, h) cin >> tile[i];
// 配列をなめて汚れたタイルの位置を獲得、汚れに番号をつける
FOR(i, h) FOR(j, w) {
if (tile[i][j] == '*') {
sy[dcount] = i;
sx[dcount] = j;
tile[i][j] = (char)('0' + dcount); // 汚れに番号を付ける
dcount++;
} else if (tile[i][j] == 'o') {
// 自分の位置
sy[0] = i;
sx[0] = j;
tile[i][j] = '0';
}
}
// グラフの初期化
FOR(i, dcount) FOR(j, dcount) g[i][j] = -1;
// FOR(i, h) cout << tile[i] << endl;
// まずはbfsしてグラフを生成する
FOR(i, dcount) {
FOR(k, h) FOR(l, w) dist[k][l] = -1;
dist[sy[i]][sx[i]] = 0;
QI yq, xq;
yq.push(sy[i]);
xq.push(sx[i]);
int checked = 1;
while (checked < dcount && !yq.empty()) {
int y = yq.front();
yq.pop();
int x = xq.front();
xq.pop();
// 上下左右を見る
FOR(j, 4) {
int ny = y + vy[j], nx = x + vx[j]; // nexty, nextx;
if (dist[ny][nx] > -1)
continue; // 既に訪れた場合
if (ny < 0 || ny > h - 1 || nx < 0 || nx > w - 1)
continue; // 部屋を出てしまう場合
int dnum = (int)tile[ny][nx] - '0';
if (tile[ny][nx] != 'x') {
// 障害物でない場合
yq.push(ny);
xq.push(nx);
dist[ny][nx] = dist[y][x] + 1;
// グラフに追加したい場
if (0 <= dnum && dnum < dcount) {
g[i][dnum] = dist[ny][nx];
checked++;
}
}
}
}
}
/*
FOR(i, dcount){
FOR(j, dcount){
cout << g[i][j] << " ";
}
cout << endl;
}
*/
// 行けないところがあったらダメ
for (int i = 1; i < dcount; i++)
if (g[0][i] == -1) {
cout << -1 << endl;
return;
}
// メモ化再帰
FOR(i, 1024) FOR(j, 11) dp[i][j] = -1;
FOR(i, dcount) p[i] = (int)pow(2, i);
dp[1][0] = 0;
dfs(1, 0);
int final = 1;
for (int i = 1; i < dcount; i++)
final += p[i];
int ans = dp[final][1];
for (int i = 2; i < dcount; i++) {
ans = min(ans, dp[final][i]);
}
cout << ans << endl;
};
int main(int argc, const char *argv[]) {
begin();
while (true) {
cin >> w >> h;
if (w == 0 && h == 0)
break;
dcount = 1;
solve();
}
}
|
[["+", 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]]
| 1
| 2,475
|
#include <bits/stdc++.h>
using namespace std;
int w, h;
vector<string> field;
int dist(pair<int, int> a, pair<int, int> b) {
queue<pair<pair<int, int>, int>> bfs;
set<pair<int, int>> already;
bfs.push(make_pair(a, 0));
while (!bfs.empty()) {
pair<int, int> pos;
int cost;
tie(pos, cost) = bfs.front();
bfs.pop();
int y, x;
tie(y, x) = pos;
if (y < 0 || h <= y || x < 0 || w <= h)
continue;
if (field[y][x] == 'x')
continue;
if (!already.insert(pos).second)
continue;
if (pos == b)
return cost;
int dy[4] = {0, 0, -1, 1}, dx[4] = {-1, 1, 0, 0};
for (int i = 0; i < 4; ++i)
bfs.push(make_pair(make_pair(y + dy[i], x + dx[i]), cost + 1));
}
return 1048576;
}
int solve() {
cin >> w >> h;
if (!w && !h)
return 0;
field.resize(h);
for (int i = 0; i < h; ++i)
cin >> field[i];
pair<int, int> robot;
vector<pair<int, int>> dirty;
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j) {
if (field[i][j] == 'o')
robot = make_pair(i, j);
if (field[i][j] == '*')
dirty.push_back(make_pair(i, j));
}
// init bitdp[state][lastpos]
vector<vector<int>> bitdp;
bitdp.assign(1 << dirty.size(), vector<int>());
for (int i = 0; i < (1 << dirty.size()); ++i)
bitdp[i].assign(dirty.size(), 1048576);
for (int i = 0; i < dirty.size(); ++i) {
bitdp[1 << i][i] = dist(robot, dirty[i]);
if (bitdp[1 << i][i] > 8192)
return -1;
}
vector<vector<int>> ecost;
ecost.assign(dirty.size(), vector<int>());
for (int i = 0; i < dirty.size(); ++i)
ecost[i].assign(dirty.size(), 1048576);
for (int i = 0; i < dirty.size(); ++i)
for (int j = 0; j < dirty.size(); ++j)
ecost[i][j] = dist(dirty[i], dirty[j]);
for (int i = 0; i < (1 << dirty.size()); ++i)
for (int j = 0; j < dirty.size(); ++j) {
if (i & (1 << j))
continue;
for (int k = 0; k < dirty.size(); ++k)
if (i & (1 << k))
bitdp[i | (1 << j)][j] =
min(bitdp[i | (1 << j)][j], bitdp[i][k] + ecost[k][j]);
}
int answer = 1048576;
for (int i = 0; i < dirty.size(); ++i)
answer = min(answer, bitdp[(1 << dirty.size()) - 1][i]);
if (answer > 65536)
answer = -1;
return answer;
}
int main() {
for (;;) {
int answer = solve();
if (answer)
cout << answer << endl;
else
break;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int w, h;
vector<string> field;
int dist(pair<int, int> a, pair<int, int> b) {
queue<pair<pair<int, int>, int>> bfs;
set<pair<int, int>> already;
bfs.push(make_pair(a, 0));
while (!bfs.empty()) {
pair<int, int> pos;
int cost;
tie(pos, cost) = bfs.front();
bfs.pop();
int y, x;
tie(y, x) = pos;
if (y < 0 || h <= y || x < 0 || w <= x)
continue;
if (field[y][x] == 'x')
continue;
if (!already.insert(pos).second)
continue;
if (pos == b)
return cost;
int dy[4] = {0, 0, -1, 1}, dx[4] = {-1, 1, 0, 0};
for (int i = 0; i < 4; ++i)
bfs.push(make_pair(make_pair(y + dy[i], x + dx[i]), cost + 1));
}
return 1048576;
}
int solve() {
cin >> w >> h;
if (!w && !h)
return 0;
field.resize(h);
for (int i = 0; i < h; ++i)
cin >> field[i];
pair<int, int> robot;
vector<pair<int, int>> dirty;
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j) {
if (field[i][j] == 'o')
robot = make_pair(i, j);
if (field[i][j] == '*')
dirty.push_back(make_pair(i, j));
}
// init bitdp[state][lastpos]
vector<vector<int>> bitdp;
bitdp.assign(1 << dirty.size(), vector<int>());
for (int i = 0; i < (1 << dirty.size()); ++i)
bitdp[i].assign(dirty.size(), 1048576);
for (int i = 0; i < dirty.size(); ++i) {
bitdp[1 << i][i] = dist(robot, dirty[i]);
if (bitdp[1 << i][i] > 8192)
return -1;
}
vector<vector<int>> ecost;
ecost.assign(dirty.size(), vector<int>());
for (int i = 0; i < dirty.size(); ++i)
ecost[i].assign(dirty.size(), 1048576);
for (int i = 0; i < dirty.size(); ++i)
for (int j = 0; j < dirty.size(); ++j)
ecost[i][j] = dist(dirty[i], dirty[j]);
for (int i = 0; i < (1 << dirty.size()); ++i)
for (int j = 0; j < dirty.size(); ++j) {
if (i & (1 << j))
continue;
for (int k = 0; k < dirty.size(); ++k)
if (i & (1 << k))
bitdp[i | (1 << j)][j] =
min(bitdp[i | (1 << j)][j], bitdp[i][k] + ecost[k][j]);
}
int answer = 1048576;
for (int i = 0; i < dirty.size(); ++i)
answer = min(answer, bitdp[(1 << dirty.size()) - 1][i]);
if (answer > 65536)
answer = -1;
return answer;
}
int main() {
for (;;) {
int answer = solve();
if (answer)
cout << answer << endl;
else
break;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 886
|
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define ll long long int
using namespace std;
const int INF = (1 << 25) - 1;
vector<int> bfs(int s, vector<pair<int, int>> &dirtys, vector<string> &field) {
int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};
int H = field.size(), W = field[0].size();
vector<vector<int>> d(H, vector<int>(W, INF));
pair<int, int> start = dirtys[s];
queue<pair<int, int>> q;
d[start.first][start.second] = 0;
q.push(start);
while (!q.empty()) {
pair<int, int> p = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nh = p.first + dh[i];
int nw = p.second + dw[i];
if (nh < 0 || H <= nh || nw < 0 || W <= nw || field[nh][nw] == 'x' ||
d[nh][nw] != INF)
continue;
d[nh][nw] = d[p.first][p.second] + 1;
q.push(make_pair(nh, nw));
}
}
vector<int> res(dirtys.size());
for (int i = 0; i < dirtys.size(); i++)
res[i] = d[dirtys[i].first][dirtys[i].second];
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int W, H;
while (cin >> W >> H, W | H) {
vector<string> field(H);
for (string &r : field)
cin >> r;
// start???dirty??¨??????
vector<pair<int, int>> dirtys;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (field[i][j] == 'o')
dirtys.push_back(make_pair(i, j));
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (field[i][j] == '*')
dirtys.push_back(make_pair(i, j));
vector<int> order(dirtys.size());
for (int i = 0; i < dirtys.size(); i++)
order[i] = i;
sort(order.begin() + 1, order.end());
vector<vector<int>> table(dirtys.size());
for (int i = 0; i < dirtys.size(); i++)
table[i] = bfs(i, dirtys, field);
int ans = INF;
do {
int tans = 0;
for (int i = 0; i < order.size() - 1; i++)
tans += table[order[i]][order[i + 1]];
ans = min(ans, tans);
} while (next_permutation(order.begin(), order.end()));
cout << (ans == INF ? -1 : ans) << endl;
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define ll long long int
using namespace std;
const int INF = (1 << 25) - 1;
vector<int> bfs(int s, vector<pair<int, int>> &dirtys, vector<string> &field) {
int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};
int H = field.size(), W = field[0].size();
vector<vector<int>> d(H, vector<int>(W, INF));
pair<int, int> start = dirtys[s];
queue<pair<int, int>> q;
d[start.first][start.second] = 0;
q.push(start);
while (!q.empty()) {
pair<int, int> p = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nh = p.first + dh[i];
int nw = p.second + dw[i];
if (nh < 0 || H <= nh || nw < 0 || W <= nw || field[nh][nw] == 'x' ||
d[nh][nw] != INF)
continue;
d[nh][nw] = d[p.first][p.second] + 1;
q.push(make_pair(nh, nw));
}
}
vector<int> res(dirtys.size());
for (int i = 0; i < dirtys.size(); i++)
res[i] = d[dirtys[i].first][dirtys[i].second];
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int W, H;
while (cin >> W >> H, W | H) {
vector<string> field(H);
for (string &r : field)
cin >> r;
// start???dirty??¨??????
vector<pair<int, int>> dirtys;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (field[i][j] == 'o')
dirtys.push_back(make_pair(i, j));
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (field[i][j] == '*')
dirtys.push_back(make_pair(i, j));
vector<int> order(dirtys.size());
for (int i = 0; i < dirtys.size(); i++)
order[i] = i;
sort(order.begin() + 1, order.end());
vector<vector<int>> table(dirtys.size());
for (int i = 0; i < dirtys.size(); i++)
table[i] = bfs(i, dirtys, field);
int ans = INF;
do {
int tans = 0;
for (int i = 0; i < order.size() - 1; i++)
tans += table[order[i]][order[i + 1]];
ans = min(ans, tans);
} while (next_permutation(order.begin() + 1, order.end()));
cout << (ans == INF ? -1 : ans) << endl;
}
return 0;
}
|
[["+", 15, 23, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 15, 23, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 776
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
reader(t);
reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
reader(t);
reader(u);
reader(v);
}
void writer(const int a, char c) {
printf("%d", a);
putchar(c);
}
void writer(const ll a, char c) {
printf("%lld", a);
putchar(c);
}
void writer(const ull a, char c) {
printf("%llu", a);
putchar(c);
}
void writer(const double a, char c) {
printf("%.20lf", a);
putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
printf("%s", a);
putchar(c);
};
void writer(const char a, char c) {
putchar(a);
putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\n'); }
template <class T, class U> void writerLn(T t, U u) {
writer(t, ' ');
writer(u, '\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
writer(t, ' ');
writer(u, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerVec(vector<T> x) {
int n = x.size();
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// #define int ll
bool test = 0;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX 22
struct Node {
int y, x;
};
int w, h;
char c[MAX][MAX];
int dm[MAX][MAX];
vector<Node> nodes;
int start;
bool create_distace_matrix() {
int i, j, k;
int y, x;
int cf[MAX][MAX];
rep(i, nodes.size()) {
rep(y, h) rep(x, w) {
if (c[y][x] == 'x')
cf[y][x] = -2;
else
cf[y][x] = -1;
}
cf[nodes[i].y][nodes[i].x] = 0;
bool changed = true;
int current = 0;
for (; changed; current += 1) {
changed = false;
rep(y, h) rep(x, w) {
if (cf[y][x] == current) {
rep(j, 4) {
int ny = y + dy[j];
int nx = x + dx[j];
if (ny < 0 || h <= ny)
continue;
if (nx < 0 || w <= nx)
continue;
if (cf[ny][nx] == -1)
cf[ny][nx] = current + 1;
changed = true;
}
}
}
}
rep(j, nodes.size()) {
int distance = cf[nodes[j].y][nodes[j].x];
if (distance < 0)
return false;
dm[i][j] = distance;
}
}
return true;
}
bool done[MAX];
int ans;
void rec(int n, int idx, int sum) {
int i;
if (sum >= ans)
return;
if (n == nodes.size()) {
if (sum < ans)
ans = sum;
return;
}
rep(i, nodes.size()) {
if (done[i])
continue;
done[i] = true;
rec(n + 1, i, sum + dm[idx][i]);
done[i] = false;
}
}
signed main(void) {
int i, j, k, l;
while (1) {
cin >> w >> h;
if (w == 0)
return 0;
rep(i, h) reader(c[i]);
nodes.clear();
rep(i, h) rep(j, w) {
if (c[i][j] == 'o')
start = nodes.size();
if (c[i][j] == 'o' || c[i][j] == '*') {
nodes.push_back({i, j});
}
}
if (!create_distace_matrix()) {
cout << -1 << endl;
}
ans = INT_MAX;
done[start] = true;
rec(1, start, 0);
cout << ans << endl;
done[start] = false;
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
reader(t);
reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
reader(t);
reader(u);
reader(v);
}
void writer(const int a, char c) {
printf("%d", a);
putchar(c);
}
void writer(const ll a, char c) {
printf("%lld", a);
putchar(c);
}
void writer(const ull a, char c) {
printf("%llu", a);
putchar(c);
}
void writer(const double a, char c) {
printf("%.20lf", a);
putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
printf("%s", a);
putchar(c);
};
void writer(const char a, char c) {
putchar(a);
putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\n'); }
template <class T, class U> void writerLn(T t, U u) {
writer(t, ' ');
writer(u, '\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
writer(t, ' ');
writer(u, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerVec(vector<T> x) {
int n = x.size();
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// #define int ll
bool test = 0;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX 22
struct Node {
int y, x;
};
int w, h;
char c[MAX][MAX];
int dm[MAX][MAX];
vector<Node> nodes;
int start;
bool create_distace_matrix() {
int i, j, k;
int y, x;
int cf[MAX][MAX];
rep(i, nodes.size()) {
rep(y, h) rep(x, w) {
if (c[y][x] == 'x')
cf[y][x] = -2;
else
cf[y][x] = -1;
}
cf[nodes[i].y][nodes[i].x] = 0;
bool changed = true;
int current = 0;
for (; changed; current += 1) {
changed = false;
rep(y, h) rep(x, w) {
if (cf[y][x] == current) {
rep(j, 4) {
int ny = y + dy[j];
int nx = x + dx[j];
if (ny < 0 || h <= ny)
continue;
if (nx < 0 || w <= nx)
continue;
if (cf[ny][nx] == -1)
cf[ny][nx] = current + 1;
changed = true;
}
}
}
}
rep(j, nodes.size()) {
int distance = cf[nodes[j].y][nodes[j].x];
if (distance < 0)
return false;
dm[i][j] = distance;
}
}
return true;
}
bool done[MAX];
int ans;
void rec(int n, int idx, int sum) {
int i;
if (sum >= ans)
return;
if (n == nodes.size()) {
if (sum < ans)
ans = sum;
return;
}
rep(i, nodes.size()) {
if (done[i])
continue;
done[i] = true;
rec(n + 1, i, sum + dm[idx][i]);
done[i] = false;
}
}
signed main(void) {
int i, j, k, l;
while (1) {
cin >> w >> h;
if (w == 0)
return 0;
rep(i, h) reader(c[i]);
nodes.clear();
rep(i, h) rep(j, w) {
if (c[i][j] == 'o')
start = nodes.size();
if (c[i][j] == 'o' || c[i][j] == '*') {
nodes.push_back({i, j});
}
}
if (!create_distace_matrix()) {
cout << -1 << endl;
continue;
}
ans = INT_MAX;
done[start] = true;
rec(1, start, 0);
cout << ans << endl;
done[start] = false;
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 35]]
| 1
| 1,433
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX 12
#define mk make_pair
#define INF 1 << 28
string s[20];
bool vis[20][20];
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int n, w, h, d[MAX][MAX], c;
int dp[1 << MAX][MAX];
int rec(int s, int v) {
if (dp[s][v] >= 0)
return dp[s][v];
if (s == (1 << n) - 1 && v != 0) {
return dp[s][v] = 0;
}
int res = INF;
for (int u = 0; u < n; u++)
if (!(s >> u & 1))
res = min(res, rec(s | 1 << u, u) + d[v][u]);
return dp[s][v] = res;
}
void bfs(int x2, int y2, int k) {
r(i, 20) r(j, 20) vis[i][j] = 0;
queue<pair<pair<int, int>, int>> q;
vis[x2][y2] = 1;
q.push(mk(mk(x2, y2), 0));
while (!q.empty()) {
pair<pair<int, int>, int> p = q.front();
q.pop();
int p1 = p.first.first, p2 = p.first.second,
p3 = p.second; // cout<<p1<<p2<<p3<<endl;
r(i, 4) {
int x = dx[i] + p1;
int y = dy[i] + p2;
if (x >= 0 && x < w && y >= 0 && y < h)
if (!vis[x][y] && (s[y][x] != '#')) {
if (0 <= s[y][x] && s[y][x] < 12)
d[k][(int)s[y][x]] = p3 + 1;
else if (k != 0 && s[y][x] == 'o')
d[k][0] = p3 + 1;
else
q.push(mk(mk(x, y), p3 + 1));
vis[x][y] = 1;
}
}
}
}
int main() {
while (cin >> w >> h, w) {
c = 1;
int a, b;
vector<pair<int, int>> v;
r(i, h) cin >> s[i];
r(j, w) r(i, h) if (s[i][j] == '*') s[i][j] = c++,
v.push_back(make_pair(j, i));
memset(dp, -1, sizeof(dp));
n = c;
r(i, MAX) r(j, MAX) d[i][j] = INF;
r(j, w) r(i, h) if (s[i][j] == 'o') a = j, b = i;
bfs(a, b, 0);
r(i, c - 1) bfs(v[i].first, v[i].second, i + 1);
// r(i,c){r(j,c){cout<<d[i][j]<<' ';}cout<<endl;}cout<<d[0][1];
int p = rec(1, 0);
if (p == INF)
p = -1;
cout << p << endl;
}
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX 12
#define mk make_pair
#define INF 1 << 28
string s[20];
bool vis[20][20];
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int n, w, h, d[MAX][MAX], c;
int dp[1 << MAX][MAX];
int rec(int s, int v) {
if (dp[s][v] >= 0)
return dp[s][v];
if (s == (1 << n) - 1 && v != 0)
return dp[s][v] = 0;
int res = INF;
for (int u = 0; u < n; u++)
if (!(s >> u & 1))
res = min(res, rec(s | 1 << u, u) + d[v][u]);
return dp[s][v] = res;
}
void bfs(int x2, int y2, int k) {
r(i, 20) r(j, 20) vis[i][j] = 0;
queue<pair<pair<int, int>, int>> q;
vis[x2][y2] = 1;
q.push(mk(mk(x2, y2), 0));
while (!q.empty()) {
pair<pair<int, int>, int> p = q.front();
q.pop();
int p1 = p.first.first, p2 = p.first.second, p3 = p.second;
r(i, 4) {
int x = dx[i] + p1;
int y = dy[i] + p2;
if (x >= 0 && x < w && y >= 0 && y < h)
if (!vis[x][y] && (s[y][x] != 'x')) {
if (0 <= s[y][x] && s[y][x] < 12)
d[k][(int)s[y][x]] = p3 + 1;
else if (k != 0 && s[y][x] == 'o')
d[k][0] = p3 + 1;
q.push(mk(mk(x, y), p3 + 1));
vis[x][y] = 1;
}
}
}
}
int main() {
while (cin >> w >> h, w) {
c = 1;
int a, b;
vector<pair<int, int>> v;
r(i, h) cin >> s[i];
r(j, w) r(i, h) if (s[i][j] == '*') s[i][j] = c++,
v.push_back(make_pair(j, i));
memset(dp, -1, sizeof(dp));
n = c;
r(i, MAX) r(j, MAX) d[i][j] = INF;
r(j, w) r(i, h) if (s[i][j] == 'o') a = j, b = i;
bfs(a, b, 0);
r(i, c - 1) bfs(v[i].first, v[i].second, i + 1);
int p = rec(1, 0);
if (p == INF)
p = -1;
cout << p << endl;
}
}
|
[["-", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["-", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 51, 16, 12, 23, 0, 16, 12, 103, 0, 125], ["+", 51, 16, 12, 23, 0, 16, 12, 103, 0, 125], ["-", 0, 57, 75, 76, 0, 57, 75, 76, 0, 95]]
| 1
| 784
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define sq(x) ((x) * (x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
int h, w;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
vector<string> f;
vector<int> pos;
int start;
int d[402][402];
int dp[1 << 11][11];
int K;
int id(int x, int y) { return x * w + y; }
string binary(int a) {
string ret;
for (int i = 0; i < 4; i++) {
if ((1 << i) & a)
ret += "1";
else
ret += "0";
}
return ret;
}
int rec(int S, int v) {
if (dp[S][v] != -1)
return dp[S][v];
if (S == 0)
return 0;
int ret = INF;
for (int i = 0; i < K; i++) {
if ((S & (1 << i)) != 0)
ret = min(ret, rec(S - (1 << i), i) + d[pos[i]][pos[v]]);
}
// cout << binary(S) << ' ' << v << ' ' << ret << endl;
return dp[S][v] = ret;
}
int solve() {
f.clear();
pos.clear();
scanf("%d %d", &w, &h);
int N = w * h;
if (h + w == 0)
return 1;
f.resize(h);
for (int i = 0; i < h; i++)
cin >> f[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
d[i][j] = INF;
if (i == j)
d[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
for (int dir = 0; dir < 4; dir++) {
int nx = i + dx[dir];
int ny = j + dy[dir];
if (nx < 0 || nx >= h || ny < 0 || ny >= w)
continue;
if (f[i][j] == 'x' || f[nx][ny] == 'x')
continue;
// cout << id(i,j) << ' ' << id(nx,ny) << endl;
d[id(nx, ny)][id(i, j)] = 1;
d[id(i, j)][id(nx, ny)] = 1;
}
}
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (f[i][j] == 'o')
start = pos.size();
if (f[i][j] == 'o' || f[i][j] == '*')
pos.pb(id(i, j));
}
}
K = pos.size();
for (int i = 0; i < (1 << K); i++) {
for (int j = 0; j < K; j++) {
dp[i][j] = -1;
}
}
int ans = rec((1 << K) - (1 << start), start);
if (ans == INF)
ans = -1;
printf("%d\n", ans);
return 0;
}
int main() {
while (1) {
if (solve())
return 0;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define sq(x) ((x) * (x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
int h, w;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
vector<string> f;
vector<int> pos;
int start;
int d[402][402];
int dp[1 << 11][11];
int K;
int id(int x, int y) { return x * w + y; }
string binary(int a) {
string ret;
for (int i = 0; i < 4; i++) {
if ((1 << i) & a)
ret += "1";
else
ret += "0";
}
return ret;
}
int rec(int S, int v) {
if (dp[S][v] != -1)
return dp[S][v];
if (S == 0)
return 0;
int ret = INF;
for (int i = 0; i < K; i++) {
if ((S & (1 << i)) != 0)
ret = min(ret, rec(S - (1 << i), i) + d[pos[i]][pos[v]]);
}
// cout << S << ' ' << v << ' ' << ret << endl;
return dp[S][v] = ret;
}
int solve() {
f.clear();
pos.clear();
scanf("%d %d", &w, &h);
int N = w * h;
if (h + w == 0)
return 1;
f.resize(h);
for (int i = 0; i < h; i++)
cin >> f[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
d[i][j] = INF;
if (i == j)
d[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
for (int dir = 0; dir < 4; dir++) {
int nx = i + dx[dir];
int ny = j + dy[dir];
if (nx < 0 || nx >= h || ny < 0 || ny >= w)
continue;
if (f[i][j] == 'x' || f[nx][ny] == 'x')
continue;
// cout << id(i,j) << ' ' << id(nx,ny) << endl;
d[id(nx, ny)][id(i, j)] = 1;
d[id(i, j)][id(nx, ny)] = 1;
}
}
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (f[i][j] == 'o')
start = pos.size();
if (f[i][j] == 'o' || f[i][j] == '*')
pos.pb(id(i, j));
}
}
K = pos.size();
for (int i = 0; i < (1 << K); i++) {
for (int j = 0; j < K; j++) {
dp[i][j] = -1;
}
}
int ans = rec((1 << K) - 1 - (1 << start), start);
if (ans == INF)
ans = -1;
printf("%d\n", ans);
return 0;
}
int main() {
while (1) {
if (solve())
return 0;
}
return 0;
}
|
[["+", 51, 2, 3, 4, 0, 16, 31, 16, 12, 13], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 33]]
| 1
| 966
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
Scanner sc;
void run() {
for (;;) {
long a, d, n;
a = ni();
d = ni();
n = ni();
if ((a | d | n) == 0)
break;
int cnt = 0;
for (long ite = a;; ite += d) {
boolean f = true;
f = 2 <= ite;
for (int j = 2; j * j < ite; ++j) {
f &= ite % j != 0;
}
if (f) {
if (++cnt == n) {
System.out.println(ite);
break;
}
}
}
}
}
Main() { sc = new Scanner(System.in); }
int ni() { return sc.nextInt(); }
String ns() { return sc.next(); }
public static void main(String[] args) { new Main().run(); }
void debug(Object... os) { System.err.println(Arrays.deepToString(os)); }
}
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
Scanner sc;
void run() {
for (;;) {
long a, d, n;
a = ni();
d = ni();
n = ni();
if ((a | d | n) == 0)
break;
int cnt = 0;
for (long ite = a;; ite += d) {
boolean f = true;
f = 2 <= ite;
for (int j = 2; j * j <= ite; ++j) {
f &= ite % j != 0;
}
if (f) {
if (++cnt == n) {
System.out.println(ite);
break;
}
}
}
}
}
Main() { sc = new Scanner(System.in); }
int ni() { return sc.nextInt(); }
String ns() { return sc.next(); }
public static void main(String[] args) { new Main().run(); }
void debug(Object... os) { System.err.println(Arrays.deepToString(os)); }
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 241
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int[] createPrimes(int n) {
int[] ans = new int[n + 1];
Arrays.fill(ans, 1);
ans[0] = ans[1] = 0;
int max = (int)Math.sqrt(n) + 1;
for (int i = 2; i < max / 2 + 1; i++) {
ans[i * 2] = 0;
}
for (int i = 3; i <= max; i += 2) {
for (int j = 2; j < n / i; j++) {
ans[i * j] = 0;
}
}
return ans;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, d, n;
int m = (int)Math.pow(10, 6);
int[] primes = createPrimes(m);
// int[] subarray = new int[50]; // to debug
// System.arraycopy(primes, 0, subarray, 0, 50);
// System.out.println(Arrays.toString(subarray));
while (true) {
a = Integer.parseInt(sc.next());
d = Integer.parseInt(sc.next());
n = Integer.parseInt(sc.next());
int c = 0;
if (a == 0)
break;
int i = 0;
while (true) {
if (primes[a + i * d] == 1)
c++;
if (c == n) {
System.out.println(a + i * d);
break;
}
i++;
}
}
}
}
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int[] createPrimes(int n) {
int[] ans = new int[n + 1];
Arrays.fill(ans, 1);
ans[0] = ans[1] = 0;
int max = (int)Math.sqrt(n) + 1;
for (int i = 2; i < n / 2 + 1; i++) {
ans[i * 2] = 0;
}
for (int i = 3; i <= max; i += 2) {
for (int j = 2; j < n / i; j++) {
ans[i * j] = 0;
}
}
return ans;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, d, n;
int m = (int)Math.pow(10, 6);
int[] primes = createPrimes(m);
// int[] subarray = new int[50]; // to debug
// System.arraycopy(primes, 0, subarray, 0, 50);
// System.out.println(Arrays.toString(subarray));
while (true) {
a = Integer.parseInt(sc.next());
d = Integer.parseInt(sc.next());
n = Integer.parseInt(sc.next());
int c = 0;
if (a == 0)
break;
int i = 0;
while (true) {
if (primes[a + i * d] == 1)
c++;
if (c == n) {
System.out.println(a + i * d);
break;
}
i++;
}
}
}
}
|
[["-", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22]]
| 3
| 324
|
import java.util.Scanner;
public class Main {
static boolean[] primes;
static void primeSet(final int MAX) {
primes = new boolean[MAX + 1];
primes[2] = true;
for (int i = 3; i <= MAX; i += 2) {
primes[i] = true;
}
int rt = (int)Math.sqrt(MAX);
for (int i = 3; i <= rt; i += 2) {
if (primes[i]) {
for (int j = i * 2; j <= MAX; j += i) {
primes[j] = false;
}
}
}
}
@SuppressWarnings("unused")
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
primeSet(1000000);
while (true) {
int a = stdIn.nextInt();
int d = stdIn.nextInt();
int n = stdIn.nextInt();
int cnt = 0;
if (a == 0 && d == 0 && n == 0) {
break;
}
for (int i = a;; i += d) {
// System.out.println(i);
if (primes[i]) {
cnt++;
}
if (cnt == n) {
System.out.println("result " + i);
break;
}
}
}
}
}
|
import java.util.Scanner;
public class Main {
static boolean[] primes;
static void primeSet(final int MAX) {
primes = new boolean[MAX + 1];
primes[2] = true;
for (int i = 3; i <= MAX; i += 2) {
primes[i] = true;
}
int rt = (int)Math.sqrt(MAX);
for (int i = 3; i <= rt; i += 2) {
if (primes[i]) {
for (int j = i * 2; j <= MAX; j += i) {
primes[j] = false;
}
}
}
}
@SuppressWarnings("unused")
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
primeSet(1000000);
while (true) {
int a = stdIn.nextInt();
int d = stdIn.nextInt();
int n = stdIn.nextInt();
int cnt = 0;
if (a == 0 && d == 0 && n == 0) {
break;
}
for (int i = a;; i += d) {
if (primes[i]) {
cnt++;
}
if (cnt == n) {
System.out.println(i);
break;
}
}
}
}
}
|
[["-", 0, 492, 3, 4, 0, 16, 31, 5, 0, 62], ["-", 0, 492, 3, 4, 0, 16, 31, 5, 0, 491], ["-", 0, 1, 0, 492, 3, 4, 0, 16, 17, 72]]
| 3
| 275
|
#include <stdio.h>
#define N 1000010
int c[N];
int main(void) {
int i, j, a, d, n;
c[0] = c[1] = 1;
for (i = 2; i * i < N; ++i)
if (!c[i])
for (j = i * i; j < N; j += i)
c[j] = 1;
while (scanf("%d%d%d", &a, &d, &n), a) {
for (i = 1; i < n; i += !c[a])
a += d;
printf("%d\n", a);
}
return 0;
}
|
#include <stdio.h>
#define N 1000010
int c[N];
int main(void) {
int i, j, a, d, n;
c[0] = c[1] = 1;
for (i = 2; i * i < N; ++i)
if (!c[i])
for (j = i * i; j < N; j += i)
c[j] = 1;
while (scanf("%d%d%d", &a, &d, &n), a) {
for (i = !c[a]; i < n; i += !c[a])
a += d;
printf("%d\n", a);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 8, 9, 0, 7, 10, 11, 12, 91, 17, 111], ["+", 0, 7, 10, 11, 12, 91, 28, 69, 28, 22], ["+", 0, 7, 10, 11, 12, 91, 28, 69, 0, 70], ["+", 0, 7, 10, 11, 12, 91, 28, 69, 71, 22], ["+", 0, 7, 10, 11, 12, 91, 28, 69, 0, 73]]
| 0
| 144
|
#include <iostream>
int main() {
while (1) {
int judgeNum = 0;
int pointSum = 0;
int maximumPoint = 0;
int minimumPoint = 1000;
std::cin >> judgeNum;
if (judgeNum == 0) {
break;
}
for (int i = 0; i < judgeNum; i++) {
int point;
std::cin >> point;
if (point > maximumPoint) {
maximumPoint = point;
} else if (point < minimumPoint) {
minimumPoint = point;
}
pointSum += point;
}
int answerSum = pointSum - maximumPoint - minimumPoint;
std::cout << answerSum / (judgeNum - 2) << std::endl;
}
return 0;
}
|
#include <iostream>
int main() {
while (1) {
int judgeNum = 0;
int pointSum = 0;
int maximumPoint = 0;
int minimumPoint = 1000;
std::cin >> judgeNum;
if (judgeNum == 0) {
break;
}
for (int i = 0; i < judgeNum; i++) {
int point;
std::cin >> point;
if (point > maximumPoint) {
maximumPoint = point;
}
if (point < minimumPoint) {
minimumPoint = point;
}
pointSum += point;
}
int answerSum = pointSum - maximumPoint - minimumPoint;
std::cout << answerSum / (judgeNum - 2) << std::endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 132
|
#include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N && N > 0) {
int sum = 0;
int largest = 0;
int smallest = 1000;
for (int i = 0; i < N; ++i) {
cin >> S;
if (largest < S) {
largest = S;
} else if (smallest > S) {
smallest = S;
}
sum += S;
}
cout << ((sum - largest - smallest) / (N - 2)) << endl;
}
}
|
#include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N && N > 0) {
int sum = 0;
int largest = 0;
int smallest = 1000;
for (int i = 0; i < N; ++i) {
cin >> S;
if (largest < S) {
largest = S;
}
if (smallest > S) {
smallest = S;
}
sum += S;
}
cout << ((sum - largest - smallest) / (N - 2)) << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 113
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
int max = -1, min = 10000, sum = 0, score = 0, ans = 0;
for (int i = 0; i < n; i++) {
cin >> score;
sum += score;
if (score > max)
max = score;
else if (score < min)
min = score;
}
sum -= max + min;
ans = sum / (n - 2);
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
int max = -1, min = 10000, sum = 0, score = 0, ans = 0;
for (int i = 0; i < n; i++) {
cin >> score;
sum += score;
if (score > max)
max = score;
if (score < min)
min = score;
}
sum -= max + min;
ans = sum / (n - 2);
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 148
|
#include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N &&
N > 0) { // N??????????????????????????????????????§while????????????
int sum = 0;
int min = 1001; // min????°?????????¨?????????
int max = -1;
int average = -1;
for (int i = 0; i < N; i++) {
cin >> S;
sum += S;
if (S > max)
max = S;
if (S < min)
min = S;
}
average = sum - min - max / N - 2; //???N-2?????§???????????¨?????¨??????
cout << average << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N &&
N > 0) { // N??????????????????????????????????????§while????????????
int sum = 0;
int min = 1001; // min????°?????????¨?????????
int max = -1;
int average = -1;
for (int i = 0; i < N; i++) {
cin >> S;
sum += S;
if (S > max)
max = S;
if (S < min)
min = S;
}
average =
(sum - min - max) /
(N -
2); //???N-2?????§???????????¨?????¨??????????????????????????¨????????????????????????
cout << average << endl;
}
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 1
| 117
|
#include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N && N > 0) {
int sum = 0;
int largest = 0;
int smallest = 1000;
for (int i = 0; i < N; i++) {
cin >> S;
sum += S;
if (S > largest)
largest = S;
if (S < smallest)
smallest = S;
}
sum = sum - largest - smallest;
cout << sum << endl;
}
}
|
#include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N && N > 0) {
int sum = 0;
int largest = 0;
int smallest = 1000;
for (int i = 0; i < N; i++) {
cin >> S;
sum += S;
if (S > largest)
largest = S;
if (S < smallest)
smallest = S;
}
sum = sum - largest - smallest;
// cout << "laegest:" << largest << endl;
// cout << "smallest:" << smallest << endl;
cout << sum / (N - 2) << endl;
}
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 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
| 102
|
#include <algorithm>
#include <iostream>
using namespace std;
int MIN, MAX, n, sum, a, i;
int main() {
while (true) {
cin >> n;
if (!n) {
break;
}
MIN = 10000000;
MAX = 0;
sum = 0;
for (i = 0; i < n; i++) {
cin >> a;
MIN = min(MIN, a);
MAX = max(MAX, a);
sum += a;
}
cout << (sum - MIN - MAX) / n << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int MIN, MAX, n, sum, a, i;
int main() {
while (true) {
cin >> n;
if (!n) {
break;
}
MIN = 10000000;
MAX = 0;
sum = 0;
for (i = 0; i < n; i++) {
cin >> a;
MIN = min(MIN, a);
MAX = max(MAX, a);
sum += a;
}
cout << (sum - MIN - MAX) / (n - 2) << endl;
}
}
|
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 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
| 113
|
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define INF 1e09
using namespace std;
int main() {
int n;
int total, maxim, minim;
int tmp;
while (cin >> n) {
total = 0;
maxim = -INF;
minim = INF;
REP(i, n) {
cin >> tmp;
total += tmp;
maxim = max(maxim, tmp);
minim = min(minim, tmp);
}
total -= (maxim + minim);
cout << total / (n - 2) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define INF 1e09
using namespace std;
int main() {
int n;
int total, maxim, minim;
int tmp;
while (cin >> n and n) {
total = 0;
maxim = -INF;
minim = INF;
REP(i, n) {
cin >> tmp;
total += tmp;
maxim = max(maxim, tmp);
minim = min(minim, tmp);
}
total -= (maxim + minim);
cout << total / (n - 2) << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 355], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
| 1
| 114
|
#include <iostream>
using namespace std;
int main() {
int a, n, sum, min, max, i;
while (1) {
cin >> n;
if (n == 0) {
break;
}
cin >> min;
sum = min;
max = min;
for (i = 0; i < n - 1; i++) {
cin >> a;
sum = sum + a;
if (min > a) {
min = a;
}
if (max < a) {
max = a;
}
}
cout << (sum - max - min) / n << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, n, sum, min, max, i;
while (1) {
cin >> n;
if (n == 0) {
break;
}
cin >> min;
sum = min;
max = min;
for (i = 0; i < n - 1; i++) {
cin >> a;
sum = sum + a;
if (min > a) {
min = a;
}
if (max < a) {
max = a;
}
}
cout << (sum - max - min) / (n - 2) << endl;
}
return 0;
}
|
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 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
| 125
|
#include <iostream>
using namespace std;
int main() {
int n, s;
while (cin >> n && n > 0) {
int large = 0;
int small = 1000;
int sum = 0;
for (int i = 0; i > n; ++i) {
cin >> s;
sum = sum + s;
if (large < s) {
large = s;
}
if (small > s) {
small = s;
}
}
int ans = 0;
ans = (sum - large - small) / (n - 2);
cout << ans << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int n, s;
while (cin >> n && n > 0) {
int large = 0;
int small = 1000;
int sum = 0;
for (int i = 0; i < n; ++i) {
cin >> s;
sum = sum + s;
if (large < s) {
large = s;
}
if (small > s) {
small = s;
}
}
int ans = 0;
ans = (sum - large - small) / (n - 2);
cout << ans << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 121
|
#include <iostream>
using namespace std;
int main() {
int n, max, min, s;
long sum;
while (true) {
cin >> n;
sum = max = min = 0;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> s;
if (s < min)
min = s;
if (s > max)
max = s;
sum += s;
}
sum -= (min + max);
cout << sum / (n - 2) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, max, min, s;
long sum;
while (true) {
cin >> n;
sum = max = 0;
min = 1000;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> s;
if (s < min)
min = s;
if (s > max)
max = s;
sum += s;
}
sum -= (min + max);
cout << sum / (n - 2) << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 11, 12, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 1, 0, 11, 12, 11, 12, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 117
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.