标签:
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
while (cin >> str) {
vector<int> ab;
vector<int> ba;
for (int i = 0; i < str.length() - 1; ++i) {
if (str[i] == ‘A‘ && str[i + 1] == ‘B‘) {
ab.push_back(i);
} else if (str[i] == ‘B‘ && str[i + 1] == ‘A‘) {
ba.push_back(i);
}
}
bool flag = false;
for (int i = 0; i < ab.size(); ++i) {
for (int j = 0; j < ba.size(); ++j) {
if (abs(ab[i] - ba[j]) > 1) {
flag = true;
break;
}
}
if (flag) {
break;
}
}
cout << (flag ? "YES" : "NO") << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int MAX = 16;
int sum[MAX];
int c[MAX];
int n, l, r, x;
bool check(int state) {
int sum = 0, mind = 0xfffffff, maxd = -1;
for (int i = 0; i < n; ++i) {
if (state & 1) {
sum += c[i];
if (c[i] > maxd) {
maxd = c[i];
}
if (c[i] < mind) {
mind = c[i];
}
}
state >>= 1;
}
if (sum < l || sum > r || (maxd - mind) < x) {
return false;
}
return true;
}
int main() {
while (~scanf(" %d %d %d %d", &n, &l, &r, &x)) {
for (int i = 0; i < n; ++i) {
scanf(" %d", c + i);
}
sort(c, c + n);
memset(sum, 0, sizeof(sum));
sum[0] = c[0];
for (int i = 1; i < n; ++i) {
sum[i] = sum[i - 1] + c[i];
}
int ans = 0;
for (int i = 0; i < (1 << n); ++i) {
if (check(i)) {
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
pair<bool, string> judge1(string x) {
for (int i = x.length() - 1; i >= 0; --i) {
if (x[i] == ‘0‘) {
return make_pair(true, "0");
}
}
return make_pair(false, "joke");
}
bool judge2(int x) {
if (x == 0) {
return false;
}
while (x) {
if (x % 10 == 0) {
return false;
}
x /= 10;
}
return true;
}
string toString(int x) {
string res = "";
if (x == 0) {
res = "0";
}
while (x) {
res = (char)(x % 10 + ‘0‘) + res;
x /= 10;
}
return res;
}
void init(vector<string>& x) {
for (int i = 1; i < 1000; ++i) {
if (i % 8 == 0 && judge2(i)) {
//printf("push %d\n", i);
x.push_back(toString(i));
}
}
}
pair<bool, string> judge3(string x, string sub) {
//cout << "Judge3(" << x << ", " << sub << ")" << endl;
int i = 0, j = 0;
while (i < x.size() && j < sub.size()) {
if (x[i] == sub[j]) {
++i;
++j;
} else {
++i;
}
}
if (j == sub.size()) {
return make_pair(true, sub);
} else {
return make_pair(false, "fuck");
}
}
int main() {
//cout << toString(344) << endl;
vector<string> box;
init(box);
string num;
while (cin >> num) {
pair<bool, string> ans = judge1(num);
if (ans.first) {
cout << "YES\n0" << endl;
} else {
bool flag = false;
for (int i = 0; i < box.size(); ++i) {
ans = judge3(num, box[i]);
if (ans.first) {
cout << "YES\n" << ans.second << endl;
flag = true;
break;
}
}
if (!flag) {
cout << "NO" << endl;
}
}
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/bit_line/article/details/46447303