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
| change_count
int64 0
100
|
|---|---|---|---|---|---|
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int n, c;
const int num[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
while (cin >> n, n != -1) {
int seg[] = {0, 0, 0, 0, 0, 0, 0};
while (n--) {
cin >> c;
for (int i = 0; i < 7; i++) {
if (seg[i] != num[c][i]) {
seg[i] = 1;
} else {
seg[i] = 0;
}
cout << seg[i];
}
memcpy(seg, num[c], sizeof(int) * 7);
cout << endl;
}
}
return (0);
}
|
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int n, c;
const int num[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
while (cin >> n, n != -1) {
int seg[] = {0, 0, 0, 0, 0, 0, 0};
while (n--) {
cin >> c;
for (int i = 0; i < 7; i++) {
if (seg[i] != num[c][i]) {
seg[i] = 1;
} else {
seg[i] = 0;
}
cout << seg[i];
}
memcpy(seg, num[c], sizeof(int) * 7);
cout << endl;
}
}
return (0);
}
|
[["-", 0, 43, 49, 50, 51, 83, 0, 83, 0, 13], ["-", 0, 43, 49, 50, 51, 83, 0, 83, 0, 21], ["+", 0, 43, 49, 50, 51, 83, 0, 83, 0, 21], ["+", 0, 43, 49, 50, 51, 83, 0, 83, 0, 13]]
| 1
| 318
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define gsort(st, en) sort((st), (en), greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string, int>;
using pii = pair<int, int>;
const int mod = 1000000007;
constexpr int imax = ((1 << 30) - 1) * 2 + 1;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0);
double eps = 1e-10;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
inline bool value(int x, int y, int w, int h) {
return (x >= 0 && x < w && y >= 0 && y < h);
}
template <typename T> void Unique(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <typename T> T ston(string &str, T n) {
istringstream sin(str);
T num;
sin >> num;
return num;
}
void Ans(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
std::string to_binString(unsigned int val) {
std::string str = "";
while (val != 0) {
if ((val & 1) == 0)
str.insert(str.begin(), '0');
else
str.insert(str.begin(), '1');
val >>= 1;
}
while (str.size() < 7) {
str = "0" + str;
}
return str;
}
const int bit[10] = {126, 48, 109, 121, 51, 91, 95, 112, 127, 123};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// rep(i,10){
// cout << i << " " +to_binString(bit[i])<<endl;
// }
ll n;
while (cin >> n && n != -1) {
ll a;
int state = 0;
rep(i, n) {
cin >> a;
auto s = to_binString(state ^ bit[a]);
reverse(all(s));
cout << s << endl;
state = bit[a];
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define gsort(st, en) sort((st), (en), greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string, int>;
using pii = pair<int, int>;
const int mod = 1000000007;
constexpr int imax = ((1 << 30) - 1) * 2 + 1;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0);
double eps = 1e-10;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
inline bool value(int x, int y, int w, int h) {
return (x >= 0 && x < w && y >= 0 && y < h);
}
template <typename T> void Unique(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <typename T> T ston(string &str, T n) {
istringstream sin(str);
T num;
sin >> num;
return num;
}
void Ans(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
std::string to_binString(unsigned int val) {
std::string str = "";
while (val != 0) {
if ((val & 1) == 0)
str.insert(str.begin(), '0');
else
str.insert(str.begin(), '1');
val >>= 1;
}
while (str.size() < 7) {
str = "0" + str;
}
return str;
}
const int bit[10] = {126, 48, 109, 121, 51, 91, 95, 114, 127, 123};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// rep(i,10){
// cout << i << " " +to_binString(bit[i])<<endl;
// }
ll n;
while (cin >> n && n != -1) {
ll a;
int state = 0;
rep(i, n) {
cin >> a;
auto s = to_binString(state ^ bit[a]);
reverse(all(s));
cout << s << endl;
state = bit[a];
}
}
return 0;
}
|
[["-", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13], ["+", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13]]
| 1
| 589
| 2
|
#include <algorithm>
#include <iostream>
#include <string>
const int V[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
using namespace std;
typedef long long ll;
typedef long double ld;
string change(int a, int b) {
string res = "";
for (int i = 0; i < 7; i++) {
if (V[a][i] == V[b][i]) {
res += "0";
} else {
res += "1";
}
}
return res;
}
int main() {
int n, f = -1, t;
while (true) {
cin >> n;
if (n == -1)
break;
for (int i = 0; i < n; i++) {
cin >> t;
if (f == -1) {
for (int j = 0; j < 7; j++) {
cout << V[t][j];
}
cout << endl;
f = t;
} else {
cout << change(f, t) << endl;
f = t;
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
const int V[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
using namespace std;
typedef long long ll;
typedef long double ld;
string change(int a, int b) {
string res = "";
for (int i = 0; i < 7; i++) {
if (V[a][i] == V[b][i]) {
res += "0";
} else {
res += "1";
}
}
return res;
}
int main() {
int n, f = -1, t;
while (true) {
cin >> n;
if (n == -1)
break;
for (int i = 0; i < n; i++) {
cin >> t;
if (f == -1) {
for (int j = 0; j < 7; j++) {
cout << V[t][j];
}
cout << endl;
f = t;
} else {
cout << change(f, t) << endl;
f = t;
}
}
f = -1;
}
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]]
| 1
| 379
| 4
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, i;
string n, d[10] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
while (cin >> a) {
if (a == -1)
break;
n = "1111111";
for (i = 0; i < a; i++) {
cin >> b;
for (int j = 0; j < 7; j++) {
if (n[j] == d[b][j]) {
cout << "1";
} else {
cout << "0";
}
}
n = d[b];
cout << endl;
}
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, i;
string n, d[10] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
while (cin >> a) {
if (a == -1)
break;
n = "0000000";
for (i = 0; i < a; i++) {
cin >> b;
for (int j = 0; j < 7; j++) {
if (n[j] == d[b][j]) {
cout << "0";
} else {
cout << "1";
}
}
n = d[b];
cout << endl;
}
}
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["-", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
| 1
| 171
| 6
|
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
using namespace std;
int dis[10] = {63, 6, 91, 79, 102, 109, 115, 39, 127, 111};
int main() {
int a;
while (cin >> a, a != -1) {
int now = 0;
for (int b = 0; b < a; b++) {
int c;
cin >> c;
int d = now ^ dis[c];
for (int k = 64; k != 0; k >>= 1) {
if (d & k)
cout << 1;
else
cout << 0;
}
cout << endl;
now = dis[c];
}
}
}
|
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
using namespace std;
int dis[10] = {63, 6, 91, 79, 102, 109, 125, 39, 127, 111};
int main() {
int a;
while (cin >> a, a != -1) {
int now = 0;
for (int b = 0; b < a; b++) {
int c;
cin >> c;
int d = now ^ dis[c];
for (int k = 64; k != 0; k >>= 1) {
if (d & k)
cout << 1;
else
cout << 0;
}
cout << endl;
now = dis[c];
}
}
}
|
[["-", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13], ["+", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13]]
| 1
| 144
| 2
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
string s[10] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
int n, a;
while (cin >> n, n < 0) {
string b = "00000000";
while (n--) {
cin >> a;
r(i, 7) {
if (b[i] != s[a][i]) {
cout << 1;
} else
cout << 0;
b[i] = s[a][i];
}
cout << endl;
}
}
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
string s[10] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
int n, a;
while (cin >> n, n > -1) {
string b = "00000000";
while (n--) {
cin >> a;
r(i, 7) {
if (b[i] != s[a][i]) {
cout << 1;
} else
cout << 0;
b[i] = s[a][i];
}
cout << endl;
}
}
}
|
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 18], ["-", 0, 52, 15, 339, 51, 34, 12, 16, 12, 13], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 47], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 13]]
| 1
| 155
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 20)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
string str[] = {"0111111", "0000110", "10111011", "1001111", "1100110",
"1101101", "1111101", "01001111", "1111111", "1101111"};
int main() {
int n;
while (1) {
string s = "";
cin >> n;
if (n == -1)
break;
rep(i, n) {
int num;
cin >> num;
if (i == 0)
cout << str[num] << endl;
else {
string tmp = "";
rep(i, 7) {
if (str[num][i] != s[i])
tmp += "1";
else
tmp += "0";
}
cout << tmp << endl;
}
s = str[num];
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 20)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
string str[] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
int main() {
int n;
while (1) {
string s = "";
cin >> n;
if (n == -1)
break;
rep(i, n) {
int num;
cin >> num;
if (i == 0)
cout << str[num] << endl;
else {
string tmp = "";
rep(i, 7) {
if (str[num][i] != s[i])
tmp += "1";
else
tmp += "0";
}
cout << tmp << endl;
}
s = str[num];
}
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6]]
| 1
| 259
| 4
|
// 0228.cpp : ??????????????? ??¢????????±????????§????????¨?????????
// ?????????????????????????????????
//
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
int main() {
ios::sync_with_stdio(false);
string a[10];
a[0] = "0111111";
a[1] = "0000110";
a[2] = "1011011";
a[3] = "1001111";
a[4] = "1100001";
a[5] = "1101101";
a[7] = "0100111";
a[6] = "1111101";
a[8] = "1111111";
a[9] = "1101111";
while (true) {
ll n;
cin >> n;
if (n == -1) {
break;
}
string s = "0000000";
for (int i = 0; i < n; i++) {
int d;
cin >> d;
for (int j = 0; j < 7; j++) {
if (a[d][j] == s[j]) {
cout << 0;
} else {
cout << 1;
}
}
cout << endl;
s = a[d];
}
}
return 0;
}
|
// 0228.cpp : ??????????????? ??¢????????±????????§????????¨?????????
// ?????????????????????????????????
//
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
int main() {
ios::sync_with_stdio(false);
string a[10];
a[0] = "0111111";
a[1] = "0000110";
a[2] = "1011011";
a[3] = "1001111";
a[4] = "1100110";
a[5] = "1101101";
a[7] = "0100111";
a[6] = "1111101";
a[8] = "1111111";
a[9] = "1101111";
while (true) {
ll n;
cin >> n;
if (n == -1) {
break;
}
string s = "0000000";
for (int i = 0; i < n; i++) {
int d;
cin >> d;
for (int j = 0; j < 7; j++) {
if (a[d][j] == s[j]) {
cout << 0;
} else {
cout << 1;
}
}
cout << endl;
s = a[d];
}
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6]]
| 1
| 279
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
string table[] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "1111111", "1101111"};
int n;
while (cin >> n, ~n) {
string cur = "0000000";
rep(i, n) {
int number;
cin >> number;
rep(i, 7) cout << (cur[i] != table[number][i]);
cout << endl;
cur = table[number];
}
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
string table[] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
int n;
while (cin >> n, ~n) {
string cur = "0000000";
rep(i, n) {
int number;
cin >> number;
rep(i, 7) cout << (cur[i] != table[number][i]);
cout << endl;
cur = table[number];
}
}
}
|
[["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 62], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 21]]
| 1
| 137
| 4
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;
int main() {
int n;
string s[10];
s[0] = "0111111";
s[1] = "0000110";
s[2] = "1011011";
s[3] = "1001111";
s[4] = "1100110";
s[5] = "1101101";
s[6] = "1111101";
s[7] = "0100111";
s[8] = "1111111";
s[9] = "1101111";
bool bi[9][7];
REP(i, 9)
REP(j, 7)
bi[i][j] = (s[i][j] == '1');
while (cin >> n, n != -1) {
int a;
bool prev[7] = {};
REP(i, n) {
cin >> a;
REP(i, 7) {
cout << (bi[a][i] xor prev[i]);
prev[i] = bi[a][i];
}
cout << endl;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;
int main() {
int n;
string s[10];
s[0] = "0111111";
s[1] = "0000110";
s[2] = "1011011";
s[3] = "1001111";
s[4] = "1100110";
s[5] = "1101101";
s[6] = "1111101";
s[7] = "0100111";
s[8] = "1111111";
s[9] = "1101111";
bool bi[10][7];
REP(i, 10)
REP(j, 7)
bi[i][j] = (s[i][j] == '1');
while (cin >> n, n != -1) {
int a;
bool prev[7] = {};
REP(i, n) {
cin >> a;
REP(i, 7) {
cout << (bi[a][i] xor prev[i]);
prev[i] = bi[a][i];
}
cout << endl;
}
}
}
|
[["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
| 1
| 283
| 4
|
#include <iostream>
using namespace std;
const string numbers[10] = {"0111111", "0000110", "1011011", "1001111",
"1100110", "1101101", "1111101", "0100111",
"1111111", "1101111"};
string convert(int k, string prev) {
string answer;
for (int i = 0; i < 7; i++) {
if (numbers[k][i] == prev[i]) {
answer += '0';
} else {
answer += '1';
}
}
return answer;
}
int main(void) {
int n;
while (cin >> n && n != -1) {
string prev = "000000";
for (int i = 0; i < n; i++) {
int k;
cin >> k;
cout << convert(k, prev) << endl;
prev = numbers[k];
}
}
return 0;
}
|
#include <iostream>
using namespace std;
const string numbers[10] = {"0111111", "0000110", "1011011", "1001111",
"1100110", "1101101", "1111101", "0100111",
"1111111", "1101111"};
string convert(int k, string prev) {
string answer;
for (int i = 0; i < 7; i++) {
if (numbers[k][i] == prev[i]) {
answer += '0';
} else {
answer += '1';
}
}
return answer;
}
int main(void) {
int n;
while (cin >> n && n != -1) {
string prev = "0000000";
for (int i = 0; i < n; i++) {
int k;
cin >> k;
cout << convert(k, prev) << endl;
prev = numbers[k];
}
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 5, 0, 6], ["+", 8, 9, 0, 43, 49, 50, 51, 5, 0, 6]]
| 1
| 193
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
int i, j;
int a[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 11, 1}, {1, 1, 0, 1, 1, 1, 1}};
int b[7], c[100], n;
while (cin >> n && n != -1) {
for (i = 0; i < n; i++)
cin >> c[i];
memset(b, 0, sizeof(b));
for (i = 0; i < n; i++) {
for (j = 0; j < 7; j++) {
cout << (b[j] ^ a[c[i]][j]);
b[j] = (b[j] + (b[j] ^ a[c[i]][j])) % 2;
}
cout << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
int i, j;
int a[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
int b[7], c[100], n;
while (cin >> n && n != -1) {
for (i = 0; i < n; i++)
cin >> c[i];
memset(b, 0, sizeof(b));
for (i = 0; i < n; i++) {
for (j = 0; j < 7; j++) {
cout << (b[j] ^ a[c[i]][j]);
b[j] = (b[j] + (b[j] ^ a[c[i]][j])) % 2;
}
cout << endl;
}
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 83, 0, 83, 0, 13], ["+", 0, 43, 49, 50, 51, 83, 0, 83, 0, 13], ["+", 0, 43, 49, 50, 51, 83, 0, 83, 0, 21]]
| 1
| 348
| 4
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string state[10];
int n;
state[0] = "0111111";
state[1] = "0000110";
state[2] = "1011011";
state[3] = "1001111";
state[4] = "1100110";
state[5] = "1101101";
state[6] = "1111101";
state[7] = "0000111";
state[8] = "1111111";
state[9] = "1101111";
while (cin >> n && n != -1) {
string cur = "0000000";
string out = "0000000";
int t;
for (int i = 0; i < n; i++) {
cin >> t;
for (int i = 0; i < 7; i++) {
cur[i] == state[t][i] ? out[i] = '0' : out[i] = '1';
}
cout << out << endl;
cur = state[t];
}
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string state[10];
int n;
state[0] = "0111111";
state[1] = "0000110";
state[2] = "1011011";
state[3] = "1001111";
state[4] = "1100110";
state[5] = "1101101";
state[6] = "1111101";
state[7] = "0100111";
state[8] = "1111111";
state[9] = "1101111";
while (cin >> n && n != -1) {
string cur = "0000000";
string out = "0000000";
int t;
for (int i = 0; i < n; i++) {
cin >> t;
for (int i = 0; i < 7; i++) {
cur[i] == state[t][i] ? out[i] = '0' : out[i] = '1';
}
cout << out << endl;
cur = state[t];
}
}
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6]]
| 1
| 223
| 2
|
#include <cstdio>
int main() {
while (true) {
int n, a[100];
int mask[10];
mask[0] = 1 + 2 + 4 + 8 + 16 + 32;
mask[1] = 2 + 4;
mask[2] = 1 + 2 + 8 + 16 + 64;
mask[3] = 1 + 2 + 8 + 16 + 64;
mask[4] = 2 + 4 + 32 + 64;
mask[5] = 1 + 4 + 8 + 32 + 64;
mask[6] = 1 + 4 + 8 + 16 + 32 + 64;
mask[7] = 1 + 2 + 4 + 32;
mask[8] = 1 + 2 + 4 + 8 + 16 + 32 + 64;
mask[9] = 1 + 2 + 4 + 8 + 32 + 64;
scanf("%d", &n);
if (n == -1)
break;
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
int state = 0;
for (int i = 0; i < n; ++i) {
int sig = state ^ mask[a[i]];
for (int bit = 6; bit >= 0; --bit)
printf("%c", sig & (1 << bit) ? '1' : '0');
printf("\n");
state = mask[a[i]];
}
}
return 0;
}
|
#include <cstdio>
int main() {
while (true) {
int n, a[100];
int mask[10];
mask[0] = 1 + 2 + 4 + 8 + 16 + 32;
mask[1] = 2 + 4;
mask[2] = 1 + 2 + 8 + 16 + 64;
mask[3] = 1 + 2 + 4 + 8 + 64;
mask[4] = 2 + 4 + 32 + 64;
mask[5] = 1 + 4 + 8 + 32 + 64;
mask[6] = 1 + 4 + 8 + 16 + 32 + 64;
mask[7] = 1 + 2 + 4 + 32;
mask[8] = 1 + 2 + 4 + 8 + 16 + 32 + 64;
mask[9] = 1 + 2 + 4 + 8 + 32 + 64;
scanf("%d", &n);
if (n == -1)
break;
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
int state = 0;
for (int i = 0; i < n; ++i) {
int sig = state ^ mask[a[i]];
for (int bit = 6; bit >= 0; --bit)
printf("%c", sig & (1 << bit) ? '1' : '0');
printf("\n");
state = mask[a[i]];
}
}
return 0;
}
|
[["-", 0, 11, 12, 16, 31, 16, 31, 16, 12, 13], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 13], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 13]]
| 1
| 314
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
int ss[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 0, 1, 1, 1, 1, 1}};
int main() {
for (;;) {
int n;
cin >> n;
if (n == -1)
return 0;
int d[7];
fill(d, d + 7, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int j = 0; j < 7; j++) {
cout << (d[j] ^ ss[x][j]);
d[j] = ss[x][j];
}
cout << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
// g, f, e, d, c, b, a
int ss[10][7] = {{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
int main() {
for (;;) {
int n;
cin >> n;
if (n == -1)
return 0;
int d[7];
fill(d, d + 7, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int j = 0; j < 7; j++) {
cout << (d[j] ^ ss[x][j]);
d[j] = ss[x][j];
}
cout << endl;
}
}
}
|
[["-", 0, 43, 49, 50, 51, 83, 0, 83, 0, 13], ["-", 0, 43, 49, 50, 51, 83, 0, 83, 0, 21], ["+", 0, 43, 49, 50, 51, 83, 0, 83, 0, 21], ["+", 0, 43, 49, 50, 51, 83, 0, 83, 0, 13]]
| 1
| 298
| 4
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
const int A = 1, B = 2, C = 4, D = 8, E = 16, F = 32, G = 64;
int sig[10];
int main() {
sig[0] = 1 + B * 1 + C * 1 + D * 1 + E * 1 + F * 1 + G * 0;
sig[1] = 0 + B * 1 + C * 1 + D * 0 + E * 0 + F * 0 + G * 0;
sig[2] = 1 + B * 1 + C * 0 + D * 1 + E * 1 + F * 0 + G * 0;
sig[3] = 1 + B * 1 + C * 1 + D * 1 + E * 0 + F * 0 + G * 1;
sig[4] = 0 + B * 1 + C * 1 + D * 0 + E * 0 + F * 1 + G * 1;
sig[5] = 1 + B * 0 + C * 1 + D * 1 + E * 0 + F * 1 + G * 1;
sig[6] = 1 + B * 0 + C * 1 + D * 1 + E * 1 + F * 1 + G * 1;
sig[7] = 1 + B * 1 + C * 1 + D * 0 + E * 0 + F * 1 + G * 0;
sig[8] = 1 + B * 1 + C * 1 + D * 1 + E * 1 + F * 1 + G * 1;
sig[9] = 1 + B * 1 + C * 1 + D * 1 + E * 0 + F * 1 + G * 1;
// REP(10) cout << i << ":" << sig[i] << endl;
int n;
while (cin >> n) {
if (n == -1)
break;
int disp = 0, next = 0, ans = 0;
REP(n) {
cin >> next;
ans = sig[next] ^ disp;
// cout << "ans" << ans << endl;
rep(j, 7) cout << (ans >> (6 - j) & 1);
cout << endl;
disp = sig[next];
}
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
const int A = 1, B = 2, C = 4, D = 8, E = 16, F = 32, G = 64;
int sig[10];
int main() {
sig[0] = 1 + B * 1 + C * 1 + D * 1 + E * 1 + F * 1 + G * 0;
sig[1] = 0 + B * 1 + C * 1 + D * 0 + E * 0 + F * 0 + G * 0;
sig[2] = 1 + B * 1 + C * 0 + D * 1 + E * 1 + F * 0 + G * 1;
sig[3] = 1 + B * 1 + C * 1 + D * 1 + E * 0 + F * 0 + G * 1;
sig[4] = 0 + B * 1 + C * 1 + D * 0 + E * 0 + F * 1 + G * 1;
sig[5] = 1 + B * 0 + C * 1 + D * 1 + E * 0 + F * 1 + G * 1;
sig[6] = 1 + B * 0 + C * 1 + D * 1 + E * 1 + F * 1 + G * 1;
sig[7] = 1 + B * 1 + C * 1 + D * 0 + E * 0 + F * 1 + G * 0;
sig[8] = 1 + B * 1 + C * 1 + D * 1 + E * 1 + F * 1 + G * 1;
sig[9] = 1 + B * 1 + C * 1 + D * 1 + E * 0 + F * 1 + G * 1;
// REP(10) cout << i << ":" << sig[i] << endl;
int n;
while (cin >> n) {
if (n == -1)
break;
int disp = 0, next = 0, ans = 0;
REP(n) {
cin >> next;
ans = sig[next] ^ disp;
// cout << "ans" << ans << endl;
rep(j, 7) cout << (ans >> (6 - j) & 1);
cout << endl;
disp = sig[next];
}
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
| 1
| 475
| 2
|
#include <iostream>
using namespace std;
const char *bits[] = {
"0111111", "0000110", "1011011", "1001111", "1100110", "1101101",
"1111101", "1001111", "0100111", "1111111", "1101111",
};
int main() {
int n;
while (cin >> n, n != -1) {
char current[] = "0000000";
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int i = 0; i < 7; i++) {
if (current[i] != bits[x][i]) {
cout << '1';
current[i] = bits[x][i];
} else {
cout << '0';
}
}
cout << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
const char *bits[] = {
"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111",
};
int main() {
int n;
while (cin >> n, n != -1) {
char current[] = "0000000";
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int i = 0; i < 7; i++) {
if (current[i] != bits[x][i]) {
cout << '1';
current[i] = bits[x][i];
} else {
cout << '0';
}
}
cout << endl;
}
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 62], ["-", 0, 30, 0, 43, 49, 50, 51, 83, 0, 21]]
| 1
| 181
| 4
|
#include <bitset>
#include <iostream>
#include <string>
using namespace std;
int nikara(const string &sig);
void tenkara(int);
int main() {
string sig[10] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "1111111", "1101111"};
string before, hoge;
int n, num;
int var = 0x0001;
int bvar, piyo;
while (cin >> n, n != -1) {
bvar = 0;
for (int i = 0; i < n; i++) {
cin >> num;
hoge = sig[num];
var = nikara(hoge);
piyo = var ^ bvar;
tenkara(piyo);
bvar = var;
}
}
}
int nikara(const string &sig) {
int out = 0;
for (int i = 0, size = sig.size(); i < size; ++i) {
out *= 2;
out += ((int)sig[i] == 49) ? 1 : 0;
}
return out;
}
void tenkara(int hoge) {
string sig;
for (int i = 0; i < 7; i++) {
sig[i] = hoge % 2 + '0';
hoge = hoge / 2;
}
for (int i = 6; i >= 0; i--) {
cout << sig[i];
}
cout << endl;
}
|
#include <bitset>
#include <iostream>
#include <string>
using namespace std;
int nikara(const string &sig);
void tenkara(int);
int main() {
string sig[10] = {"0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"};
string before, hoge;
int n, num;
int var = 0x0001;
int bvar, piyo;
while (cin >> n, n != -1) {
bvar = 0;
for (int i = 0; i < n; i++) {
cin >> num;
hoge = sig[num];
var = nikara(hoge);
piyo = var ^ bvar;
tenkara(piyo);
bvar = var;
}
}
}
int nikara(const string &sig) {
int out = 0;
for (int i = 0, size = sig.size(); i < size; ++i) {
out *= 2;
out += ((int)sig[i] == 49) ? 1 : 0;
}
return out;
}
void tenkara(int hoge) {
string sig;
for (int i = 0; i < 7; i++) {
sig[i] = hoge % 2 + '0';
hoge = hoge / 2;
}
for (int i = 6; i >= 0; i--) {
cout << sig[i];
}
cout << endl;
}
|
[["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 62], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 21]]
| 1
| 297
| 4
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int n, m;
vector<int> vege;
const int INF = 1 << 29;
int main(void) {
// 0111111 0000110 1011011 1001111 1100110 1101101 1111101 0100111 1111111
// 1101111
int memo[] = {127 - 64,
6,
64 + 16 + 8 + 2 + 1,
64 + 15,
64 + 32 + 4 + 2,
64 + 32 + 8 + 4 + 1,
127 - 2,
32 + 7,
127,
127 - 16};
int nisin[] = {64, 32, 16, 8, 4, 2, 1};
while (cin >> n && n != -1) {
int bit = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
int ans = bit ^ memo[a];
bit = memo[a];
for (int j = 0; j < 7; j++) {
if (ans > nisin[j]) {
ans -= nisin[j];
cout << 1;
} else
cout << 0;
}
cout << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int n, m;
vector<int> vege;
const int INF = 1 << 29;
int main(void) {
// 0111111 0000110 1011011 1001111 1100110 1101101 1111101 0100111 1111111
// 1101111
int memo[] = {127 - 64,
6,
64 + 16 + 8 + 2 + 1,
64 + 15,
64 + 32 + 4 + 2,
64 + 32 + 8 + 4 + 1,
127 - 2,
32 + 7,
127,
127 - 16};
int nisin[] = {64, 32, 16, 8, 4, 2, 1};
while (cin >> n && n != -1) {
int bit = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
int ans = bit ^ memo[a];
bit = memo[a];
for (int j = 0; j < 7; j++) {
if (ans >= nisin[j]) {
ans -= nisin[j];
cout << 1;
} else
cout << 0;
}
cout << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 241
| 2
|
#include <stdio.h>
int main(void) {
int b, r, g, c, s, t;
int gain;
int use;
for (;;) {
scanf("%d %d %d %d %d %d", &b, &r, &g, &c, &s, &t);
if (b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0)
break;
gain = b * 15 + r * 15 + g * 7 + c * 2 + (b * 5 + r * 3) * 15;
use = (t - s) * 3 - (b * 5 + r * 3);
printf("%d", gain - use + 100);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int b, r, g, c, s, t;
int gain;
int use;
for (;;) {
scanf("%d %d %d %d %d %d", &b, &r, &g, &c, &s, &t);
if (b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0)
break;
gain = b * 15 + r * 15 + g * 7 + c * 2 + (b * 5 + r * 3) * 15;
use = (t - s) * 3 - (b * 5 + r * 3);
printf("%d\n", gain - use + 100);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 154
| 1
|
main(b, r, g, c, s, t) {
for (; scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t), t;
printf("%d\n", 100 + b * 77 + r * 51 + g * 4 - c - 3 * t + 18 * b +
3 * r + 3 * g + 3 * c + 3 * s))
;
exit(0);
}
|
main(b, r, g, c, s, t) {
for (; scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t), t;
printf("%d\n", 100 + b * 77 + r * 51 + g * 4 - c - 3 * t + 18 * b +
12 * r + 3 * g + 3 * c + 3 * s))
;
exit(0);
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 16, 31, 13], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 31, 13]]
| 0
| 101
| 2
|
b, r, g, c, s;
main(t) {
while (t)
scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t);
if (t)
printf("%d\n", 100 - (t - s) * 3 + c * 2 + g * 7 + 95 * b + 63 * r);
}
|
b, r, g, c, s;
main(t) {
while (t && scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t))
if (t)
printf("%d\n", 100 - (t - s) * 3 + c * 2 + g * 7 + 95 * b + 63 * r);
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 23, 0, 25], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 2, 3, 4, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 1, 0, 35]]
| 0
| 83
| 4
|
s, i;
main(x) {
for (; scanf("%d", &x),
i - 5 ? s += x * ("}]% !"[i++] - 30)
: x
? i = !printf("%d\n", s - 3 * x),
s = 100 : 0;)
;
}
|
s = 100, i;
main(x) {
for (; scanf("%d", &x),
i - 5 ? s += x * ("}]% !"[i++] - 30)
: x
? i = !printf("%d\n", s - 3 * x),
s = 100 : 0;)
;
}
|
[["+", 36, 36, 0, 30, 0, 1, 0, 11, 17, 32], ["+", 36, 36, 0, 30, 0, 1, 0, 11, 12, 13]]
| 0
| 70
| 10
|
b, r, g, c, s;
main(t) {
for (; scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t), ~b && t;)
// printf("%d\n",100-(t-s)*3+c*2+g*7+95*b+63*r);
printf("%d\n", 100 - (t - s) * 3 + c * 2 + 95 * b + (9 * r + g));
}
|
b, r, g, c, s;
main(t) {
for (; scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t), ~b && t;)
// printf("%d\n",100-(t-s)*3+c*2+g*7+95*b+63*r);
printf("%d\n", 100 - (t - s) * 3 + c * 2 + 95 * b + 7 * (9 * r + g));
}
|
[["+", 0, 2, 3, 4, 0, 16, 12, 16, 31, 13], ["+", 0, 2, 3, 4, 0, 16, 12, 16, 17, 48]]
| 0
| 85
| 2
|
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n && m != 0 && n != 0) {
list<int> a;
for (int i = 1; i <= m; i++)
a.push_back(i);
list<int>::iterator it = a.begin(), it2;
for (int z = 1; z <= n; z++) {
string b;
cin >> b;
if (a.size() != 0) {
if ((z % 3 == 0 && z % 5 != 0 && b == "Fizz") ||
(z % 5 == 0 && z % 3 != 0 && b == "Buzz") ||
(z % 5 == 0 && z % 3 == 0 && b == "FizzBuzz") ||
(z % 3 != 0 && z % 5 != 0 && b == to_string(z))) {
it++;
} else {
it2 = it;
it2++;
a.erase(it);
it = it2;
}
if (it == a.end()) {
it = a.begin();
}
}
}
it = a.begin();
while (it != a.end()) {
if (it == a.begin())
cout << (*it);
else
cout << " " << (*it);
it++;
}
cout << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n && m != 0 && n != 0) {
list<int> a;
for (int i = 1; i <= m; i++)
a.push_back(i);
list<int>::iterator it = a.begin(), it2;
for (int z = 1; z <= n; z++) {
string b;
cin >> b;
if (a.size() != 1) {
if ((z % 3 == 0 && z % 5 != 0 && b == "Fizz") ||
(z % 5 == 0 && z % 3 != 0 && b == "Buzz") ||
(z % 5 == 0 && z % 3 == 0 && b == "FizzBuzz") ||
(z % 3 != 0 && z % 5 != 0 && b == to_string(z))) {
it++;
} else {
it2 = it;
it2++;
a.erase(it);
it = it2;
}
if (it == a.end()) {
it = a.begin();
}
}
}
it = a.begin();
while (it != a.end()) {
if (it == a.begin())
cout << (*it);
else
cout << " " << (*it);
it++;
}
cout << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 308
| 2
|
#include <bits/stdc++.h>
using namespace std;
string fb[10001];
int main() {
for (int i = 1; i < 10001; i++) {
if (i % 15 == 0) {
fb[i] = "FizzBuzz";
} else if (i % 3 == 0) {
fb[i] = "Fizz";
} else if (i % 5 == 0) {
fb[i] = "Buzz";
} else {
stringstream ss;
ss << i;
ss >> fb[i];
}
}
while (1) {
int m, n;
scanf(" %d %d", &m, &n);
if (m == 0 && n == 0) {
break;
}
list<int> l;
for (int i = 1; i <= m; i++) {
l.push_back(i);
}
list<int>::iterator itr = l.begin();
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
if (l.size() == 0) {
continue;
}
if (s != fb[i]) {
list<int>::iterator itmp = itr;
itr++;
l.erase(itmp);
} else {
itr++;
}
if (itr == l.end()) {
itr = l.begin();
}
}
if (l.size() != 0) {
itr = l.begin();
cout << *itr;
itr++;
for (; itr != l.end(); itr++) {
cout << ' ' << *itr;
}
cout << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string fb[10001];
int main() {
for (int i = 1; i < 10001; i++) {
if (i % 15 == 0) {
fb[i] = "FizzBuzz";
} else if (i % 3 == 0) {
fb[i] = "Fizz";
} else if (i % 5 == 0) {
fb[i] = "Buzz";
} else {
stringstream ss;
ss << i;
ss >> fb[i];
}
}
while (1) {
int m, n;
scanf(" %d %d", &m, &n);
if (m == 0 && n == 0) {
break;
}
list<int> l;
for (int i = 1; i <= m; i++) {
l.push_back(i);
}
list<int>::iterator itr = l.begin();
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
if (l.size() == 1) {
continue;
}
if (s != fb[i]) {
list<int>::iterator itmp = itr;
itr++;
l.erase(itmp);
} else {
itr++;
}
if (itr == l.end()) {
itr = l.begin();
}
}
if (l.size() != 0) {
itr = l.begin();
cout << *itr;
itr++;
for (; itr != l.end(); itr++) {
cout << ' ' << *itr;
}
cout << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 345
| 2
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
string table[10001];
string itos(int n) {
stringstream ss;
ss << n;
return ss.str();
}
int main() {
for (int i = 1; i <= 10000; i++) {
if (i % 15 == 0) {
table[i] = "FizzBuzz";
} else if (i % 3 == 0) {
table[i] = "Fizz";
} else if (i % 5 == 0) {
table[i] = "Buzz";
} else {
table[i] = itos(i);
}
}
int n, m;
while (cin >> n >> m && n) {
vector<int> v(n);
for (int i = 0; i < n; i++)
v[i] = i;
int x = 0;
for (int z = 1; z <= m; z++) {
string s;
cin >> s;
if (v.size() == 1)
continue;
if (s != table[z]) {
v.erase(remove(v.begin(), v.end(), x), v.end());
} else {
x++;
}
x %= v.size();
}
for (int i = 0; i < v.size(); i++)
cout << v[i] + 1 << (v.size() - 1 == i ? "\n" : " ");
}
}
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
string table[10001];
string itos(int n) {
stringstream ss;
ss << n;
return ss.str();
}
int main() {
for (int i = 1; i <= 10000; i++) {
if (i % 15 == 0) {
table[i] = "FizzBuzz";
} else if (i % 3 == 0) {
table[i] = "Fizz";
} else if (i % 5 == 0) {
table[i] = "Buzz";
} else {
table[i] = itos(i);
}
}
int n, m;
while (cin >> n >> m && n) {
vector<int> v(n);
for (int i = 0; i < n; i++)
v[i] = i;
int x = 0;
for (int z = 1; z <= m; z++) {
string s;
cin >> s;
if (v.size() == 1)
continue;
if (s != table[z]) {
v.erase(remove(v.begin(), v.end(), v[x]), v.end());
} else {
x++;
}
x %= v.size();
}
for (int i = 0; i < v.size(); i++)
cout << v[i] + 1 << (v.size() - 1 == i ? "\n" : " ");
}
}
|
[["+", 3, 4, 0, 2, 3, 4, 0, 69, 28, 22], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73]]
| 1
| 321
| 3
|
#include <cstring>
#include <iostream>
#include <sstream>
struct person {
int num;
struct person *prev;
struct person *next;
};
struct person *head, *p, *now;
int m, n;
char s[128];
void set() {
for (int i = 0; i < m; i++) {
p[i].num = i + 1;
p[i].prev = p + i - 1;
p[i].next = p + i + 1;
}
p[0].prev = p + m - 1;
p[m - 1].next = p;
}
void del(struct person *a) {
(a->prev)->next = a->next;
(a->next)->prev = a->prev;
if (a == head)
head = a->next;
}
void show(struct person *a) {
std::cout << a->num;
if (a->next == head)
return;
else {
std::cout << ' ';
show(a->next);
}
}
int main() {
while (true) {
std::cin >> m >> n;
if (!m && !n)
return 0;
p = new struct person[m];
head = p;
now = head;
set();
for (int i = 0; i < n; i++) {
std::cin >> s;
if (now == now->next) {
i = n;
} else if ((i + 1) % 15 == 0) {
if (strcmp(s, "FizzBuzz") != 0)
del(now);
} else if ((i + 1) % 3 == 0) {
if (strcmp(s, "Fizz") != 0)
del(now);
} else if ((i + 1) % 5 == 0) {
if (strcmp(s, "Buzz") != 0)
del(now);
} else {
std::string str(s);
std::istringstream ss(str);
int a = 0;
ss >> a;
if (a != i + 1)
del(now);
}
now = now->next;
}
show(head);
std::cout << std::endl;
delete[] p;
}
}
|
#include <cstring>
#include <iostream>
#include <sstream>
struct person {
int num;
struct person *prev;
struct person *next;
};
struct person *head, *p, *now;
int m, n;
char s[128];
void set() {
for (int i = 0; i < m; i++) {
p[i].num = i + 1;
p[i].prev = p + i - 1;
p[i].next = p + i + 1;
}
p[0].prev = p + m - 1;
p[m - 1].next = p;
}
void del(struct person *a) {
(a->prev)->next = a->next;
(a->next)->prev = a->prev;
if (a == head)
head = a->next;
}
void show(struct person *a) {
std::cout << a->num;
if (a->next == head)
return;
else {
std::cout << ' ';
show(a->next);
}
}
int main() {
while (true) {
std::cin >> m >> n;
if (!m && !n)
return 0;
p = new struct person[m];
head = p;
now = head;
set();
for (int i = 0; i < n; i++) {
std::cin >> s;
if (now == now->next) {
continue;
} else if ((i + 1) % 15 == 0) {
if (strcmp(s, "FizzBuzz") != 0)
del(now);
} else if ((i + 1) % 3 == 0) {
if (strcmp(s, "Fizz") != 0)
del(now);
} else if ((i + 1) % 5 == 0) {
if (strcmp(s, "Buzz") != 0)
del(now);
} else {
std::string str(s);
std::istringstream ss(str);
int a = 0;
ss >> a;
if (a != i + 1)
del(now);
}
now = now->next;
}
show(head);
std::cout << std::endl;
delete[] p;
}
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117]]
| 1
| 473
| 4
|
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
// ply.erase(find(ply.begin(),ply.end(),3));
int m, n;
while (cin >> n >> m && !(n == 0 && m == 0)) {
vector<int> ply;
for (int i = 0; i < n; i++)
ply.push_back(i);
int tern = 0;
for (int i = 1; i <= m; i++) {
string str;
cin >> str;
if (ply.size() == 1)
break;
if (i % 3 == 0 & i % 5 == 0) {
if (str == "FizzBuzz") {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
} else if (i % 3 == 0) {
if (str == "Fizz") {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
} else if (i % 5 == 0) {
if (str == "Buzz") {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
} else {
int num = atoi(str.c_str());
if (num == i) {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
}
}
for (int i = 0; i < ply.size(); i++) {
cout << ply[i] + 1;
if (i != ply.size() - 1)
cout << " ";
else
cout << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
// ply.erase(find(ply.begin(),ply.end(),3));
int m, n;
while (cin >> n >> m && !(n == 0 && m == 0)) {
vector<int> ply;
for (int i = 0; i < n; i++)
ply.push_back(i);
int tern = 0;
bool f = false;
for (int i = 1; i <= m; i++) {
string str;
cin >> str;
if (ply.size() == 1)
continue;
if (i % 3 == 0 & i % 5 == 0) {
if (str == "FizzBuzz") {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
} else if (i % 3 == 0) {
if (str == "Fizz") {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
} else if (i % 5 == 0) {
if (str == "Buzz") {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
} else {
int num = atoi(str.c_str());
if (num == i) {
tern++;
tern %= ply.size();
} else {
ply.erase(find(ply.begin(), ply.end(), ply[tern]));
if (tern == ply.size()) {
tern = 0;
}
}
}
}
for (int i = 0; i < ply.size(); i++) {
cout << ply[i] + 1;
if (i != ply.size() - 1)
cout << " ";
else
cout << endl;
}
}
return 0;
}
|
[["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 49, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 147], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 0, 35], ["-", 0, 7, 8, 9, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 9, 0, 57, 64, 116, 0, 117]]
| 1
| 482
| 7
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
if (a < b)
a = b;
}
template <class T, class C> void chmin(T &a, C b) {
if (b < a)
a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }
string toRight(int i) {
if (i % 3 == 0 && i % 5 == 0)
return "FizzBuzz";
if (i % 3 == 0)
return "Fizz";
if (i % 5 == 0)
return "Buzz";
stringstream ss;
ss << i;
return ss.str();
}
int main() {
int n, m;
while (cin >> n >> m && n) {
vint v(n);
rep(i, n) v[i] = i + 1;
int p = 0;
bool flag = true;
rep(i, m) {
string in;
cin >> in;
if (flag && in != toRight(i + 1)) {
v.erase(v.begin() + p);
flag == v.size() != 1;
} else
p++;
p %= v.size();
}
rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : " ");
}
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
if (a < b)
a = b;
}
template <class T, class C> void chmin(T &a, C b) {
if (b < a)
a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }
string toRight(int i) {
if (i % 3 == 0 && i % 5 == 0)
return "FizzBuzz";
if (i % 3 == 0)
return "Fizz";
if (i % 5 == 0)
return "Buzz";
stringstream ss;
ss << i;
return ss.str();
}
int main() {
int n, m;
while (cin >> n >> m && n) {
vint v(n);
rep(i, n) v[i] = i + 1;
int p = 0;
bool flag = n != 1;
rep(i, m) {
string in;
cin >> in;
if (flag && in != toRight(i + 1)) {
v.erase(v.begin() + p);
flag = v.size() != 1;
} else
p++;
p %= v.size();
}
rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : " ");
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 146], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 79], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["-", 64, 9, 0, 1, 0, 16, 31, 16, 17, 60], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32]]
| 1
| 451
| 6
|
while(True):
m,n = map(int,input().split())
if not m: break
a = [True]*m
j = -1
for i in range(1,n+1):
if not sum(a): input(); continue
j = (j+1+((a+a)[j+1:]).index(True))%m
s = input()
if not i%15:
if s == "FizzBuzz": continue
else: a[j] = False; continue
if not i%5:
if s == "Buzz": continue
else: a[j] = False; continue
if not i%3:
if s == "Fizz": continue
else: a[j] = False; continue
if s != str(i): a[j] = False;continue
print(" ".join(str(e+1) for e in range(m) if a[e]))
|
while(True):
m,n = map(int,input().split())
if not m: break
a = [True]*m
j = -1
for i in range(1,n+1):
if sum(a) < 2: input(); continue
j = (j+1+((a+a)[j+1:]).index(True))%m
s = input()
if not i%15:
if s == "FizzBuzz": continue
else: a[j] = False; continue
if not i%5:
if s == "Buzz": continue
else: a[j] = False; continue
if not i%3:
if s == "Fizz": continue
else: a[j] = False; continue
if s != str(i): a[j] = False;continue
print(" ".join(str(e+1) for e in range(m) if a[e]))
|
[["-", 0, 7, 8, 196, 0, 57, 15, 681, 0, 372], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 612]]
| 5
| 210
| 3
|
while(True):
m,n = map(int,input().split())
if not m: break
a = list(range(1,m+1))
b = [input() for _ in range(n)]
t = [str(i+1) for i in range(n)]
t[2::3] = ["Fizz"]*len(t[2::3])
t[4::5] = ["Buzz"]*len(t[4::5])
t[14::15] = ["FizzBuzz"]*len(t[14::15])
i=0
for j in range(n):
if len(a) <2: break
if b[j] != t[j]: del a[i]; i = i if i > len(a) else 0; continue
i += 1
i = i%len(a)
print(" ".join(str(e) for e in a))
|
while(True):
m,n = map(int,input().split())
if not m: break
a = list(range(1,m+1))
b = [input() for _ in range(n)]
t = [str(i+1) for i in range(n)]
t[2::3] = ["Fizz"]*len(t[2::3])
t[4::5] = ["Buzz"]*len(t[4::5])
t[14::15] = ["FizzBuzz"]*len(t[14::15])
i=0
for j in range(n):
if len(a) <2: break
if b[j] != t[j]: del a[i]; i = 0 if i >= len(a) else i; continue
i += 1
i = i%len(a)
print(" ".join(str(e) for e in a))
|
[["-", 64, 196, 0, 1, 0, 662, 12, 41, 0, 22], ["+", 64, 196, 0, 1, 0, 662, 12, 41, 0, 612], ["-", 0, 1, 0, 662, 12, 41, 0, 666, 667, 47], ["+", 0, 1, 0, 662, 12, 41, 0, 666, 667, 20], ["-", 64, 196, 0, 1, 0, 662, 12, 41, 0, 612], ["+", 64, 196, 0, 1, 0, 662, 12, 41, 0, 22]]
| 5
| 222
| 6
|
def fizzbuzz(n):
if n%15==0: return "FizzBuzz"
if n%5==0: return "Buzz"
if n%3==0: return "Fizz"
return str(n)
while True:
m,n=list(map(int,input().split()))
if m==0:break
player=list(range(1,m+1))
p=0
for i in range(n):
if len(player)==1:
break
if fizzbuzz(i+1)!=input():
del player[p]
p%=len(player)
else:
p=(p+1)%len(player)
print(" ".join(map(str,player)))
|
def fizzbuzz(n):
if n%15==0: return "FizzBuzz"
if n%5==0: return "Buzz"
if n%3==0: return "Fizz"
return str(n)
while True:
try:
m,n=list(map(int,input().split()))
if m==0:break
player=list(range(1,m+1))
p=0
for i in range(n):
if len(player)==1:
break
if fizzbuzz(i+1)!=input():
del player[p]
p%=len(player)
else:
p=(p+1)%len(player)
print(" ".join(map(str,player)))
except:
pass
|
[["+", 0, 656, 0, 52, 8, 196, 0, 246, 0, 247], ["+", 0, 656, 0, 52, 8, 196, 0, 246, 0, 102], ["+", 0, 52, 8, 196, 0, 246, 0, 671, 0, 672], ["+", 0, 52, 8, 196, 0, 246, 0, 671, 0, 102], ["+", 0, 246, 0, 671, 0, 196, 0, 674, 0, 675]]
| 5
| 158
| 5
|
public class Main {
static int N = 10000001;
public void run(java.io.InputStream in, java.io.PrintStream out) {
java.util.Scanner sc = new java.util.Scanner(in);
int[] p;
int pn, i, n, a;
p = new int[N / 6];
pn = getprime(p);
for (;;) {
n = sc.nextInt();
if (n == 0)
break;
a = 13;
for (i = 6; p[i] <= n && i < pn; i++) {
if (p[i] - p[i - 1] == 2 && p[i] - p[i - 2] == 6 &&
p[i] - p[i - 3] == 8) {
a = p[i];
}
}
out.println(a + " " + pn);
}
sc.close();
}
public static void main(String[] args) {
(new Main()).run(System.in, System.out);
}
private static int getprime(int[] p) {
int i, j, count = 0;
boolean[] e;
e = new boolean[N];
e[0] = true;
e[1] = true;
for (i = 2; i < N; i++)
if (!e[i]) {
p[count++] = i;
for (j = i * 2; j < N; j += i)
e[j] = true;
}
return count;
}
}
|
public class Main {
static int N = 10000001;
public void run(java.io.InputStream in, java.io.PrintStream out) {
java.util.Scanner sc = new java.util.Scanner(in);
int[] p;
int pn, i, n, a;
p = new int[N / 6];
pn = getprime(p);
for (;;) {
n = sc.nextInt();
if (n == 0)
break;
a = 13;
for (i = 6; p[i] <= n && i < pn; i++) {
if (p[i] - p[i - 1] == 2 && p[i] - p[i - 2] == 6 &&
p[i] - p[i - 3] == 8) {
a = p[i];
}
}
out.println(a);
}
sc.close();
}
public static void main(String[] args) {
(new Main()).run(System.in, System.out);
}
private static int getprime(int[] p) {
int i, j, count = 0;
boolean[] e;
e = new boolean[N];
e[0] = true;
e[1] = true;
for (i = 2; i < N; i++)
if (!e[i]) {
p[count++] = i;
for (j = i * 2; j < N; j += i)
e[j] = true;
}
return count;
}
}
|
[["-", 0, 492, 3, 4, 0, 16, 31, 16, 17, 72], ["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 491], ["-", 0, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 492, 3, 4, 0, 16, 12, 22]]
| 3
| 335
| 6
|
import java.util.*;
public class Main {
private static final int mx = 10000000;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
boolean[] prime = (new boolean[mx]);
Arrays.fill(prime, true);
prime[0] = prime[1] = false;
for (int i = 2; i < mx; ++i)
if (prime[i])
for (int j = i + i; j < mx; j += i)
prime[j] = false;
while (sc.hasNext()) {
n = sc.nextInt();
if (n == 0)
break;
for (int i = n; i < mx; ++i)
if (prime[i - 8] && prime[i - 6] && prime[i - 2] && prime[i]) {
System.out.println(n);
break;
}
}
}
}
|
import java.util.*;
public class Main {
private static final int mx = 10000000;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
boolean[] prime = (new boolean[mx]);
Arrays.fill(prime, true);
prime[0] = prime[1] = false;
for (int i = 2; i < mx; ++i)
if (prime[i])
for (int j = i + i; j < mx; j += i)
prime[j] = false;
while (sc.hasNext()) {
n = sc.nextInt();
if (n == 0)
break;
for (int i = n; i >= 13; --i)
if (prime[i - 8] && prime[i - 6] && prime[i - 2] && prime[i]) {
System.out.println(i);
break;
}
}
}
}
|
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 499], ["-", 0, 52, 8, 196, 0, 7, 26, 27, 0, 29], ["+", 0, 52, 8, 196, 0, 7, 26, 27, 0, 68], ["-", 64, 196, 0, 1, 0, 492, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 492, 3, 4, 0, 22]]
| 3
| 206
| 8
|
#include <stdio.h>
char prime[10000001];
void SetPrime(int max) {
int i, j;
for (i = 4; i <= max; i += 2) {
prime[i] = 1;
}
for (i = 3; i * i <= max; i += 2) {
if (prime[i] == 0) {
for (j = i * 2; j <= max; j += i) {
prime[j] = 1;
}
}
}
}
int main(void) {
long n;
SetPrime(10000000);
while (scanf("%ld", &n) * n != 0) {
long i;
if (n % 2 == 0)
n--;
for (i = n; i >= 10; i -= 2) {
if (prime[i] + prime[i - 2] + prime[i - 6] + prime[i - 8] == 0) {
printf("%l1d\n", i);
break;
}
}
}
return 0;
}
|
#include <stdio.h>
char prime[10000001];
void SetPrime(int max) {
int i, j;
for (i = 4; i <= max; i += 2) {
prime[i] = 1;
}
for (i = 3; i * i <= max; i += 2) {
if (prime[i] == 0) {
for (j = i * 2; j <= max; j += i) {
prime[j] = 1;
}
}
}
}
int main(void) {
long n;
SetPrime(10000000);
while (scanf("%ld", &n) * n != 0) {
long i;
if (n % 2 == 0)
n--;
for (i = n; i >= 10; i -= 2) {
if (prime[i] + prime[i - 2] + prime[i - 6] + prime[i - 8] == 0) {
printf("%ld\n", i);
break;
}
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 208
| 2
|
/*
*/
#include <stdio.h>
int max = 10000000;
short prime[10000000];
void make_prime() {
int i, p, n;
for (i = 0; i <= max; i++) {
prime[i] = 1;
}
prime[0] = 0;
prime[1] = 0;
for (p = 2; p <= max; p++) {
if (prime[p]) {
for (n = p + p; n <= max; n += p) {
prime[n] = 0;
}
}
}
}
int main() {
short n;
make_prime();
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
} else if (n >= 13 && n <= 10000000) {
while (1) {
if (prime[n]) {
if (prime[n - 2]) {
if (prime[n - 6]) {
if (prime[n - 8]) {
printf("%d\n", n);
break;
}
}
}
}
n--;
}
}
}
return 0;
}
|
/*
*/
#include <stdio.h>
int max = 10000000;
short prime[10000000];
void make_prime() {
int i, p, n;
for (i = 0; i <= max; i++) {
prime[i] = 1;
}
prime[0] = 0;
prime[1] = 0;
for (p = 2; p <= max; p++) {
if (prime[p]) {
for (n = p + p; n <= max; n += p) {
prime[n] = 0;
}
}
}
}
int main() {
int n;
make_prime();
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
} else if (n >= 13 && n <= 10000000) {
while (1) {
if (prime[n]) {
if (prime[n - 2]) {
if (prime[n - 6]) {
if (prime[n - 8]) {
printf("%d\n", n);
break;
}
}
}
}
n--;
}
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 39, 86, 0, 133], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40]]
| 0
| 230
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define MAX 10000100
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
bool sosu[MAX];
int main() {
bool sosu[MAX];
memset(sosu, true, MAX);
for (int i = 4; i < MAX; i += 2)
sosu[i] = false;
for (int i = 3; i < MAX; i += 2)
for (int j = 3 * i; j < MAX; j += 2 * i)
sosu[j] = false;
int n;
while (cin >> n, n) {
for (int i = n; i >= 0; i--) {
if (sosu[i] && sosu[i - 2] && sosu[i - 6] & sosu[i - 8]) {
cout << i << endl;
break;
}
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define MAX 10000100
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
bool sosu[MAX];
int main() {
memset(sosu, true, MAX);
for (int i = 4; i < MAX; i += 2)
sosu[i] = false;
for (int i = 3; i < MAX; i += 2)
for (int j = 3 * i; j < MAX; j += 2 * i)
sosu[j] = false;
int n;
while (cin >> n, n) {
for (int i = n; i >= 0; i--) {
if (sosu[i] && sosu[i - 2] && sosu[i - 6] & sosu[i - 8]) {
cout << i << endl;
break;
}
}
}
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 49, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 0, 70], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 0, 73], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35]]
| 1
| 243
| 6
|
#include <algorithm>
#include <iostream>
using namespace std;
bool prime[1000000001];
int main() {
for (int i = 3; i * i <= 1000000000; i += 2) {
if (!prime[i]) {
for (int j = i * 2; j <= 1000000000; j += i) {
prime[j] = true;
}
}
}
int n;
while (cin >> n, n) {
for (;; n--) {
if (!prime[n] && !prime[n - 2] && !prime[n - 6] && !prime[n - 8] &&
n % 2 != 0) {
cout << n << endl;
break;
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
bool prime[10000001];
int main() {
for (int i = 3; i * i <= 10000000; i += 2) {
if (!prime[i]) {
for (int j = i * 2; j <= 10000000; j += i) {
prime[j] = true;
}
}
}
int n;
while (cin >> n, n) {
for (;; n--) {
if (!prime[n] && !prime[n - 2] && !prime[n - 6] && !prime[n - 8] &&
n % 2 != 0) {
cout << n << endl;
break;
}
}
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 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
| 148
| 6
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
int main() {
const int N = 10000000;
deque<bool> isp(N + 1, true);
isp[0] = isp[1] = false;
rep(i, N + 1) if (isp[i]) for (int j = i + i; j <= N; j += i) isp[j] = false;
for (int n; cin >> n, n;) {
for (int i = n;; i--)
if (isp[i] && isp[i - 2] && isp[i - 6] && isp[i - 6]) {
cout << i << endl;
break;
}
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
int main() {
const int N = 10000000;
deque<bool> isp(N + 1, true);
isp[0] = isp[1] = false;
rep(i, N + 1) if (isp[i]) for (int j = i + i; j <= N; j += i) isp[j] = false;
for (int n; cin >> n, n;) {
for (int i = n;; i--)
if (isp[i] && isp[i - 2] && isp[i - 6] && isp[i - 8]) {
cout << i << endl;
break;
}
}
return 0;
}
|
[["-", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 308
| 2
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int answer;
int b, r, g, c, s, t;
cin >> b >> r >> g >> c >> s >> t;
if (b == 0) {
break;
}
int bonus = b * 5 + r * 3;
answer = 100 + b * 15 + r * 15 + bonus * 15 + g * 7 + c * 2 -
((t - s - bonus) * 3) - (bonus * 2);
cout << answer << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int answer;
int b, r, g, c, s, t;
cin >> b >> r >> g >> c >> s >> t;
if (t == 0) {
break;
}
int bonus = b * 5 + r * 3;
answer = 100 + b * 15 + r * 15 + bonus * 15 + g * 7 + c * 2 -
((t - s - bonus) * 3) - (bonus * 2);
cout << answer << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
| 1
| 120
| 2
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int b, r, g, c, s, t;
while (true) {
cin >> b >> r >> g >> c >> s >> t;
if (b == 0)
break;
int out = 100 - (t * 3) + (s * 3) + (c * 2) + (g * 7) + ((r + b) * 15) +
((r * 3 + b * 5) * 16);
cout << out << endl;
}
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int b, r, g, c, s, t;
while (true) {
cin >> b >> r >> g >> c >> s >> t;
if (t == 0)
break;
int out = 100 - (t * 3) + (s * 3) + (c * 2) + (g * 7) + ((r + b) * 15) +
((r * 3 + b * 5) * 16);
cout << out << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
| 1
| 146
| 2
|
#include <iostream>
using namespace std;
int main() {
int b, r, g, c, s, t;
while (cin >> b >> r >> g >> c >> s >> t) {
if (b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t)
break;
int point = 100;
point += b * 15;
point += (b * 5) * 16;
point += r * 15;
point += (r * 3) * 16;
point += g * 7;
point += c * 2;
point += s * 3;
point -= t * 3;
cout << point << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int b, r, g, c, s, t;
while (cin >> b >> r >> g >> c >> s >> t) {
if (b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0)
break;
int point = 100;
point += b * 15;
point += (b * 5) * 16;
point += r * 15;
point += (r * 3) * 16;
point += g * 7;
point += c * 2;
point += s * 3;
point -= t * 3;
cout << point << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 139
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int n, b[2][128];
int rec1(int x, int y) {
if (b[x][y + 1] == 1)
return rec1(x, y + 1);
return y;
}
int rec2(int x, int y) {
if (b[x][y] == 2)
return rec2(x, y - 1);
return y;
}
int main() {
while (scanf("%d", &n) && n) {
rep(i, 2) rep(j, n) scanf("%d", &b[i][j]);
queue<pii> q;
q.push(MP(0, MP(0, 0)));
q.push(MP(1, MP(0, 0)));
map<pi, int> m;
m[MP(0, 0)] = 1;
m[MP(1, 0)] = 0;
int res = -1;
while (!q.empty()) {
pii now = q.front();
q.pop();
// printf("%d %d %d\n", now.F, now.S.F, now.S.S);
if (b[now.F][now.S.F] == 1)
now.S.F = rec1(now.F, now.S.F);
else if (b[now.F][now.S.F] == 2)
now.S.F = rec2(now.F, now.S.F);
if (now.S.F == n - 1) {
res = now.S.S;
break;
}
rep(i, 3) {
pii next = now;
next.F = (next.F + 1) % 2;
next.S.F += i;
next.S.S++;
if (m.count(MP(next.F, next.S.F)))
continue;
m[MP(next.F, next.S.F)] = next.S.S;
q.push(next);
}
}
if (res < 0)
puts("NA");
else
printf("%d\n", res);
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int n, b[2][128];
int rec1(int x, int y) {
if (b[x][y + 1] == 1)
return rec1(x, y + 1);
return y;
}
int rec2(int x, int y) {
if (b[x][y] == 2)
return rec2(x, y - 1);
return y;
}
int main() {
while (scanf("%d", &n) && n) {
rep(i, 2) rep(j, n) scanf("%d", &b[i][j]);
queue<pii> q;
q.push(MP(0, MP(0, 0)));
q.push(MP(1, MP(0, 0)));
map<pi, int> m;
m[MP(0, 0)] = 1;
m[MP(1, 0)] = 0;
int res = -1;
while (!q.empty()) {
pii now = q.front();
q.pop();
// printf("%d %d %d\n", now.F, now.S.F, now.S.S);
if (b[now.F][now.S.F] == 1)
now.S.F = rec1(now.F, now.S.F);
else if (b[now.F][now.S.F] == 2)
now.S.F = rec2(now.F, now.S.F);
if (now.S.F >= n - 1) {
res = now.S.S;
break;
}
rep(i, 3) {
pii next = now;
next.F = (next.F + 1) % 2;
next.S.F += i;
next.S.S++;
if (m.count(MP(next.F, next.S.F)))
continue;
m[MP(next.F, next.S.F)] = next.S.S;
q.push(next);
}
}
if (res < 0)
puts("NA");
else
printf("%d\n", res);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 570
| 2
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
while (true) {
int N;
int Num[200];
scanf("%d", &N);
if (N == 0)
break;
for (int i = 0; i < 2 * N; i++)
scanf("%d", &Num[i]);
bool G[200][200];
for (int i = 0; i < 2 * N; i++) {
for (int j = 0; j < 2 * N; j++) {
G[i][j] = false;
}
}
for (int i = 0; i < N; i++) {
if (Num[i] == 0) {
for (int k = i + N; k < i + N + 3 && k < 2 * N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < 2 * N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= N + 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else if (Num[i] == 1) {
int l = i;
while (l < 2 * N && Num[l] == 1) {
l++;
}
l--;
for (int k = l + N; k < l + N + 3 && k < 2 * N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < 2 * N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= N + 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else {
int l = i;
while (l >= 1 && Num[l] == 2)
l--;
for (int k = l + N; k < l + N + 3 && k < 2 * N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < 2 * N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= N + 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
}
}
for (int i = N; i < 2 * N; i++) {
if (Num[i] == 0) {
for (int k = i - N; k < i - N + 3 && k < N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else if (Num[i] == 1) {
int l = i;
while (l < N && Num[l] == 1) {
l++;
}
l--;
for (int k = l - N; k < l - N + 3 && k < N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else {
int l = i;
while (l >= N + 1 && Num[l] == 2)
l--;
for (int k = l - N; k < l - N + 3 && k < N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
}
}
int SS[200];
for (int i = 0; i < 200; i++)
SS[i] = 1000;
SS[0] = 0;
SS[N] = 0;
if (Num[0] == 1) {
int I = 0;
while (Num[I] == 1 && I < N) {
SS[I] = 0;
I++;
}
SS[I] = 1000;
}
if (Num[N] == 1) {
int I = N;
while (Num[I] == 1 && I < 2 * N) {
SS[I] = 0;
I++;
}
SS[I] = 1000;
}
for (int k = 0; k < 2 * N; k++) {
for (int i = 0; i < 2 * N; i++) {
for (int j = 0; j < 2 * N; j++) {
if (G[j][i]) {
SS[i] = min(SS[i], SS[j] + 1);
}
}
}
}
int ans = min(SS[N - 1], SS[2 * N - 1]);
if (ans == 1000)
printf("NA\n");
else
printf("%d\n", ans);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
while (true) {
int N;
int Num[200];
scanf("%d", &N);
if (N == 0)
break;
for (int i = 0; i < 2 * N; i++)
scanf("%d", &Num[i]);
bool G[200][200];
for (int i = 0; i < 2 * N; i++) {
for (int j = 0; j < 2 * N; j++) {
G[i][j] = false;
}
}
for (int i = 0; i < N; i++) {
if (Num[i] == 0) {
for (int k = i + N; k < i + N + 3 && k < 2 * N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < 2 * N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= N + 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else if (Num[i] == 1) {
int l = i;
while (l < N && Num[l] == 1) {
l++;
}
l--;
for (int k = l + N; k < l + N + 3 && k < 2 * N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < 2 * N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= N + 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else {
int l = i;
while (l >= 1 && Num[l] == 2)
l--;
for (int k = l + N; k < l + N + 3 && k < 2 * N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < 2 * N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= N + 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
}
}
for (int i = N; i < 2 * N; i++) {
if (Num[i] == 0) {
for (int k = i - N; k < i - N + 3 && k < N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else if (Num[i] == 1) {
int l = i;
while (l < 2 * N && Num[l] == 1) {
l++;
}
l--;
for (int k = l - N; k < l - N + 3 && k < N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
} else {
int l = i;
while (l >= N + 1 && Num[l] == 2)
l--;
for (int k = l - N; k < l - N + 3 && k < N; k++) {
if (Num[k] == 1) {
int j = k;
while (j < N && Num[j] == 1) {
j++;
}
G[i][j - 1] = true;
} else if (Num[k] == 2) {
int j = k;
while (j >= 1 && Num[j] == 2) {
j--;
}
G[i][j] = true;
} else {
G[i][k] = true;
}
}
}
}
int SS[200];
for (int i = 0; i < 200; i++)
SS[i] = 1000;
SS[0] = 0;
SS[N] = 0;
if (Num[0] == 1) {
int I = 0;
while (Num[I] == 1 && I < N) {
SS[I] = 0;
I++;
}
SS[I] = 1000;
}
if (Num[N] == 1) {
int I = N;
while (Num[I] == 1 && I < 2 * N) {
SS[I] = 0;
I++;
}
SS[I] = 1000;
}
for (int k = 0; k < 2 * N; k++) {
for (int i = 0; i < 2 * N; i++) {
for (int j = 0; j < 2 * N; j++) {
if (G[j][i]) {
SS[i] = min(SS[i], SS[j] + 1);
}
}
}
}
int ans = min(SS[N - 1], SS[2 * N - 1]);
if (ans == 1000)
printf("NA\n");
else
printf("%d\n", ans);
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 31, 13], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 48], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 31, 13], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 48]]
| 1
| 1,392
| 4
|
#include <iostream>
using namespace std;
int bill[2][100];
int n;
bool visited[2][100];
int jump(int, int, int);
main() {
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
cin >> bill[i][j];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
visited[i][j] = false;
}
}
int count1 = jump(0, 0, 0);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
visited[i][j] = false;
}
}
int count2 = jump(0, 1, 0);
if (count1 == -1 && count2 == -1)
cout << "NA" << endl;
else if (count1 >= count2)
cout << count1 << endl;
else
cout << count2 << endl;
}
return 0;
}
int jump(int count, int b, int h) {
if (bill[b][h] == 1) {
while (1) {
if (h == n - 1)
break;
if (bill[b][h + 1] != 1)
break;
h++;
}
} else if (bill[b][h] == 2) {
while (1) {
if (h == 0)
break;
if (bill[b][h - 1] != 2)
break;
h--;
}
}
if (visited[b][h])
return -1;
visited[b][h] = true;
if (h == n - 1)
return count;
if (b == 1)
b = 0;
else
b = 1;
if (h == n - 2)
return jump(count + 1, b, h + 1);
return jump(count + 1, b, h + 2);
}
|
#include <iostream>
using namespace std;
int bill[2][100];
int n;
bool visited[2][100];
int jump(int, int, int);
main() {
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
cin >> bill[i][j];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
visited[i][j] = false;
}
}
int count1 = jump(0, 0, 0);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
visited[i][j] = false;
}
}
int count2 = jump(0, 1, 0);
if (count1 == -1 && count2 == -1)
cout << "NA" << endl;
else if (count1 <= count2)
cout << count1 << endl;
else
cout << count2 << endl;
}
return 0;
}
int jump(int count, int b, int h) {
if (bill[b][h] == 1) {
while (1) {
if (h == n - 1)
break;
if (bill[b][h + 1] != 1)
break;
h++;
}
} else if (bill[b][h] == 2) {
while (1) {
if (h == 0)
break;
if (bill[b][h] != 2)
break;
h--;
}
}
if (visited[b][h])
return -1;
visited[b][h] = true;
if (h == n - 1)
return count;
if (b == 1)
b = 0;
else
b = 1;
if (h == n - 2)
return jump(count + 1, b, h + 1);
return jump(count + 1, b, h + 2);
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 447
| 4
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
const int N = 200;
const int inf = (1 << 20);
int cost[2][N];
int in[2][N];
int getheight(int n, int ind, int i) {
if (in[ind][i] == 1) {
int hi = i;
rep(j, n) {
if (in[ind][j] != 1)
break;
hi = j;
}
return hi;
} else if (in[ind][i] == 2) {
int lo = i;
for (int j = i; j >= 0; j--) {
lo = j;
if (in[ind][j] != 2)
break;
}
return lo;
}
return i;
}
class st {
public:
int p;
int h;
int cost;
};
void bfs(int n) {
rep(i, 2) rep(j, n) cost[i][j] = inf;
queue<st> Q;
int a = getheight(n, 0, 0), b = getheight(n, 1, 0);
Q.push((st){0, a, 0});
Q.push((st){1, b, 0});
cost[0][a] = 0;
cost[1][b] = 0;
while (!Q.empty()) {
st now = Q.front();
Q.pop();
if (now.h == n - 1) {
cout << now.cost << endl;
return;
}
rep(i, 3) {
if (now.h + i == n)
break;
int nextp = 1 - now.p, nexth = getheight(n, 1 - now.p, now.h + i);
if (cost[nextp][nexth] == inf) {
cost[nextp][nexth] = now.cost + 1;
Q.push((st){nextp, nexth, cost[nextp][nexth]});
}
}
}
cout << "NA" << endl;
}
main() {
int n;
while (cin >> n && n) {
rep(i, 2) {
rep(j, n) { cin >> in[i][j]; }
}
bfs(n);
}
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
const int N = 200;
const int inf = (1 << 20);
int cost[2][N];
int in[2][N];
int getheight(int n, int ind, int i) {
if (in[ind][i] == 1) {
int hi = i;
REP(j, i, n) {
if (in[ind][j] != 1)
break;
hi = j;
}
return hi;
} else if (in[ind][i] == 2) {
int lo = i;
for (int j = i; j >= 0; j--) {
lo = j;
if (in[ind][j] != 2)
break;
}
return lo;
}
return i;
}
class st {
public:
int p;
int h;
int cost;
};
void bfs(int n) {
rep(i, 2) rep(j, n) cost[i][j] = inf;
queue<st> Q;
int a = getheight(n, 0, 0), b = getheight(n, 1, 0);
Q.push((st){0, a, 0});
Q.push((st){1, b, 0});
cost[0][a] = 0;
cost[1][b] = 0;
while (!Q.empty()) {
st now = Q.front();
Q.pop();
if (now.h == n - 1) {
cout << now.cost << endl;
return;
}
rep(i, 3) {
if (now.h + i == n)
break;
int nextp = 1 - now.p, nexth = getheight(n, 1 - now.p, now.h + i);
if (cost[nextp][nexth] == inf) {
cost[nextp][nexth] = now.cost + 1;
Q.push((st){nextp, nexth, cost[nextp][nexth]});
}
}
}
cout << "NA" << endl;
}
main() {
int n;
while (cin >> n && n) {
rep(i, 2) {
rep(j, n) { cin >> in[i][j]; }
}
bfs(n);
}
}
|
[["-", 0, 57, 64, 9, 0, 14, 49, 53, 49, 22], ["+", 0, 57, 64, 9, 0, 14, 49, 53, 49, 22], ["+", 64, 9, 0, 14, 49, 53, 54, 55, 0, 21], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
| 1
| 538
| 4
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int dp[2][103];
int n;
int bill[2][103];
while (cin >> n, n) {
rep(i, 2) rep(j, 103) dp[i][j] = (1 << 21);
rep(i, 2) rep(j, 103) bill[i][j] = 0;
rep(i, 2) rep(j, n) cin >> bill[i][j];
dp[0][0] = dp[1][0] = 0;
rep(loop, n + 1000) {
rep(i, n) {
rep(bit, 2) {
if (bill[bit][i] == 1) {
if (bill[bit][i + 1] == 1) {
dp[bit][i + 1] = min(dp[bit][i + 1], dp[bit][i]);
} else {
dp[bit ^ 1][i] = min(dp[bit ^ 1][i], dp[bit][i] + 1);
dp[bit ^ 1][i + 1] = min(dp[bit ^ 1][i + 1], dp[bit][i] + 1);
dp[bit ^ 1][i + 2] = min(dp[bit ^ 1][i + 2], dp[bit][i] + 1);
}
} else if (bill[bit][i] == 2) {
dp[bit][i - 1] = min(dp[bit][i - 1], dp[bit][i]);
} else if (bill[bit][i] == 0) {
dp[bit ^ 1][i] = min(dp[bit ^ 1][i], dp[bit][i] + 1);
dp[bit ^ 1][i + 1] = min(dp[bit ^ 1][i + 1], dp[bit][i] + 1);
dp[bit ^ 1][i + 2] = min(dp[bit ^ 1][i + 2], dp[bit][i] + 1);
}
}
}
}
rep(bit, 2) {
if (dp[bit][n - 1] != 2)
dp[bit][n] = min(dp[bit][n - 1], dp[bit][n]);
}
int ret = min(dp[0][n], dp[1][n]);
if (ret != (1 << 21)) {
cout << ret << endl;
} else {
cout << "NA" << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int dp[2][103];
int n;
int bill[2][103];
while (cin >> n, n) {
rep(i, 2) rep(j, 103) dp[i][j] = (1 << 21);
rep(i, 2) rep(j, 103) bill[i][j] = 0;
rep(i, 2) rep(j, n) cin >> bill[i][j];
dp[0][0] = dp[1][0] = 0;
rep(loop, n + 1000) {
rep(i, n) {
rep(bit, 2) {
if (bill[bit][i] == 1) {
if (bill[bit][i + 1] == 1) {
dp[bit][i + 1] = min(dp[bit][i + 1], dp[bit][i]);
} else {
dp[bit ^ 1][i] = min(dp[bit ^ 1][i], dp[bit][i] + 1);
dp[bit ^ 1][i + 1] = min(dp[bit ^ 1][i + 1], dp[bit][i] + 1);
dp[bit ^ 1][i + 2] = min(dp[bit ^ 1][i + 2], dp[bit][i] + 1);
}
} else if (bill[bit][i] == 2) {
dp[bit][i - 1] = min(dp[bit][i - 1], dp[bit][i]);
} else if (bill[bit][i] == 0) {
dp[bit ^ 1][i] = min(dp[bit ^ 1][i], dp[bit][i] + 1);
dp[bit ^ 1][i + 1] = min(dp[bit ^ 1][i + 1], dp[bit][i] + 1);
dp[bit ^ 1][i + 2] = min(dp[bit ^ 1][i + 2], dp[bit][i] + 1);
}
}
}
}
rep(bit, 2) {
if (bill[bit][n - 1] != 2)
dp[bit][n] = min(dp[bit][n - 1], dp[bit][n]);
}
int ret = min(dp[0][n], dp[1][n]);
if (ret != (1 << 21)) {
cout << ret << endl;
} else {
cout << "NA" << endl;
}
}
}
|
[["-", 15, 339, 51, 16, 31, 69, 28, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 28, 69, 28, 22]]
| 1
| 613
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int f(int a[][100], int b[][100], int p, int q, int r, int n) {
int mn = -1;
if (a[p][q] == 1)
for (; q < n && a[p][q + 1] == 1; q++)
;
else if (a[p][q] == 2) {
for (; q > -1 && a[p][q] == 2; q--)
;
if (q == -1)
return -1;
}
if (q >= n)
return r;
if (b[p][q] == -1 || b[p][q] > r) {
int tmp;
b[p][q] = r;
if ((tmp = f(a, b, (p + 1) % 2, q, r + 1, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if ((tmp = f(a, b, (p + 1) % 2, q + 1, r + 1, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if ((tmp = f(a, b, (p + 1) % 2, q + 2, r + 1, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
}
return mn;
}
int main() {
int i, j;
int a[2][100], b[2][100], n;
int mn, tmp;
while (cin >> n && n) {
for (i = 0; i < 2; i++)
for (j = 0; j < n; j++)
cin >> a[i][j];
memset(b, -1, sizeof(b));
mn = -1;
if ((tmp = f(a, b, 0, 0, 0, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if ((tmp = f(a, b, 1, 0, 0, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if (mn == -1)
cout << "NA" << endl;
else
cout << mn << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int f(int a[][100], int b[][100], int p, int q, int r, int n) {
int mn = -1;
if (a[p][q] == 1)
for (; q + 1 < n && a[p][q + 1] == 1; q++)
;
else if (a[p][q] == 2) {
for (; q > -1 && a[p][q] == 2; q--)
;
if (q == -1)
return -1;
}
if (q >= n - 1)
return r;
if (b[p][q] == -1 || b[p][q] > r) {
int tmp;
b[p][q] = r;
if ((tmp = f(a, b, (p + 1) % 2, q, r + 1, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if ((tmp = f(a, b, (p + 1) % 2, q + 1, r + 1, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if ((tmp = f(a, b, (p + 1) % 2, q + 2, r + 1, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
}
return mn;
}
int main() {
int i, j;
int a[2][100], b[2][100], n;
int mn, tmp;
while (cin >> n && n) {
for (i = 0; i < 2; i++)
for (j = 0; j < n; j++)
cin >> a[i][j];
memset(b, -1, sizeof(b));
mn = -1;
if ((tmp = f(a, b, 0, 0, 0, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if ((tmp = f(a, b, 1, 0, 0, n)) != -1) {
if (mn == -1 || mn > tmp)
mn = tmp;
}
if (mn == -1)
cout << "NA" << endl;
else
cout << mn << endl;
}
return 0;
}
|
[["+", 64, 7, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 64, 7, 15, 16, 31, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 533
| 4
|
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
int n;
int bill[2][102];
bool mem[2][102];
const int INF = 1000000000;
int count;
int DFS(int i, int j) {
mem[i][j] = true;
while (bill[i][j] == 1 && bill[i][j + 1] == 1)
j++;
while (bill[i][j] == 2)
j--;
if (j >= n - 1)
return count;
if (i == 0) {
if (mem[1][j + 2] == false) {
count++;
return DFS(1, j + 2);
}
} else {
if (mem[1][j + 2] == false) {
count++;
return DFS(0, j + 2);
}
}
return INF;
}
int main() {
while (cin >> n) {
if (!n)
break;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
cin >> bill[i][j];
}
}
memset(mem, false, sizeof(mem));
count = 0;
int ans = DFS(0, 0);
memset(mem, false, sizeof(mem));
count = 0;
ans = min(ans, DFS(1, 0));
if (ans == INF)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
int n;
int bill[2][102];
bool mem[2][102];
const int INF = 1000000000;
int count;
int DFS(int i, int j) {
mem[i][j] = true;
while (bill[i][j] == 1 && bill[i][j + 1] == 1)
j++;
while (bill[i][j] == 2)
j--;
if (j >= n - 1)
return count;
if (i == 0) {
if (mem[1][j + 2] == false) {
count++;
return DFS(1, j + 2);
}
} else {
if (mem[0][j + 2] == false) {
count++;
return DFS(0, j + 2);
}
}
return INF;
}
int main() {
while (cin >> n) {
if (!n)
break;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
cin >> bill[i][j];
}
}
memset(mem, false, sizeof(mem));
count = 0;
int ans = DFS(0, 0);
memset(mem, false, sizeof(mem));
count = 0;
ans = min(ans, DFS(1, 0));
if (ans == INF)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["-", 51, 16, 31, 69, 28, 69, 341, 342, 0, 13], ["+", 51, 16, 31, 69, 28, 69, 341, 342, 0, 13]]
| 1
| 329
| 2
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
void solve() {
int n;
while (cin >> n, n) {
vector<vector<int>> Buil(2, vector<int>(n + 2));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < n; ++j) {
cin >> Buil[i][j];
}
}
queue<PP> Que;
Que.push(PP(P(0, 0), 0));
Que.push(PP(P(1, 0), 0));
bool used[2][101];
memset(used, 0, sizeof(used));
while (!Que.empty()) {
PP pp = Que.front();
Que.pop();
if (Buil[pp.first.first][pp.first.second] == 1) {
while (pp.first.first < n &&
Buil[pp.first.first][pp.first.second] == 1) {
++pp.first.second;
}
--pp.first.second;
} else if (Buil[pp.first.first][pp.first.second] == 2) {
while (Buil[pp.first.first][pp.first.second] == 2) {
--pp.first.second;
}
}
if (used[pp.first.first][pp.first.second]) {
continue;
}
used[pp.first.first][pp.first.second] = true;
if (pp.first.second >= n - 1) {
cout << pp.second << endl;
goto END;
}
for (int i = 0; i < 3; ++i) {
Que.push(PP(P(!pp.first.first, pp.first.second + i), pp.second + 1));
}
}
cout << "NG" << endl;
END:;
}
}
int main() {
solve();
return (0);
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
void solve() {
int n;
while (cin >> n, n) {
vector<vector<int>> Buil(2, vector<int>(n + 2));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < n; ++j) {
cin >> Buil[i][j];
}
}
queue<PP> Que;
Que.push(PP(P(0, 0), 0));
Que.push(PP(P(1, 0), 0));
bool used[2][101];
memset(used, 0, sizeof(used));
while (!Que.empty()) {
PP pp = Que.front();
Que.pop();
if (Buil[pp.first.first][pp.first.second] == 1) {
while (pp.first.first < n &&
Buil[pp.first.first][pp.first.second] == 1) {
++pp.first.second;
}
--pp.first.second;
} else if (Buil[pp.first.first][pp.first.second] == 2) {
while (Buil[pp.first.first][pp.first.second] == 2) {
--pp.first.second;
}
}
if (used[pp.first.first][pp.first.second]) {
continue;
}
used[pp.first.first][pp.first.second] = true;
if (pp.first.second >= n - 1) {
cout << pp.second << endl;
goto END;
}
for (int i = 0; i < 3; ++i) {
Que.push(PP(P(!pp.first.first, pp.first.second + i), pp.second + 1));
}
}
cout << "NA" << endl;
END:;
}
}
int main() {
solve();
return (0);
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 459
| 2
|
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define INF 1 << 20
struct node {
int kind, h, step;
node() { this->kind = this->h = this->step = 0; }
node(int kind, int h, int step) : kind(kind), h(h), step(step) {}
};
int main() {
int H;
while (cin >> H, H) {
vector<vector<int>> state(2, vector<int>(H + 1, 0));
for (int i = 0; i < 2; ++i)
for (int j = 0; j < H; ++j)
cin >> state[i][j];
vector<vector<int>> steps(2, vector<int>(H));
for (int i = 0; i < 2; ++i)
for (int j = 0; j < H; ++j)
steps[i][j] = -1;
int ans = -1;
queue<node> que;
que.push(node(0, 0, 0));
que.push(node(1, 0, 0));
while (!que.empty()) {
node n = que.front();
que.pop();
if (n.h >= H)
continue;
if (state[n.kind][n.h] == 2)
while (state[n.kind][--n.h] != 2)
;
else if (state[n.kind][n.h] == 1) {
while (state[n.kind][++n.h] != 1)
;
--n.h;
}
if (n.h == H - 1) {
ans = n.step;
break;
}
if (steps[n.kind][n.h] >= 0)
continue;
steps[n.kind][n.h] = n.step;
que.push(node(!n.kind, n.h, n.step + 1));
que.push(node(!n.kind, n.h + 1, n.step + 1));
que.push(node(!n.kind, n.h + 2, n.step + 1));
}
if (ans >= 0)
cout << ans << endl;
else
cout << "NA" << endl;
}
}
|
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define INF 1 << 20
struct node {
int kind, h, step;
node() { this->kind = this->h = this->step = 0; }
node(int kind, int h, int step) : kind(kind), h(h), step(step) {}
};
int main() {
int H;
while (cin >> H, H) {
vector<vector<int>> state(2, vector<int>(H + 1, 0));
for (int i = 0; i < 2; ++i)
for (int j = 0; j < H; ++j)
cin >> state[i][j];
vector<vector<int>> steps(2, vector<int>(H));
for (int i = 0; i < 2; ++i)
for (int j = 0; j < H; ++j)
steps[i][j] = -1;
int ans = -1;
queue<node> que;
que.push(node(0, 0, 0));
que.push(node(1, 0, 0));
while (!que.empty()) {
node n = que.front();
que.pop();
if (n.h >= H)
continue;
if (state[n.kind][n.h] == 2)
while (state[n.kind][--n.h] == 2)
;
else if (state[n.kind][n.h] == 1) {
while (state[n.kind][++n.h] == 1)
;
--n.h;
}
if (n.h == H - 1) {
ans = n.step;
break;
}
if (steps[n.kind][n.h] >= 0)
continue;
steps[n.kind][n.h] = n.step;
que.push(node(!n.kind, n.h, n.step + 1));
que.push(node(!n.kind, n.h + 1, n.step + 1));
que.push(node(!n.kind, n.h + 2, n.step + 1));
}
if (ans >= 0)
cout << ans << endl;
else
cout << "NA" << endl;
}
}
|
[["-", 0, 57, 64, 52, 15, 339, 51, 16, 17, 79], ["+", 0, 57, 64, 52, 15, 339, 51, 16, 17, 60], ["-", 64, 9, 0, 52, 15, 339, 51, 16, 17, 79], ["+", 64, 9, 0, 52, 15, 339, 51, 16, 17, 60]]
| 1
| 510
| 4
|
#include <iostream>
using namespace std;
int main() {
int m[100], a[100], b[100], c[200];
int i, j, s, n, f;
while (1) {
cin >> n;
if (n == 0)
break;
f = 0;
for (i = 0; i < n; i++) {
cin >> m[i] >> a[i] >> b[i];
c[2 * i] = a[i];
c[2 * i + 1] = b[i];
}
for (i = 0; i < 2 * n; i++) {
s = 0;
for (j = 0; j < n; j++) {
if (a[j] < c[i] && c[i] < b[j])
s += m[j];
if (s > 150) {
f = 1;
break;
}
}
if (f == 1)
break;
}
if (f == 1)
cout << "NG" << endl;
else
cout << "OK" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m[100], a[100], b[100], c[200];
int i, j, s, n, f;
while (1) {
cin >> n;
if (n == 0)
break;
f = 0;
for (i = 0; i < n; i++) {
cin >> m[i] >> a[i] >> b[i];
c[2 * i] = a[i];
c[2 * i + 1] = b[i];
}
for (i = 0; i < 2 * n; i++) {
s = 0;
for (j = 0; j < n; j++) {
if (a[j] <= c[i] && c[i] < b[j])
s += m[j];
if (s > 150) {
f = 1;
break;
}
}
if (f == 1)
break;
}
if (f == 1)
cout << "NG" << endl;
else
cout << "OK" << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 19]]
| 1
| 237
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> vec;
int N, x[1000], y[1000], w[1000];
int main() {
while (true) {
vec.clear();
cin >> N;
if (N == 0) {
break;
}
for (int i = 0; i < N; i++) {
cin >> w[i] >> x[i] >> y[i];
int ok1 = 1, ok2 = 1;
for (int j = 0; j < vec.size(); j++) {
if (vec[i] == x[i]) {
ok1 = 0;
}
if (vec[i] == y[i]) {
ok2 = 0;
}
}
if (ok1 == 1) {
vec.push_back(x[i]);
}
if (ok2 == 1) {
vec.push_back(y[i]);
}
}
sort(vec.begin(), vec.end());
for (int i = 0; i < N; i++) {
for (int j = 0; j < vec.size(); j++) {
if (vec[j] == x[i]) {
x[i] = j;
break;
}
}
for (int j = 0; j < vec.size(); j++) {
if (vec[j] == y[j]) {
y[i] = j;
break;
}
}
}
int W = 0;
int ok = 1;
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < N; j++) {
if (x[j] == i) {
W += w[j];
}
if (y[j] == i) {
W -= w[j];
}
}
if (W > 150) {
ok = 0;
}
}
if (ok == 1) {
cout << "OK" << endl;
}
if (ok == 0) {
cout << "NG" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> vec;
int N, x[1000], y[1000], w[1000];
int main() {
while (true) {
vec.clear();
cin >> N;
if (N == 0) {
break;
}
for (int i = 0; i < N; i++) {
cin >> w[i] >> x[i] >> y[i];
int ok1 = 1, ok2 = 1;
for (int j = 0; j < vec.size(); j++) {
if (vec[i] == x[i]) {
ok1 = 0;
}
if (vec[i] == y[i]) {
ok2 = 0;
}
}
if (ok1 == 1) {
vec.push_back(x[i]);
}
if (ok2 == 1) {
vec.push_back(y[i]);
}
}
sort(vec.begin(), vec.end());
for (int i = 0; i < N; i++) {
for (int j = 0; j < vec.size(); j++) {
if (vec[j] == x[i]) {
x[i] = j;
break;
}
}
for (int j = 0; j < vec.size(); j++) {
if (vec[j] == y[i]) {
y[i] = j;
break;
}
}
}
int W = 0;
int ok = 1;
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < N; j++) {
if (x[j] == i) {
W += w[j];
}
if (y[j] == i) {
W -= w[j];
}
}
if (W > 150) {
ok = 0;
}
}
if (ok == 1) {
cout << "OK" << endl;
}
if (ok == 0) {
cout << "NG" << endl;
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22]]
| 1
| 446
| 2
|
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0231
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
//??\???
#define MAX_N 100
#define W_LIM 150
int N;
int main() {
ios::sync_with_stdio(false);
while (cin >> N) {
if (N == 0)
break;
map<int, int> imos;
int m, a, b;
for (int i = 0; i < N; i++) {
cin >> m >> a >> b;
imos[a] += m;
imos[b] -= m;
}
int mx = 0, acc = 0;
for (auto it : imos) {
acc += it.second;
mx = max(mx, acc);
}
cout << ((mx > W_LIM) ? "OK" : "NG") << "\n";
}
}
|
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0231
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
//??\???
#define MAX_N 100
#define W_LIM 150
int N;
int main() {
ios::sync_with_stdio(false);
while (cin >> N) {
if (N == 0)
break;
map<int, int> imos;
int m, a, b;
for (int i = 0; i < N; i++) {
cin >> m >> a >> b;
imos[a] += m;
imos[b] -= m;
}
int mx = 0, acc = 0;
for (auto it : imos) {
acc += it.second;
mx = max(mx, acc);
}
cout << ((mx <= W_LIM) ? "OK" : "NG") << "\n";
}
}
|
[["-", 12, 23, 0, 41, 15, 23, 0, 16, 17, 47], ["+", 12, 23, 0, 41, 15, 23, 0, 16, 17, 19]]
| 1
| 160
| 2
|
#include <iostream>
using namespace std;
int main() {
int t;
while (cin >> t && t != 0) {
int n;
int sum = 0;
cin >> n;
while (n--) {
int s, f;
cin >> s >> f;
sum += (f - s);
}
if (sum >= t)
cout << "OK" << endl;
else
cout << n - sum << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int t;
while (cin >> t && t != 0) {
int n;
int sum = 0;
cin >> n;
while (n--) {
int s, f;
cin >> s >> f;
sum += (f - s);
}
if (sum >= t)
cout << "OK" << endl;
else
cout << t - sum << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22]]
| 1
| 91
| 2
|
#include <stdio.h>
int main(void) {
int n, t, i, k, h, x, w;
w = 0;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d %d", &k, &h);
w += h - k;
}
if (n >= w) {
printf("OK\n");
} else {
x = n - w;
printf("%d\n", x);
}
w = 0;
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, t, i, k, h, x, w;
w = 0;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d %d", &k, &h);
w += h - k;
}
if (n <= w) {
printf("OK\n");
} else {
x = n - w;
printf("%d\n", x);
}
w = 0;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 138
| 2
|
#include <iostream>
using namespace std;
int main() {
int t, n, s, f, sum;
while (cin >> t && t) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s >> f;
sum += (f - s);
}
if (sum >= t) {
cout << "OK" << endl;
} else {
cout << t - sum << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int t, n, s, f, sum;
while (cin >> t && t) {
cin >> n;
sum = 0;
for (int i = 0; i < n; i++) {
cin >> s >> f;
sum += (f - s);
}
if (sum >= t) {
cout << "OK" << endl;
} else {
cout << t - sum << endl;
}
}
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]]
| 1
| 97
| 4
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
int main() {
int t;
while (cin >> t, t) {
int n;
cin >> n;
int sum = 0;
REP(i, n) {
int s, t;
cin >> s >> t;
sum += t - s;
}
if (sum >= t) {
cout << "Ok" << endl;
} else {
cout << t - sum << endl;
}
}
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
int main() {
int t;
while (cin >> t, t) {
int n;
cin >> n;
int sum = 0;
REP(i, n) {
int s, t;
cin >> s >> t;
sum += t - s;
}
if (sum >= t) {
cout << "OK" << endl;
} else {
cout << t - sum << endl;
}
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 185
| 2
|
#include <iostream>
using namespace std;
int main(void) {
while (true) {
int n, m, p;
p = 0;
cin >> n;
if (n == 0) {
break;
}
cin >> m;
while (m > 0) {
int s, q;
cin >> s >> q;
p += q - s;
m--;
}
if (p >= n) {
cout << "OK" << endl;
} else {
cout << n - p;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
while (true) {
int n, m, p;
p = 0;
cin >> n;
if (n == 0) {
break;
}
cin >> m;
while (m > 0) {
int s, q;
cin >> s >> q;
p += q - s;
m--;
}
if (p >= n) {
cout << "OK" << endl;
} else {
cout << n - p << endl;
}
}
return 0;
}
|
[["+", 75, 76, 0, 9, 0, 1, 0, 16, 17, 151], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 104
| 2
|
#include <stdio.h>
int main() {
int s, f, t, total;
int i, j, n;
scanf("%d", &t);
while (t != 0) {
//初期化
total = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &s, &f);
total += f - s;
}
if (total < t)
printf("%d\n", t - total);
else
printf("NO\n");
scanf("%d", &t);
}
return 0;
}
|
#include <stdio.h>
int main() {
int s, f, t, total;
int i, j, n;
scanf("%d", &t);
while (t != 0) {
//初期化
total = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &s, &f);
total += f - s;
}
if (total < t)
printf("%d\n", t - total);
else
printf("OK\n");
scanf("%d", &t);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 131
| 2
|
#include <iostream>
using namespace std;
int main() {
int t, n, s, f, cnt;
while (true) {
cin >> t;
if (t == 0)
break;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s >> f;
cnt += f - s;
}
if (cnt >= t)
cout << "OK" << endl;
else
cout << t - cnt << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int t, n, s, f, cnt;
while (true) {
cin >> t;
cnt = 0;
if (t == 0)
break;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s >> f;
cnt += f - s;
}
if (cnt >= t)
cout << "OK" << endl;
else
cout << t - cnt << endl;
}
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]]
| 1
| 99
| 4
|
#include <iostream>
using namespace std;
int d, n, s, t, sum;
int main() {
while (cin >> d >> n, d) {
sum = 0;
for (int i = 0; i < n; i++) {
cin >> s >> t;
sum += t - s;
}
if (sum < d)
cout << sum - d << endl;
else
cout << "OK" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int d, n, s, t, sum;
int main() {
while (cin >> d >> n, d) {
sum = 0;
for (int i = 0; i < n; i++) {
cin >> s >> t;
sum += t - s;
}
if (sum < d)
cout << d - sum << endl;
else
cout << "OK" << endl;
}
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["-", 64, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
| 1
| 93
| 4
|
import java.io.*;
import java.util.*;
public class Main {
static void solve(FastScanner in, PrintWriter out, Methods ms) {
while (true) {
int n = in.nextInt();
if (n == 0)
return;
Food[] food = new Food[n];
for (int i = 0; i < n; i++) {
food[i] =
new Food(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
}
int P = in.nextInt(), F = in.nextInt(), C = in.nextInt(),
CA = in.nextInt();
boolean contain = false;
for (int i = 0; i < n; i++) {
if (food[i].protein < P && food[i].fat < F && food[i].carbon < C &&
food[i].calorie < CA) {
out.println(food[i].id);
contain = true;
}
}
if (contain == false)
out.println("NA");
}
}
static class Food {
int id, protein, fat, carbon, calorie;
Food(int i, int p, int f, int c) {
id = i;
protein = p;
fat = f;
carbon = c;
calorie = p * 4 + f * 9 + c * 4;
}
}
public static void main(String[] args) {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Methods ms = new Methods();
solve(in, out, ms);
in.close();
out.close();
}
static class Methods {
public void print(Object... ar) {
System.out.println(Arrays.deepToString(ar));
}
public int max(int... ar) {
Arrays.sort(ar);
return ar[ar.length - 1];
}
public int min(int... ar) {
Arrays.sort(ar);
return ar[0];
}
public long gcd(long a, long b) { return b > 0 ? gcd(b, a % b) : a; }
public long lcm(long a, long b) { return a / gcd(a, b) * b; }
public long factorial(int i) {
if (i == 1)
return 1;
else
return i * factorial(i - 1);
}
public int manhat(int x1, int y1, int x2, int y2) {
return Math.abs(x1 - x2) + Math.abs(y1 - y2);
}
public double euclid(double x1, double y1, double x2, double y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
public boolean isPrime(int n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (int i = 3; i <= Math.sqrt(n); i += 2)
if (n % i == 0)
return false;
return true;
}
}
static class FastScanner {
private InputStream in;
private byte[] buffer = new byte[1024];
private int length = 0, p = 0;
public FastScanner(InputStream stream) { in = stream; }
public boolean hasNextByte() {
if (p < length)
return true;
else {
p = 0;
try {
length = in.read(buffer);
} catch (Exception e) {
e.printStackTrace();
}
if (length <= 0)
return false;
}
return true;
}
public int readByte() {
if (hasNextByte() == true)
return buffer[p++];
return -1;
}
public boolean isPrintable(int n) { return 33 <= n && n <= 126; }
public void skip() {
while (hasNextByte() && !isPrintable(buffer[p]))
p++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int t = readByte();
while (isPrintable(t)) {
sb.appendCodePoint(t);
t = readByte();
}
return sb.toString();
}
public String[] nextArray(int n) {
String[] ar = new String[n];
for (int i = 0; i < n; i++)
ar[i] = next();
return ar;
}
public int nextInt() { return Math.toIntExact(nextLong()); }
public int[] nextIntArray(int n) {
int[] ar = new int[n];
for (int i = 0; i < n; i++)
ar[i] = nextInt();
return ar;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
boolean minus = false;
int temp = readByte();
if (temp == '-') {
minus = true;
temp = readByte();
}
if (temp < '0' || '9' < temp)
throw new NumberFormatException();
long n = 0;
while (isPrintable(temp)) {
if ('0' <= temp && temp <= '9') {
n *= 10;
n += temp - '0';
} else
throw new NumberFormatException();
temp = readByte();
}
return minus ? -n : n;
}
public long[] nextLongArray(int n) {
long[] ar = new long[n];
for (int i = 0; i < n; i++)
ar[i] = nextLong();
return ar;
}
public double nextDouble() { return Double.parseDouble(next()); }
public double[] nextDoubleArray(int n) {
double[] ar = new double[n];
for (int i = 0; i < n; i++)
ar[i] = nextDouble();
return ar;
}
public void close() {
try {
in.close();
} catch (Exception e) {
}
}
}
}
|
import java.io.*;
import java.util.*;
public class Main {
static void solve(FastScanner in, PrintWriter out, Methods ms) {
while (true) {
int n = in.nextInt();
if (n == 0)
return;
Food[] food = new Food[n];
for (int i = 0; i < n; i++) {
food[i] =
new Food(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
}
int P = in.nextInt(), F = in.nextInt(), C = in.nextInt(),
CA = in.nextInt();
boolean contain = false;
for (int i = 0; i < n; i++) {
if (food[i].protein <= P && food[i].fat <= F && food[i].carbon <= C &&
food[i].calorie <= CA) {
out.println(food[i].id);
contain = true;
}
}
if (contain == false)
out.println("NA");
}
}
static class Food {
int id, protein, fat, carbon, calorie;
Food(int i, int p, int f, int c) {
id = i;
protein = p;
fat = f;
carbon = c;
calorie = p * 4 + f * 9 + c * 4;
}
}
public static void main(String[] args) {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Methods ms = new Methods();
solve(in, out, ms);
in.close();
out.close();
}
static class Methods {
public void print(Object... ar) {
System.out.println(Arrays.deepToString(ar));
}
public int max(int... ar) {
Arrays.sort(ar);
return ar[ar.length - 1];
}
public int min(int... ar) {
Arrays.sort(ar);
return ar[0];
}
public long gcd(long a, long b) { return b > 0 ? gcd(b, a % b) : a; }
public long lcm(long a, long b) { return a / gcd(a, b) * b; }
public long factorial(int i) {
if (i == 1)
return 1;
else
return i * factorial(i - 1);
}
public int manhat(int x1, int y1, int x2, int y2) {
return Math.abs(x1 - x2) + Math.abs(y1 - y2);
}
public double euclid(double x1, double y1, double x2, double y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
public boolean isPrime(int n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (int i = 3; i <= Math.sqrt(n); i += 2)
if (n % i == 0)
return false;
return true;
}
}
static class FastScanner {
private InputStream in;
private byte[] buffer = new byte[1024];
private int length = 0, p = 0;
public FastScanner(InputStream stream) { in = stream; }
public boolean hasNextByte() {
if (p < length)
return true;
else {
p = 0;
try {
length = in.read(buffer);
} catch (Exception e) {
e.printStackTrace();
}
if (length <= 0)
return false;
}
return true;
}
public int readByte() {
if (hasNextByte() == true)
return buffer[p++];
return -1;
}
public boolean isPrintable(int n) { return 33 <= n && n <= 126; }
public void skip() {
while (hasNextByte() && !isPrintable(buffer[p]))
p++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int t = readByte();
while (isPrintable(t)) {
sb.appendCodePoint(t);
t = readByte();
}
return sb.toString();
}
public String[] nextArray(int n) {
String[] ar = new String[n];
for (int i = 0; i < n; i++)
ar[i] = next();
return ar;
}
public int nextInt() { return Math.toIntExact(nextLong()); }
public int[] nextIntArray(int n) {
int[] ar = new int[n];
for (int i = 0; i < n; i++)
ar[i] = nextInt();
return ar;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
boolean minus = false;
int temp = readByte();
if (temp == '-') {
minus = true;
temp = readByte();
}
if (temp < '0' || '9' < temp)
throw new NumberFormatException();
long n = 0;
while (isPrintable(temp)) {
if ('0' <= temp && temp <= '9') {
n *= 10;
n += temp - '0';
} else
throw new NumberFormatException();
temp = readByte();
}
return minus ? -n : n;
}
public long[] nextLongArray(int n) {
long[] ar = new long[n];
for (int i = 0; i < n; i++)
ar[i] = nextLong();
return ar;
}
public double nextDouble() { return Double.parseDouble(next()); }
public double[] nextDoubleArray(int n) {
double[] ar = new double[n];
for (int i = 0; i < n; i++)
ar[i] = nextDouble();
return ar;
}
public void close() {
try {
in.close();
} catch (Exception e) {
}
}
}
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 0, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 15, 0, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 15, 0, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 15, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 17, 19]]
| 3
| 1,303
| 8
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = Integer.parseInt(scan.nextLine());
if (n == 0) {
break;
}
String[] str[] = new String[n + 1][];
for (int i = 0; i < n + 1; i++) {
str[i] = scan.nextLine().split(" ");
}
int[] lim = new int[4];
for (int i = 0; i < 4; i++) {
lim[i] = Integer.parseInt(str[n][i]);
}
int[] a = {4, 7, 4};
boolean sw = true;
for (int i = 0; i < n; i++) {
int ca = 0;
for (int j = 1; j < 4; j++) {
int t = Integer.parseInt(str[i][j]);
if (t > lim[j - 1]) {
break;
}
ca += t * a[j - 1];
if (j == 3 && ca <= lim[3]) {
System.out.println(str[i][0]);
sw = false;
}
}
}
if (sw) {
System.out.println("NA");
}
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = Integer.parseInt(scan.nextLine());
if (n == 0) {
break;
}
String[] str[] = new String[n + 1][];
for (int i = 0; i < n + 1; i++) {
str[i] = scan.nextLine().split(" ");
}
int[] lim = new int[4];
for (int i = 0; i < 4; i++) {
lim[i] = Integer.parseInt(str[n][i]);
}
int[] a = {4, 9, 4};
boolean sw = true;
for (int i = 0; i < n; i++) {
int ca = 0;
for (int j = 1; j < 4; j++) {
int t = Integer.parseInt(str[i][j]);
if (t > lim[j - 1]) {
break;
}
ca += t * a[j - 1];
if (j == 3 && ca <= lim[3]) {
System.out.println(str[i][0]);
sw = false;
}
}
}
if (sw) {
System.out.println("NA");
}
}
}
}
|
[["-", 8, 196, 0, 503, 49, 200, 51, 518, 0, 499], ["+", 8, 196, 0, 503, 49, 200, 51, 518, 0, 499]]
| 3
| 315
| 2
|
import java.util.*;
public class Main {
Scanner in = new Scanner(System.in);
public static void main(String[] args) { new Main(); }
public Main() { new AOJ0239(); }
class AOJ0239 {
public AOJ0239() {
while (true) {
int n = in.nextInt();
if (n == 0)
break;
ArrayList<Sweet> list = new ArrayList<Sweet>();
for (int i = 0; i < n; i++)
list.add(new Sweet(in.nextInt(), in.nextInt(), in.nextInt(),
in.nextInt()));
int P = in.nextInt(), Q = in.nextInt(), R = in.nextInt(),
C = in.nextInt();
boolean sw = false;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).p <= P && list.get(i).q <= Q && list.get(i).r <= R &&
list.get(i).sum <= C) {
System.out.println(list.get(i).num);
sw = true;
}
}
if (sw == false)
System.out.println("NA");
}
}
class Sweet {
int num, sum, p, q, r;
public Sweet(int num, int p, int q, int r) {
this.num = num;
this.sum = p + q + r;
this.p = p;
this.q = q;
this.r = r;
}
}
}
}
|
import java.util.*;
public class Main {
Scanner in = new Scanner(System.in);
public static void main(String[] args) { new Main(); }
public Main() { new AOJ0239(); }
class AOJ0239 {
public AOJ0239() {
while (true) {
int n = in.nextInt();
if (n == 0)
break;
ArrayList<Sweet> list = new ArrayList<Sweet>();
for (int i = 0; i < n; i++)
list.add(new Sweet(in.nextInt(), in.nextInt(), in.nextInt(),
in.nextInt()));
int P = in.nextInt(), Q = in.nextInt(), R = in.nextInt(),
C = in.nextInt();
boolean sw = false;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).p <= P && list.get(i).q <= Q && list.get(i).r <= R &&
list.get(i).sum <= C) {
System.out.println(list.get(i).num);
sw = true;
}
}
if (sw == false)
System.out.println("NA");
}
}
class Sweet {
int num, sum, p, q, r;
public Sweet(int num, int p, int q, int r) {
this.num = num;
this.sum = p * 4 + q * 9 + r * 4;
this.p = p;
this.q = q;
this.r = r;
}
}
}
}
|
[["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 499], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 12, 499], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 499]]
| 3
| 354
| 6
|
#include <stdio.h>
int main(void) {
int n;
int i[1001], p[1001], q[1001], r[1001], c[1001];
int P, Q, R, C;
int j, flg;
scanf("%d", &n);
while (n != 0) {
flg = 0;
for (j = 0; j < n; j++) {
scanf("%d %d %d %d", &i[j], &p[j], &q[j], &r[j]);
c[j] = p[j] * 4 + q[j] * 9 + r[j] * 4;
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
for (j = 0; j < n; j++) {
if (p[j] < P && r[j] < R && q[j] < Q && c[j] < C) {
printf("%d\n", i[j]);
flg = 1;
}
}
if (flg == 0) {
printf("NA\n");
}
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n;
int i[1001], p[1001], q[1001], r[1001], c[1001];
int P, Q, R, C;
int j, flg;
scanf("%d", &n);
while (n != 0) {
flg = 0;
for (j = 0; j < n; j++) {
scanf("%d %d %d %d", &i[j], &p[j], &q[j], &r[j]);
c[j] = p[j] * 4 + q[j] * 9 + r[j] * 4;
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
for (j = 0; j < n; j++) {
if (p[j] <= P && r[j] <= R && q[j] <= Q && c[j] <= C) {
printf("%d\n", i[j]);
flg = 1;
}
}
if (flg == 0) {
printf("NA\n");
}
scanf("%d", &n);
}
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 0, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19]]
| 0
| 258
| 8
|
#include <stdio.h>
int main() {
int n, id[1000], p[1000], q[1000], r[1000], P, Q, R, c[1000], C, i, a;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &id[i], &p[i], &q[i], &r[i]);
c[i] = (p[i] + r[i]) * 4 + q[i] * 9;
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
a = 1;
for (i = 0; i < n; i++) {
if (P > p[i] && Q > q[i] && R > r[i] && C > c[i]) {
printf("%d\n", id[i]);
a = 0;
}
}
if (a)
printf("NA\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, id[1000], p[1000], q[1000], r[1000], P, Q, R, c[1000], C, i, a;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &id[i], &p[i], &q[i], &r[i]);
c[i] = (p[i] + r[i]) * 4 + q[i] * 9;
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
a = 1;
for (i = 0; i < n; i++) {
if (P >= p[i] && Q >= q[i] && R >= r[i] && C >= c[i]) {
printf("%d\n", id[i]);
a = 0;
}
}
if (a)
printf("NA\n");
}
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 0, 16, 31, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 20], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 17, 20], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 20]]
| 0
| 246
| 8
|
#include <stdio.h>
int main() {
int n, i, f, a[1010], b[1010], c[1010], d[1010], l[4];
while (scanf("%d", &n), n) {
for (i = 0; i < n; i++)
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
for (i = 0; i < 4; i++)
scanf("%d", &l[i]);
for (i = f = 0; i < n; i++) {
if (b[i] > l[0] || c[i] > l[1] || d[i] > l[2])
continue; // printf("%d\n",i);
if ((b[i] + d[i]) * 4 + c[i] * 7 > l[3])
continue; // printf("%d\n",i);
printf("%d\n", a[i]);
f = 1;
}
if (f == 0)
printf("NA\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, i, f, a[1010], b[1010], c[1010], d[1010], l[4];
while (scanf("%d", &n), n) {
for (i = 0; i < n; i++)
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
for (i = 0; i < 4; i++)
scanf("%d", &l[i]);
for (i = f = 0; i < n; i++) {
if (b[i] > l[0] || c[i] > l[1] || d[i] > l[2])
continue; // printf("%d\n",i);
if ((b[i] + d[i]) * 4 + c[i] * 9 > l[3])
continue; // printf("%d\n",i);
printf("%d\n", a[i]);
f = 1;
}
if (f == 0)
printf("NA\n");
}
return 0;
}
|
[["-", 15, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 12, 13]]
| 0
| 243
| 2
|
#include <stdio.h>
int main(void) {
int y, i, n, d[1024][4] = {0}, p, q, r, c;
while (scanf("%d", &n), n != 0) {
for (i = 1; i <= n; i++) {
scanf("%d%d%d%d", &d[i][0], &d[i][1], &d[i][2], &d[i][3]);
}
scanf("%d%d%d%d", &p, &q, &r, &c);
y = 1;
for (i = 1; i <= n; i++) {
if (d[i][1] <= p && d[i][2] <= q && d[i][3] <= r &&
(d[i][1] + d[i][3]) * 4 + d[i][2] <= c) {
printf("%d\n", d[i][0]);
y = 0;
}
}
if (y) {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int y, i, n, d[1024][4] = {0}, p, q, r, c;
while (scanf("%d", &n), n != 0) {
for (i = 1; i <= n; i++) {
scanf("%d%d%d%d", &d[i][0], &d[i][1], &d[i][2], &d[i][3]);
}
scanf("%d%d%d%d", &p, &q, &r, &c);
y = 1;
for (i = 1; i <= n; i++) {
if (d[i][1] <= p && d[i][2] <= q && d[i][3] <= r &&
(d[i][1] + d[i][3]) * 4 + d[i][2] * 9 <= c) {
printf("%d\n", d[i][0]);
y = 0;
}
}
if (y) {
printf("NA\n");
}
}
return 0;
}
|
[["+", 0, 16, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 16, 12, 16, 31, 16, 12, 16, 12, 13]]
| 0
| 251
| 2
|
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include <stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type, x) fprintf(stdout, "%" #type "\n", x)
int main() {
int n, d[1000][5], i, p, q, r, f, c;
while (fscanf(stdin, "%d", &n), n) {
f = 1;
for (i = 0; i < n; i++)
fscanf(stdin, "%d%d%d%d", &d[i][0], &d[i][1], &d[i][2], &d[i][3]),
d[i][4] = 4 * (d[i][1] + d[i][3]) + 9 * d[i][2];
fscanf(stdin, "%d%d%d%d", &p, &q, &r, &c);
for (i = 0; i < n; i++)
if (d[i][1] < p && d[i][2] < q && d[i][3] < r && d[i][4] < c)
P(d, d[i][0]), f = 0;
if (f)
puts("NA");
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include <stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type, x) fprintf(stdout, "%" #type "\n", x)
int main() {
int n, d[1000][5], i, p, q, r, f, c;
while (fscanf(stdin, "%d", &n), n) {
f = 1;
for (i = 0; i < n; i++)
fscanf(stdin, "%d%d%d%d", &d[i][0], &d[i][1], &d[i][2], &d[i][3]),
d[i][4] = 4 * (d[i][1] + d[i][3]) + 9 * d[i][2];
fscanf(stdin, "%d%d%d%d", &p, &q, &r, &c);
for (i = 0; i < n; i++)
if (d[i][1] <= p && d[i][2] <= q && d[i][3] <= r && d[i][4] <= c)
P(d, d[i][0]), f = 0;
if (f)
puts("NA");
}
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 0, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 17, 19], ["-", 8, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 8, 57, 15, 23, 0, 16, 12, 16, 17, 19]]
| 0
| 271
| 8
|
#include <stdio.h>
int main(void) {
for (;;) {
int a[1000], b[1000], c[1000], d[1000], e[1000], f, g, h, i, j, k, l[1000],
n;
j = 0;
scanf("%d", &k);
if (k == 0) {
break;
}
for (n = 1; n <= k; n++) {
scanf("%d %d %d %d", &a[n], &b[n], &c[n], &d[n]);
e[n] = b[n] * 4 + c[n] * 9 + d[n] * 4;
}
scanf("%d %d %d %d", &f, &g, &h, &i);
for (n = 1; n <= k; n++) {
if (b[n] < f && c[n] < g && d[n] < h && e[n] < i) {
j++;
l[j] = a[n];
}
}
if (j == 0) {
printf("NA\n");
} else {
for (n = 1; n <= j; n++) {
printf("%d\n", l[n]);
}
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
for (;;) {
int a[1000], b[1000], c[1000], d[1000], e[1000], f, g, h, i, j, k, l[1000],
n;
j = 0;
scanf("%d", &k);
if (k == 0) {
break;
}
for (n = 1; n <= k; n++) {
scanf("%d %d %d %d", &a[n], &b[n], &c[n], &d[n]);
e[n] = b[n] * 4 + c[n] * 9 + d[n] * 4;
}
scanf("%d %d %d %d", &f, &g, &h, &i);
for (n = 1; n <= k; n++) {
if (b[n] <= f && c[n] <= g && d[n] <= h && e[n] <= i) {
j++;
l[j] = a[n];
}
}
if (j == 0) {
printf("NA\n");
} else {
for (n = 1; n <= j; n++) {
printf("%d\n", l[n]);
}
}
}
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 0, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19]]
| 0
| 286
| 8
|
/*
?????????????????????????????????????¨???? ?????????4
??????
???????????¬??\???????§?????????????????£??????????????????????????????£?????§???????????????????????????
??????????????¬??????????????????????????????????????????????????????????????????????????????????????????
??????????????????????¢???????????????§?????\????????????????????????????????????????????????????????????
????????´??????????£???????????????????????????????????????????????????????????´?????????????????????¶???
???????????´??????????£??????????????????????????£???????????????????????????¨?£?????????????????????????
??????????????????????????¨??????????????????
?£????????????? 3
??§???????´???¨?????°?????????????????±????????????????????????????°´??????????????????
??????????´???????????????????????????????g?????°??????????????????????????±????????¨????°´?????????
4kcal???????????????????????????????????? 9kcal
??¨?¨????????????????????????¨?????°???????????¨???
????????¨??????????????±??????????????????????????? 7g?????????
14g???????°´?????? 47g ????????????
?????????????????????????????¨???????????????????????????????¨????????????¨???
4 ?? 7 + 9 ?? 14 + 4 ?? 47 = 342 kcal
??¨???????????????????????????????§?????¨?????????????????????????
?????? ?????? ????????±??????(g) ??????(g)
????°´??????(g) ????????????(kcal)
1 ??±?????? 7
14 47 342 2
????????????????????? 5 35 55
555
3 ???????????? 6 3
59 287
4 ????????? 6
5 15 129
?????????????±???¨???????????????????????° n
??¨????????????????????±?????¶???????????±?????\?????¨??????
???????????????????????????????????¶???????¶????????????¨?????????????£??????????????????????????????????
??§???????????????????????°????????????????????????????????????
?????????????????±????????????????????????
i?????????????????????????????????????????±??????????????? p???
??????????????? q???????°´??????????????? r
?????????????????£?????????????????¶???????????±?????????
???????????¨?????§???????????§???????????±??????????????? P??????????????????
Q???????°´????????????
??? R?????????????????????????????¨?????§???????????§???????????????C
???????????£?????????????????????
??????????????????????°´???????????????????????????????????????????????§????¶?????????¨??¶???????????¨???
??????????£????????????????????????????????????¨?????????????????????
?????????????????° n ??? 1 ??\??? 1000 ??\????????´??°????????????????????? i
??? 1 ??\??? 1000
??\????????´??°?????????????´?????????? p, q, r ??? 0 ??\??? 100
??\????????´??°??§????????????
???????????????????´??????¶?????? P, Q, R ??? 0 ??\??? 100
??\????????´??°???????????????C ??? 0 ??\??? 1700
??\????????´??°??¨?????????????£?????????????????????????????????§???????£?????????????
??????????????????????????\??????????????????????????????????????????????£???????????????????????????????
????????°???NA?????¨???????????????????????????
????????¨????????? 4 ??????????????????????????????P=10,Q=15,R=50,C=400
??¨????????¶????????´
????????±????????¨??????????????????????????????????´????????????????????????¶????????????????????§?£????
????????????????????????????????????????????????????????????????????????????°´????????¨??????????????????
????????????????°´?????????????????¶??????????¶????????????????????£?????????????????????????????????????
??????????????????
??\???
?????°???????????????????????????????????\?????¨?????????????????????????????\???????????????????????????
??¨???????????§????????????????????????????????????????????\????????¨????????§??????
1 ?????? ??????????????° n?????´??°???
2 ?????? ?¬¬ 1 ????????????????????± i p q r?????´??° ??´??° ??´??°
??´??°???????§??????????????????? 3 ?????? ?¬¬ 2 ????????????????????±
???
n+1 ?????? ?¬¬ n ????????????????????±
n+2 ?????? ??????????´????????????????????????¶?????? P Q R C?????´??° ??´??°
??´??° ??´??°???????§???????????????????
??????
??\??????????????????????????¨???????£??????????????????????????????????????????????NA????????????????????????
*/
#include <stdio.h>
#define NUM 1000 //
#define P 0 // ????????±??????(g)
#define Q 1 // ??????(g)
#define R 2 // ????°´??????(g)
#define C 3 // ????????????(kcal)
#define N 4 // ??????
int main(void) {
int pp, qq, rr, cc;
int t[NUM][5];
int i, j;
int n; // ??????????????° n?????´??°???
while (1) {
scanf("%d", &n); // ?????????????????° n?????´??°???????????\???
if (n == 0) {
break; // ??\?????????????????????????????¨?????????
}
for (i = 0; i < n; i++) {
scanf("%d %d %d %d ", &t[i][N], &t[i][P], &t[i][Q], &t[i][R]);
t[i][C] = t[i][P] * 4 + t[i][Q] * 9 + t[i][R] * 4;
}
scanf("%d %d %d %d ", &pp, &qq, &rr, &cc);
j = 0; // ?£??????????????????????????????°
for (i = 0; i < n; i++) {
// printf( "%d %d %d %d - %d %d %d %d ",
// t[ i ][ P ], t[ i ][ Q ], t[ i ][ R ],
//t[ i ][ C ], pp, qq, rr, cc );
if ((pp >= t[i][P]) && (qq >= t[i][Q]) && (rr >= t[i][R]) &&
(cc >= t[i][C])) {
printf("%d\n", i + 1);
j++;
}
}
if (j == 0) {
printf("NA\n");
}
}
return 0;
}
|
/*
?????????????????????????????????????¨???? ?????????4
??????
???????????¬??\???????§?????????????????£??????????????????????????????£?????§???????????????????????????
??????????????¬??????????????????????????????????????????????????????????????????????????????????????????
??????????????????????¢???????????????§?????\????????????????????????????????????????????????????????????
????????´??????????£???????????????????????????????????????????????????????????´?????????????????????¶???
???????????´??????????£??????????????????????????£???????????????????????????¨?£?????????????????????????
??????????????????????????¨??????????????????
?£????????????? 3
??§???????´???¨?????°?????????????????±????????????????????????????°´??????????????????
??????????´???????????????????????????????g?????°??????????????????????????±????????¨????°´?????????
4kcal???????????????????????????????????? 9kcal
??¨?¨????????????????????????¨?????°???????????¨???
????????¨??????????????±??????????????????????????? 7g?????????
14g???????°´?????? 47g ????????????
?????????????????????????????¨???????????????????????????????¨????????????¨???
4 ?? 7 + 9 ?? 14 + 4 ?? 47 = 342 kcal
??¨???????????????????????????????§?????¨?????????????????????????
?????? ?????? ????????±??????(g) ??????(g)
????°´??????(g) ????????????(kcal)
1 ??±?????? 7
14 47 342 2
????????????????????? 5 35 55
555
3 ???????????? 6 3
59 287
4 ????????? 6
5 15 129
?????????????±???¨???????????????????????° n
??¨????????????????????±?????¶???????????±?????\?????¨??????
???????????????????????????????????¶???????¶????????????¨?????????????£??????????????????????????????????
??§???????????????????????°????????????????????????????????????
?????????????????±????????????????????????
i?????????????????????????????????????????±??????????????? p???
??????????????? q???????°´??????????????? r
?????????????????£?????????????????¶???????????±?????????
???????????¨?????§???????????§???????????±??????????????? P??????????????????
Q???????°´????????????
??? R?????????????????????????????¨?????§???????????§???????????????C
???????????£?????????????????????
??????????????????????°´???????????????????????????????????????????????§????¶?????????¨??¶???????????¨???
??????????£????????????????????????????????????¨?????????????????????
?????????????????° n ??? 1 ??\??? 1000 ??\????????´??°????????????????????? i
??? 1 ??\??? 1000
??\????????´??°?????????????´?????????? p, q, r ??? 0 ??\??? 100
??\????????´??°??§????????????
???????????????????´??????¶?????? P, Q, R ??? 0 ??\??? 100
??\????????´??°???????????????C ??? 0 ??\??? 1700
??\????????´??°??¨?????????????£?????????????????????????????????§???????£?????????????
??????????????????????????\??????????????????????????????????????????????£???????????????????????????????
????????°???NA?????¨???????????????????????????
????????¨????????? 4 ??????????????????????????????P=10,Q=15,R=50,C=400
??¨????????¶????????´
????????±????????¨??????????????????????????????????´????????????????????????¶????????????????????§?£????
????????????????????????????????????????????????????????????????????????????°´????????¨??????????????????
????????????????°´?????????????????¶??????????¶????????????????????£?????????????????????????????????????
??????????????????
??\???
?????°???????????????????????????????????\?????¨?????????????????????????????\???????????????????????????
??¨???????????§????????????????????????????????????????????\????????¨????????§??????
1 ?????? ??????????????° n?????´??°???
2 ?????? ?¬¬ 1 ????????????????????± i p q r?????´??° ??´??° ??´??°
??´??°???????§??????????????????? 3 ?????? ?¬¬ 2 ????????????????????±
???
n+1 ?????? ?¬¬ n ????????????????????±
n+2 ?????? ??????????´????????????????????????¶?????? P Q R C?????´??° ??´??°
??´??° ??´??°???????§???????????????????
??????
??\??????????????????????????¨???????£??????????????????????????????????????????????NA????????????????????????
*/
#include <stdio.h>
#define NUM 1000 //
#define P 0 // ????????±??????(g)
#define Q 1 // ??????(g)
#define R 2 // ????°´??????(g)
#define C 3 // ????????????(kcal)
#define N 4 // ??????
int main(void) {
int pp, qq, rr, cc;
int t[NUM][5];
int i, j;
int n; // ??????????????° n?????´??°???
while (1) {
scanf("%d", &n); // ?????????????????° n?????´??°???????????\???
if (n == 0) {
break; // ??\?????????????????????????????¨?????????
}
for (i = 0; i < n; i++) {
scanf("%d %d %d %d ", &t[i][N], &t[i][P], &t[i][Q], &t[i][R]);
t[i][C] = t[i][P] * 4 + t[i][Q] * 9 + t[i][R] * 4;
}
scanf("%d %d %d %d ", &pp, &qq, &rr, &cc);
j = 0; // ?£??????????????????????????????°
for (i = 0; i < n; i++) {
// printf( "%d %d %d %d - %d %d %d %d ",
// t[ i ][ P ], t[ i ][ Q ], t[ i ][ R ],
//t[ i ][ C ], pp, qq, rr, cc );
if ((pp >= t[i][P]) && (qq >= t[i][Q]) && (rr >= t[i][R]) &&
(cc >= t[i][C])) {
printf("%d\n", t[i][N]);
j++;
}
}
if (j == 0) {
printf("NA\n");
}
}
return 0;
}
|
[["+", 0, 2, 3, 4, 0, 69, 28, 69, 28, 22], ["+", 0, 2, 3, 4, 0, 69, 28, 69, 0, 70], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 69, 28, 69, 0, 73], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 0, 70], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 0, 73]]
| 0
| 307
| 8
|
#include <stdio.h>
typedef struct {
int no;
int b, c, d;
int cal;
} P;
int main() {
int n, i, flg;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
P tmp[n];
P max;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &tmp[i].no, &tmp[i].b, &tmp[i].c, &tmp[i].d);
tmp[i].cal = (tmp[i].b + tmp[i].d) * 4 + tmp[i].c * 9;
}
scanf("%d %d %d %d", &max.b, &max.c, &max.d, &max.cal);
for (i = 0, flg = 0; i < n; i++) {
if (max.b >= tmp[i].b && max.c >= tmp[i].c && max.d >= tmp[i].d &&
max.cal >= tmp[i].cal) {
printf("%d\n", tmp[i].no);
flg = 1;
}
}
if (flg == 1)
printf("NA\n");
}
return 0;
}
|
#include <stdio.h>
typedef struct {
int no;
int b, c, d;
int cal;
} P;
int main() {
int n, i, flg;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
P tmp[n];
P max;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &tmp[i].no, &tmp[i].b, &tmp[i].c, &tmp[i].d);
tmp[i].cal = (tmp[i].b + tmp[i].d) * 4 + tmp[i].c * 9;
}
scanf("%d %d %d %d", &max.b, &max.c, &max.d, &max.cal);
for (i = 0, flg = 0; i < n; i++) {
if (max.b >= tmp[i].b && max.c >= tmp[i].c && max.d >= tmp[i].d &&
max.cal >= tmp[i].cal) {
printf("%d\n", tmp[i].no);
flg = 1;
}
}
if (flg == 0)
printf("NA\n");
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 285
| 2
|
#include <stdio.h>
int main() {
int n, f[1005][5], i, j, t;
for (; scanf("%d", &n), n;) {
for (i = 0; i <= n; f[i][4] = f[i][1] * 4 + f[i][2] * 9 + f[i][3] * 4, i++)
for (j = 0; j < 4; j++)
scanf("%d", &f[i][j]);
for (i = t = 0; i < n; i++) {
for (j = 1; j < 5 && f[i][j] < f[n][j - 1]; j++)
;
if (j == 5)
t = printf("%d\n", f[i][0]);
}
if (!t)
puts("NA");
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, f[1005][5], i, j, t;
for (; scanf("%d", &n), n;) {
for (i = 0; i <= n; f[i][4] = f[i][1] * 4 + f[i][2] * 9 + f[i][3] * 4, i++)
for (j = 0; j < 4; j++)
scanf("%d", &f[i][j]);
for (i = t = 0; i < n; i++) {
for (j = 1; j < 5 && f[i][j] <= f[n][j - 1];)
j++;
if (j == 5)
t = printf("%d\n", f[i][0]);
}
if (!t)
puts("NA");
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 19], ["+", 8, 9, 0, 7, 8, 9, 0, 7, 0, 25], ["-", 8, 9, 0, 7, 8, 9, 0, 7, 0, 25]]
| 0
| 211
| 4
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int s[n], p[n], q[n], r[n], c[n];
int P, Q, R, C;
for (int i = 0; i < n; i++) {
cin >> s[i] >> p[i] >> q[i] >> r[i];
c[i] = 4 * p[i] + 9 * q[i] + 4 * r[i];
}
cin >> P >> Q >> R >> C;
bool found = false;
for (int i = 0; i < n; i++) {
if (p[i] <= P && q[i] <= Q && r[i] <= R && c[i] << C) {
found = true;
cout << s[i] << endl;
}
}
if (!found)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int s[n], p[n], q[n], r[n], c[n];
int P, Q, R, C;
for (int i = 0; i < n; i++) {
cin >> s[i] >> p[i] >> q[i] >> r[i];
c[i] = 4 * p[i] + 9 * q[i] + 4 * r[i];
}
cin >> P >> Q >> R >> C;
bool found = false;
for (int i = 0; i < n; i++) {
if (p[i] <= P && q[i] <= Q && r[i] <= R && c[i] <= C) {
found = true;
cout << s[i] << endl;
}
}
if (!found)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 151], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 224
| 2
|
#include <iostream>
using namespace std;
int f(int a, int b, int c) { return (a * c) * 4 + b * 9; }
int I[1000], a[1000], b[1000], c[1000];
int P, Q, R, C;
main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++)
cin >> I[i] >> a[i] >> b[i] >> c[i];
cin >> P >> Q >> R >> C;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] > P)
continue;
if (b[i] > Q)
continue;
if (c[i] > R)
continue;
if (f(a[i], b[i], c[i]) > C)
continue;
cnt++;
cout << I[i] << endl;
}
if (!cnt)
cout << "NA" << endl;
}
}
|
#include <iostream>
using namespace std;
int f(int a, int b, int c) { return (a + c) * 4 + b * 9; }
int I[1000], a[1000], b[1000], c[1000];
int P, Q, R, C;
main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++)
cin >> I[i] >> a[i] >> b[i] >> c[i];
cin >> P >> Q >> R >> C;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] > P)
continue;
if (b[i] > Q)
continue;
if (c[i] > R)
continue;
if (f(a[i], b[i], c[i]) > C)
continue;
cnt++;
cout << I[i] << endl;
}
if (!cnt)
cout << "NA" << endl;
}
}
|
[["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72]]
| 1
| 230
| 2
|
#include <iostream>
using namespace std;
int main() {
int n, i[1000], p[1000], q[1000], r[1000];
int P, Q, R, C, count;
while (cin >> n && n != 0) {
count = 0;
for (int j = 0; j < n; j++) {
cin >> i[j] >> p[j] >> q[j] >> r[j];
}
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
if (4 * p[j] + 9 * q[j] + 4 * r[j] <= C && p[j] <= P && q[j] <= Q &&
r[j] <= R) {
cout << i[j] << endl;
} else if (j == n - 1 && count == 0) {
cout << "NA" << endl;
}
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, i[1000], p[1000], q[1000], r[1000];
int P, Q, R, C, count;
while (cin >> n && n != 0) {
count = 0;
for (int j = 0; j < n; j++) {
cin >> i[j] >> p[j] >> q[j] >> r[j];
}
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
if (4 * p[j] + 9 * q[j] + 4 * r[j] <= C && p[j] <= P && q[j] <= Q &&
r[j] <= R) {
cout << i[j] << endl;
count++;
} else if (j == n - 1 && count == 0) {
cout << "NA" << endl;
}
}
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 209
| 3
|
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
const int MAX = 10000100;
int main(void) {
int n;
while (cin >> n, n) {
vector<vector<int>> vec(n + 1, vector<int>(5));
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < 4; j++) {
cin >> vec[i][j];
// cout<<vec[i][j]<<" ";
}
vec[i][4] = vec[i][1] * 4 + vec[i][2] * 9 + vec[i][3] * 7;
// cout<<vec[i][4]<<endl;
}
// cout<<endl;
bool no = true;
for (int i = 0; i < n; i++) {
bool ans = true;
for (int j = 1; j < 5; j++) {
if (vec[i][j] > vec[n][j - 1])
ans = false;
}
if (ans) {
cout << vec[i][0] << endl;
no = false;
}
}
if (no)
cout << "NA" << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
const int MAX = 10000100;
int main(void) {
int n;
while (cin >> n, n) {
vector<vector<int>> vec(n + 1, vector<int>(5));
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < 4; j++) {
cin >> vec[i][j];
// cout<<vec[i][j]<<" ";
}
vec[i][4] = vec[i][1] * 4 + vec[i][2] * 9 + vec[i][3] * 4;
// cout<<vec[i][4]<<endl;
}
// cout<<endl;
bool no = true;
for (int i = 0; i < n; i++) {
bool ans = true;
for (int j = 1; j < 5; j++) {
if (vec[i][j] > vec[n][j - 1])
ans = false;
}
if (ans) {
cout << vec[i][0] << endl;
no = false;
}
}
if (no)
cout << "NA" << endl;
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
| 1
| 251
| 2
|
#include <stdio.h>
int main() {
int N;
int p, q, r, c;
while (1) {
int n[1002][6] = {};
scanf("%d", &N);
if (N == 0)
break;
for (int i = 0; i < N; i++) {
scanf("%d %d %d %d", &n[i][0], &n[i][1], &n[i][2], &n[i][3]);
n[i][4] = 4 * n[i][1] + 7 * n[i][2] + 4 * n[i][3];
}
scanf("%d %d %d %d", &p, &q, &r, &c);
bool f = true;
for (int i = 0; i < N; i++) {
if (n[i][1] <= p && n[i][2] <= q && n[i][3] <= r && n[i][4] <= c) {
printf("%d\n", n[i][0]);
f = false;
}
}
if (f == true)
printf("NA\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int N;
int p, q, r, c;
while (1) {
int n[1024][6] = {};
scanf("%d", &N);
if (N == 0)
break;
for (int i = 0; i < N; i++) {
scanf("%d %d %d %d", &n[i][0], &n[i][1], &n[i][2], &n[i][3]);
n[i][4] = 4 * n[i][1] + 9 * n[i][2] + 4 * n[i][3];
}
scanf("%d %d %d %d", &p, &q, &r, &c);
bool f = true;
for (int i = 0; i < N; i++) {
if (n[i][1] <= p && n[i][2] <= q && n[i][3] <= r && n[i][4] <= c) {
printf("%d\n", n[i][0]);
f = false;
}
}
if (f == true)
printf("NA\n");
}
return 0;
}
|
[["-", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["+", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["-", 0, 11, 12, 16, 31, 16, 12, 16, 31, 13], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 31, 13]]
| 1
| 274
| 4
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#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 <utility>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
int num[2000], p[2000], q[2000], r[2000];
rep(i, n) { cin >> num[i] >> p[i] >> q[i] >> r[i]; }
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool flag = true;
rep(i, n) {
if (p[i] <= P && q[i] <= Q && r[i] <= R &&
p[i] * 4 + q[i] * 9 + r[i] <= C) {
flag = false;
cout << num[i] << endl;
}
}
if (flag)
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#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 <utility>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
int num[2000], p[2000], q[2000], r[2000];
rep(i, n) { cin >> num[i] >> p[i] >> q[i] >> r[i]; }
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool flag = true;
rep(i, n) {
if (p[i] <= P && q[i] <= Q && r[i] <= R &&
p[i] * 4 + q[i] * 9 + r[i] * 4 <= C) {
flag = false;
cout << num[i] << endl;
}
}
if (flag)
cout << "NA" << endl;
}
return 0;
}
|
[["+", 51, 16, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 51, 16, 12, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 268
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n;
while (cin >> n, n) {
int I[n], p[n], q[n], r[n], cnt = 0;
for (int i = 0; i < n; i++) {
cin >> I[i] >> p[i] >> q[i] >> r[i];
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
for (int i = 0; i < n; i++) {
if (p[i] * 4 + q[i] * 9 + r[i] * 4 <= C && p[i] <= P && q[i] <= Q &&
r[i] <= R) {
std::cout << i + 1 << std::endl;
cnt++;
}
}
if (cnt == 0) {
std::cout << "NA" << std::endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n;
while (cin >> n, n) {
int I[n], p[n], q[n], r[n], cnt = 0;
for (int i = 0; i < n; i++) {
cin >> I[i] >> p[i] >> q[i] >> r[i];
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
for (int i = 0; i < n; i++) {
if (p[i] * 4 + q[i] * 9 + r[i] * 4 <= C && p[i] <= P && q[i] <= Q &&
r[i] <= R) {
std::cout << I[i] << std::endl;
cnt++;
}
}
if (cnt == 0) {
std::cout << "NA" << std::endl;
}
}
return 0;
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 73]]
| 1
| 217
| 5
|
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int cal(int, int, int);
int main(void) {
int n;
while (cin >> n, n) {
int t[n], p[n], q[n], r[n];
rep(k, n) { cin >> t[k] >> p[k] >> q[k] >> r[k]; }
int P, Q, R, C;
cin >> P >> Q >> R >> C;
int cnt = 0;
rep(k, n) {
if (p[k] < P && q[k] < Q && r[k] < R && cal(p[k], q[k], r[k]) < C) {
cout << t[k] << endl;
cnt++;
}
}
if (cnt == 0) {
cout << "NA" << endl;
}
}
return 0;
}
int cal(int a, int b, int c) { return 4 * a + 9 * b + 4 * c; }
int StrToInt(string s) {
stringstream ss;
ss << s;
int val;
ss >> val;
return val;
}
string IntToStr(int i) {
stringstream ss;
ss << i;
return ss.str();
}
|
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int cal(int, int, int);
int main(void) {
int n;
while (cin >> n, n) {
int t[n], p[n], q[n], r[n];
rep(k, n) { cin >> t[k] >> p[k] >> q[k] >> r[k]; }
int P, Q, R, C;
cin >> P >> Q >> R >> C;
int cnt = 0;
rep(k, n) {
if (p[k] <= P && q[k] <= Q && r[k] <= R && cal(p[k], q[k], r[k]) <= C) {
cout << t[k] << endl;
cnt++;
}
}
if (cnt == 0) {
cout << "NA" << endl;
}
}
return 0;
}
int cal(int a, int b, int c) { return 4 * a + 9 * b + 4 * c; }
int StrToInt(string s) {
stringstream ss;
ss << s;
int val;
ss >> val;
return val;
}
string IntToStr(int i) {
stringstream ss;
ss << i;
return ss.str();
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 51, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 390
| 8
|
#include <stdio.h>
int main(void) {
int a, s[1001], d[1001], f[1001], g[1001], h[1001], i, j;
scanf("%d", &a);
while (a != 0) {
j = 0;
for (i = 1; i <= a + 1; i++) {
scanf("%d %d %d %d", &s[i], &d[i], &f[i], &g[i]);
h[i] = 4 * d[i] + 9 * f[i] + g[i] * 4;
}
for (i = 1; i <= a; i++) {
if (d[i] < s[a + 1] && f[i] < d[a + 1] && g[i] < f[a + 1] &&
h[i] < g[a + 1]) {
printf("%d\n", s[i]);
j = 1;
}
}
if (j == 0) {
printf("NA\n");
}
scanf("%d", &a);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, s[1001], d[1001], f[1001], g[1001], h[1001], i, j;
scanf("%d", &a);
while (a != 0) {
j = 0;
for (i = 1; i <= a + 1; i++) {
scanf("%d %d %d %d", &s[i], &d[i], &f[i], &g[i]);
h[i] = 4 * d[i] + 9 * f[i] + g[i] * 4;
}
for (i = 1; i <= a; i++) {
if (d[i] <= s[a + 1] && f[i] <= d[a + 1] && g[i] <= f[a + 1] &&
h[i] <= g[a + 1]) {
printf("%d\n", s[i]);
j = 1;
}
}
if (j == 0) {
printf("NA\n");
}
scanf("%d", &a);
}
return 0;
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 51, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 250
| 42
|
#include <cstdio>
int p[1000][4], q[4];
int main() {
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
scanf("%d", &p[i][j]);
}
}
for (int i = 0; i < 4; i++) {
scanf("%d", &q[i]);
}
bool NA = 1;
for (int i = 0; i < n; i++) {
int calorie = (p[i][1] + p[i][3]) * 4 + p[i][2] * 9;
if (p[i][1] <= q[0] && p[i][2] <= q[1] && p[i][3] <= q[2] &&
calorie <= p[i][3]) {
printf("%d\n", p[i][0]);
NA = 0;
}
}
if (NA)
printf("NA\n");
}
}
|
#include <cstdio>
int p[1000][4], q[4];
int main() {
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
scanf("%d", &p[i][j]);
}
}
for (int i = 0; i < 4; i++) {
scanf("%d", &q[i]);
}
bool NA = 1;
for (int i = 0; i < n; i++) {
int calorie = (p[i][1] + p[i][3]) * 4 + p[i][2] * 9;
if (p[i][1] <= q[0] && p[i][2] <= q[1] && p[i][3] <= q[2] &&
calorie <= q[3]) {
printf("%d\n", p[i][0]);
NA = 0;
}
}
if (NA)
printf("NA\n");
}
}
|
[["-", 51, 16, 12, 16, 12, 69, 28, 69, 28, 22], ["-", 12, 16, 12, 69, 28, 69, 341, 342, 0, 70], ["-", 12, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 12, 16, 12, 69, 28, 69, 341, 342, 0, 73], ["+", 15, 339, 51, 16, 12, 16, 12, 69, 28, 22]]
| 1
| 257
| 5
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
while (cin >> N, N) {
int num[1000], p[1000], q[1000], r[1000];
for (int i = 0; i < N; i++)
cin >> num[i] >> p[i] >> q[i] >> r[i];
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool NA = true;
for (int i = 0; i < N; i++) {
if (p[i] > P || q[i] > Q || r[i] > R || p[i] * 4 + q[i] * 9 + r[i] > C)
continue;
NA = false;
printf("%d\n", num[i]);
}
if (NA)
puts("NA");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
while (cin >> N, N) {
int num[1000], p[1000], q[1000], r[1000];
for (int i = 0; i < N; i++)
cin >> num[i] >> p[i] >> q[i] >> r[i];
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool NA = true;
for (int i = 0; i < N; i++) {
if (p[i] > P || q[i] > Q || r[i] > R ||
p[i] * 4 + q[i] * 9 + r[i] * 4 > C)
continue;
NA = false;
printf("%d\n", num[i]);
}
if (NA)
puts("NA");
}
}
|
[["+", 51, 16, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 51, 16, 12, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 196
| 2
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
int main() {
int N;
while (cin >> N && N) {
vector<int> ns(N), ps(N), qs(N), rs(N);
REP(i, N) cin >> ns[i] >> ps[i] >> qs[i] >> rs[i];
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool f = true;
REP(i, N) {
int p = ps[i], q = qs[i], r = rs[i], c = p * 4 + q + 9 + r * 4;
if (p > P || q > Q || r > R || c > C)
continue;
f = false;
cout << ns[i] << endl;
}
if (f)
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
int main() {
int N;
while (cin >> N && N) {
vector<int> ns(N), ps(N), qs(N), rs(N);
REP(i, N) cin >> ns[i] >> ps[i] >> qs[i] >> rs[i];
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool f = true;
REP(i, N) {
int p = ps[i], q = qs[i], r = rs[i], c = p * 4 + q * 9 + r * 4;
if (p > P || q > Q || r > R || c > C)
continue;
f = false;
cout << ns[i] << endl;
}
if (f)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 16, 31, 16, 17, 72], ["+", 49, 50, 51, 16, 31, 16, 12, 16, 17, 48]]
| 1
| 267
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1000000;
int a[] = {4, 4, 9};
int calc(vi v) {
int ret = 0;
for (int i = 1; i <= 3; i++) {
ret += v[i] * a[i - 1];
}
return ret;
}
int main() {
int n;
while (cin >> n && n > 0) {
vii v(n, vi(5, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
cin >> v[i][j];
v[i][4] = calc(v[i]);
}
vi m(5, 0);
for (int i = 1; i < 5; i++)
cin >> m[i];
vi ans;
for (int i = 0; i < n; i++) {
for (int j = 1; j < 5; j++) {
if (v[i][j] > m[j])
break;
if (j == 4)
ans.pb(v[i][0]);
}
}
if (ans.size() == 0)
cout << "NA" << endl;
else {
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1000000;
int a[] = {4, 9, 4};
int calc(vi v) {
int ret = 0;
for (int i = 1; i <= 3; i++) {
ret += v[i] * a[i - 1];
}
return ret;
}
int main() {
int n;
while (cin >> n && n > 0) {
vii v(n, vi(5, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
cin >> v[i][j];
v[i][4] = calc(v[i]);
}
vi m(5, 0);
for (int i = 1; i < 5; i++)
cin >> m[i];
vi ans;
for (int i = 0; i < n; i++) {
for (int j = 1; j < 5; j++) {
if (v[i][j] > m[j])
break;
if (j == 4)
ans.pb(v[i][0]);
}
}
if (ans.size() == 0)
cout << "NA" << endl;
else {
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
}
}
}
|
[["-", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13], ["-", 0, 30, 0, 43, 49, 50, 51, 83, 0, 21], ["+", 0, 30, 0, 43, 49, 50, 51, 83, 0, 21], ["+", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13]]
| 1
| 432
| 4
|
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;
struct data {
int num;
int p;
int q;
int r;
int kcal;
};
int main() {
int n;
struct data data[10005];
while (cin >> n, n) {
bool c = true;
rep(i, n) {
cin >> data[i].num >> data[i].p >> data[i].q >> data[i].r;
data[i].kcal = (data[i].p + data[i].r) * 4 + data[i].q * 9;
}
cin >> data[n].p >> data[n].q >> data[n].r >> data[n].kcal;
rep(i, n) {
if (data[i].p < data[n].p && data[i].q < data[n].q &&
data[i].r < data[n].r && data[i].kcal < data[n].kcal) {
cout << data[i].num << endl;
c = false;
}
}
if (c) {
cout << "NA" << endl;
}
}
}
|
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;
struct data {
int num;
int p;
int q;
int r;
int kcal;
};
int main() {
int n;
struct data data[10005];
while (cin >> n, n) {
bool c = true;
rep(i, n) {
cin >> data[i].num >> data[i].p >> data[i].q >> data[i].r;
data[i].kcal = (data[i].p + data[i].r) * 4 + data[i].q * 9;
}
cin >> data[n].p >> data[n].q >> data[n].r >> data[n].kcal;
rep(i, n) {
if (data[i].p <= data[n].p && data[i].q <= data[n].q &&
data[i].r <= data[n].r && data[i].kcal <= data[n].kcal) {
cout << data[i].num << endl;
c = false;
}
}
if (c) {
cout << "NA" << endl;
}
}
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 51, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 300
| 8
|
#include <stdio.h>
int main(void) {
int flg, a[1000], b[1000], c[1000], d[1000], A, B, C, D, n, i, x[1000];
while (1) {
flg = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
x[i] = 4 * b[i] + 9 * c[i] + 4 * d[i];
// printf("%d\n",x[i]);
}
scanf("%d %d %d %d", &A, &B, &C, &D);
for (i = 0; i < n; i++) {
if (x[i] <= D && b[i] <= A && c[i] <= B && d[i] <= C) {
flg = 1;
printf("%d\n", i + 1);
}
}
if (flg == 0) {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int flg, a[1000], b[1000], c[1000], d[1000], A, B, C, D, n, i, x[1000];
while (1) {
flg = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
x[i] = 4 * b[i] + 9 * c[i] + 4 * d[i];
// printf("%d\n",x[i]);
}
scanf("%d %d %d %d", &A, &B, &C, &D);
for (i = 0; i < n; i++) {
if (x[i] <= D && b[i] <= A && c[i] <= B && d[i] <= C) {
flg = 1;
printf("%d\n", a[i]);
}
}
if (flg == 0) {
printf("NA\n");
}
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73]]
| 1
| 251
| 5
|
#include <stdio.h>
int main(void) {
int n, j, i[1000], p[100], q[100], r[100], p2, q2, r2, c, flg, x[1000], cnt;
while (1) {
cnt = 0;
flg = 0;
scanf("%d", &n);
if (n == 0)
break;
for (j = 0; j < n; j++) {
scanf("%d %d %d %d", &i[j], &p[j], &q[j], &r[j]);
}
scanf("%d %d %d %d", &p2, &q2, &r2, &c);
for (j = 0; j < n; j++) {
if (p[j] <= p2 && q[j] <= q2 && r[j] <= r2 &&
p[j] * 4 + q[j] + r[j] * 4 <= c) {
x[cnt] = i[j];
cnt++;
flg = 1;
}
}
if (flg == 1) {
for (j = 0; j < cnt; j++) {
printf("%d\n", x[j]);
}
} else {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, j, i[1000], p[1000], q[1000], r[1000], p2, q2, r2, c, flg, x[1000],
cnt;
while (1) {
cnt = 0;
flg = 0;
scanf("%d", &n);
if (n == 0)
break;
for (j = 0; j < n; j++) {
scanf("%d %d %d %d", &i[j], &p[j], &q[j], &r[j]);
}
scanf("%d %d %d %d", &p2, &q2, &r2, &c);
for (j = 0; j < n; j++) {
if (p[j] <= p2 && q[j] <= q2 && r[j] <= r2 &&
p[j] * 4 + q[j] * 9 + r[j] * 4 <= c) {
x[cnt] = i[j];
cnt++;
flg = 1;
}
}
if (flg == 1) {
for (j = 0; j < cnt; j++) {
printf("%d\n", x[j]);
}
} else {
printf("NA\n");
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 12, 16, 31, 16, 31, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 276
| 8
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int i[1000], p[1000], q[1000], r[1000];
int P, Q, R, C;
bool flg = false;
for (int j = 0; j < n; j++) {
cin >> i[j] >> p[j] >> q[j] >> r[j];
}
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
if (p[j] < P && q[j] < Q && r[j] < R &&
((p[j] * 4 + q[j] * 9 + r[j] * 4) < C)) {
cout << i[j] << endl;
flg = true;
}
}
if (flg == false)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int i[1000], p[1000], q[1000], r[1000];
int P, Q, R, C;
bool flg = false;
for (int j = 0; j < n; j++) {
cin >> i[j] >> p[j] >> q[j] >> r[j];
}
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
if (p[j] <= P && q[j] <= Q && r[j] <= R &&
((p[j] * 4 + q[j] * 9 + r[j] * 4) <= C)) {
cout << i[j] << endl;
flg = true;
}
}
if (flg == false)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 51, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 339, 51, 16, 12, 23, 0, 16, 17, 18], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 19]]
| 1
| 206
| 8
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
while (cin >> a, a) {
vector<vector<int>> l(a);
for (int b = 0; b < a; b++) {
vector<int> r(4);
cin >> r[0] >> r[1] >> r[2] >> r[3];
l[b] = r;
}
vector<int> o(4);
cin >> o[0] >> o[1] >> o[2] >> o[3];
vector<int> s(0);
for (int c = 0; c < a; c++) {
if (l[c][1] <= o[0] && l[c][2] <= o[1] && l[c][3] <= o[2] &&
(l[c][1] + l[c][3]) * 4 + l[c][2] <= o[3])
s.push_back(l[c][0]);
}
if (s.size() == 0)
cout << "NA" << endl;
else {
for (int j : s)
cout << j << endl;
}
}
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
while (cin >> a, a) {
vector<vector<int>> l(a);
for (int b = 0; b < a; b++) {
vector<int> r(4);
cin >> r[0] >> r[1] >> r[2] >> r[3];
l[b] = r;
}
vector<int> o(4);
cin >> o[0] >> o[1] >> o[2] >> o[3];
vector<int> s(0);
for (int c = 0; c < a; c++) {
if (l[c][1] <= o[0] && l[c][2] <= o[1] && l[c][3] <= o[2] &&
(l[c][1] + l[c][3]) * 4 + l[c][2] * 9 <= o[3])
s.push_back(l[c][0]);
}
if (s.size() == 0)
cout << "NA" << endl;
else {
for (int j : s)
cout << j << endl;
}
}
}
|
[["+", 51, 16, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 51, 16, 12, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 272
| 2
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int i[1000], p[1000], q[1000], r[1000];
int main() {
int n;
while (cin >> n, n) {
vector<int> v;
rep(j, n) { cin >> i[j] >> p[j] >> q[j] >> r[j]; }
int P, Q, R, C;
cin >> P >> Q >> R >> C;
rep(j, n) {
if (p[j] <= P && q[j] <= R && r[j] <= R &&
4 * p[j] + 9 * q[j] + 4 * r[j] <= C)
v.push_back(i[j]);
}
if (v.empty())
puts("NA");
for (int i : v)
cout << i << endl;
}
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int i[1000], p[1000], q[1000], r[1000];
int main() {
int n;
while (cin >> n, n) {
vector<int> v;
rep(j, n) { cin >> i[j] >> p[j] >> q[j] >> r[j]; }
int P, Q, R, C;
cin >> P >> Q >> R >> C;
rep(j, n) {
if (p[j] <= P && q[j] <= Q && r[j] <= R &&
4 * p[j] + 9 * q[j] + 4 * r[j] <= C)
v.push_back(i[j]);
}
if (v.empty())
puts("NA");
for (int j : v)
cout << j << endl;
}
}
|
[["-", 51, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 338, 49, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 338, 49, 22], ["-", 0, 338, 8, 1, 0, 16, 31, 16, 12, 22], ["+", 0, 338, 8, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 206
| 6
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
struct Sweets {
Sweets() { id = protein = lipid = carbo = 0; }
Sweets(int arg_id, int arg_protein, int arg_lipid, int arg_carbo) {
id = arg_id;
protein = arg_protein;
lipid = arg_lipid;
carbo = arg_carbo;
}
int id, protein, lipid, carbo;
};
int main() {
int n, P, Q, R, C, count;
Sweets sweets[1000];
while (true) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d %d %d %d", &sweets[i].id, &sweets[i].protein, &sweets[i].lipid,
&sweets[i].carbo);
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
count = 0;
for (int i = 0; i < n; i++) {
if (sweets[i].protein <= P && sweets[i].lipid <= Q &&
sweets[i].carbo <= R &&
4 * (sweets[i].protein + sweets[i].carbo) + 7 * sweets[i].lipid <=
C) {
printf("%d\n", sweets[i].id);
count++;
}
}
if (count == 0)
printf("NA\n");
}
return 0;
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
struct Sweets {
Sweets() { id = protein = lipid = carbo = 0; }
Sweets(int arg_id, int arg_protein, int arg_lipid, int arg_carbo) {
id = arg_id;
protein = arg_protein;
lipid = arg_lipid;
carbo = arg_carbo;
}
int id, protein, lipid, carbo;
};
int main() {
int n, P, Q, R, C, count;
Sweets sweets[1000];
while (true) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d %d %d %d", &sweets[i].id, &sweets[i].protein, &sweets[i].lipid,
&sweets[i].carbo);
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
count = 0;
for (int i = 0; i < n; i++) {
if (sweets[i].protein <= P && sweets[i].lipid <= Q &&
sweets[i].carbo <= R &&
4 * (sweets[i].protein + sweets[i].carbo) + 9 * sweets[i].lipid <=
C) {
printf("%d\n", sweets[i].id);
count++;
}
}
if (count == 0)
printf("NA\n");
}
return 0;
}
|
[["-", 51, 16, 12, 16, 31, 16, 12, 16, 31, 13], ["+", 51, 16, 12, 16, 31, 16, 12, 16, 31, 13]]
| 1
| 309
| 2
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int a[n + 1][5], p = 0;
r(i, n + 1) {
cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
a[i][4] = a[i][1] * 4 + a[i][2] * 7 + a[i][3] * 4;
}
r(i, n) {
if (a[i][1] <= a[n][0] && a[i][2] <= a[n][1] && a[i][3] <= a[n][2] &&
a[i][4] <= a[n][3]) {
cout << a[i][0] << endl;
p++;
}
}
if (!p)
cout << "NA" << endl;
}
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int a[n + 1][5], p = 0;
r(i, n + 1) {
cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
a[i][4] = a[i][1] * 4 + a[i][2] * 9 + a[i][3] * 4;
}
r(i, n) {
if (a[i][1] <= a[n][0] && a[i][2] <= a[n][1] && a[i][3] <= a[n][2] &&
a[i][4] <= a[n][3]) {
cout << a[i][0] << endl;
p++;
}
}
if (!p)
cout << "NA" << endl;
}
}
|
[["-", 0, 11, 12, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 235
| 2
|
#include <stdio.h>
int main(void) {
int n, s[1000], i, p[1000], q[1000], r[1000], c[1000];
int P, Q, R, C, j;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &s[i], &p[i], &q[i], &r[i]);
c[i] = p[i] * 4 + q[i] * 9 + 4 * r[i];
}
scanf("%d %d %d %d", &P, &Q, &R, &C);
j = 0;
for (i = 0; i <= n; i++) {
if (P >= p[i] && Q >= q[i] && R >= r[i] && C >= c[i]) {
printf("%d\n", s[i]);
j++;
}
}
if (j == 0) {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, s[1000], i, p[1000], q[1000], r[1000], c[1000];
int P, Q, R, C, j;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &s[i], &p[i], &q[i], &r[i]);
c[i] = p[i] * 4 + q[i] * 9 + 4 * r[i];
}
// for(i=0;i<n;i++) printf(" s=%d\n",s[i]);
scanf("%d %d %d %d", &P, &Q, &R, &C);
j = 0;
for (i = 0; i < n; i++) {
if (P >= p[i] && Q >= q[i] && R >= r[i] && C >= c[i]) {
printf("%d\n", s[i]);
j++;
}
}
if (j == 0) {
printf("NA\n");
}
// printf("cccc\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 253
| 2
|
#include <stdio.h>
int main() {
int i, n, s[1024], p[1024], q[1024], r[1024], Q, R, P, C, m;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d%d%d%d", &s[i], &p[i], &q[i], &r[i]);
}
scanf("%d%d%d%d", &P, &Q, &R, &C);
m = 1;
for (i = 0; i < n; i++) {
if (p[i] <= P && q[i] <= Q && r[i] <= R &&
4 * p[i] + 9 * q[i] + 4 * q[i] <= C) {
printf("%d\n", s[i]);
m = 0;
}
}
if (m) {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int i, n, s[1024], p[1024], q[1024], r[1024], Q, R, P, C, m;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d%d%d%d", &s[i], &p[i], &q[i], &r[i]);
}
scanf("%d%d%d%d", &P, &Q, &R, &C);
m = 1;
for (i = 0; i < n; i++) {
if (p[i] <= P && q[i] <= Q && r[i] <= R &&
4 * p[i] + 9 * q[i] + 4 * r[i] <= C) {
printf("%d\n", s[i]);
m = 0;
}
}
if (m) {
printf("NA\n");
}
}
return 0;
}
|
[["-", 12, 16, 31, 16, 12, 16, 12, 69, 28, 22], ["+", 12, 16, 31, 16, 12, 16, 12, 69, 28, 22]]
| 1
| 235
| 2
|
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct food {
int p, q, r, id;
food(int p_, int q_, int r_, int id_) {
p = p_;
q = q_;
r = r_;
id = id_;
}
food() { p = q = r = id = 0; }
int cal() { return p * 4 + q * 9 + r * 4; }
};
int main() {
int n;
while (cin >> n, n) {
vector<food> v;
for (int i = 0; i < n; i++) {
int id, p, q, r;
cin >> id >> p >> q >> r;
v.push_back(food(p, q, r, id));
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool flag = false;
for (int i = 0; i < v.size(); i++) {
if (v[i].p < P && v[i].q < Q && v[i].r < R && v[i].cal() < C) {
flag = true;
cout << v[i].id << endl;
}
}
if (!flag) {
cout << "NA" << endl;
}
}
}
|
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct food {
int p, q, r, id;
food(int p_, int q_, int r_, int id_) {
p = p_;
q = q_;
r = r_;
id = id_;
}
food() { p = q = r = id = 0; }
int cal() { return p * 4 + q * 9 + r * 4; }
};
int main() {
int n;
while (cin >> n, n) {
vector<food> v;
for (int i = 0; i < n; i++) {
int id, p, q, r;
cin >> id >> p >> q >> r;
v.push_back(food(p, q, r, id));
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool flag = false;
for (int i = 0; i < v.size(); i++) {
if (v[i].p <= P && v[i].q <= Q && v[i].r <= R && v[i].cal() <= C) {
flag = true;
cout << v[i].id << endl;
}
}
if (!flag) {
cout << "NA" << endl;
}
}
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["-", 51, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 282
| 8
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int n;
int num[1001], p[1001], q[1001], r[1001], cal[1001];
while (cin >> n, n) {
for (int i = 0; i < 1001; i++) {
num[i] = p[i] = q[i] = r[i] = cal[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> num[i] >> p[i] >> q[i] >> r[i];
cal[i] = p[i] + q[i] + r[i];
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool flag = 1;
for (int i = 0; i < n; i++) {
if (p[i] <= P && q[i] <= Q && r[i] <= R && cal[i] <= C) {
cout << num[i] << endl;
flag = 0;
}
}
if (flag)
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int n;
int num[1001], p[1001], q[1001], r[1001], cal[1001];
while (cin >> n, n) {
for (int i = 0; i < 1001; i++) {
num[i] = p[i] = q[i] = r[i] = cal[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> num[i] >> p[i] >> q[i] >> r[i];
cal[i] = p[i] * 4 + q[i] * 9 + r[i] * 4;
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool flag = 1;
for (int i = 0; i < n; i++) {
if (p[i] <= P && q[i] <= Q && r[i] <= R && cal[i] <= C) {
cout << num[i] << endl;
flag = 0;
}
}
if (flag)
cout << "NA" << endl;
}
return 0;
}
|
[["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 13], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
| 1
| 258
| 6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.