@Dmaxiya
2018-08-17T02:30:07.000000Z
字数 3931
阅读 1180
Codeforces
Contests 链接:Codeforces Round #454(Div.2)
过题数:3
排名:628/5566
有三只熊,熊爸熊妈和熊儿子,熊爸能爬得上并且喜欢大车,熊妈能爬得上中车且喜欢中车,熊儿子能爬得上小车且喜欢小车, 能爬得上小车且只喜欢小车。对于一只体积为 的角色,如果它能爬得上一辆体积为 车,它必须满足条件 ,如果它喜欢一辆车,那么它必须满足条件 ,现在给出三只熊和 的体积 ,问能否找到满足以上条件的三辆车,如果能找得到,则输出这三辆车的体积,否则输出 。
对 分几种情况讨论一下就行了,情况比较多,所以 语句比较多。要注意 只喜欢小车的条件。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>#include <functional>#include <iomanip>using namespace std;#define LL long longint a, b, c, d;int main() {#ifdef LOCALfreopen("test.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCAL// ios::sync_with_stdio(false);while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF) {a *= 2;b *= 2;if(d <= c) {if(2 * d >= c && 2 * d < b) {printf("%d\n%d\n%d\n", a, b, c);} else {printf("-1\n");}} else {if(d <= 2 * c) {c = d;if(d * 2 < b) {printf("%d\n%d\n%d\n", a, b, c);} else {printf("-1\n");}} else {printf("-1\n");}}}return 0;}
给定一个 的九宫格,对于每个宫格,都是一个 的方阵,两个人轮流下落子,如果一个人落在某个宫格的第 行第 列,那么另一个人就可以在第 行第 列的宫格中的任意一个位置落子,如果第 行第 列的宫格已经落满了子,那么另一个人可以在整个宫格中的任意一个地方落子。给定初始局面,和最后一个落子的坐标,输出另一个人可能可以落子的位置。
按照题意模拟就行了。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>#include <functional>#include <iomanip>using namespace std;#define LL long longint n, m;char str[3][3][3][10];int main() {#ifdef LOCALfreopen("test.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCAL// ios::sync_with_stdio(false);for(int i = 0; i < 9; ++i) {for(int j = 0; j < 3; ++j) {scanf("%s", str[i / 3][j][i % 3]);}}scanf("%d%d", &n, &m);--n;--m;int row = n % 3;int col = m % 3;bool flag = false;for(int i = 0; i < 3; ++i) {for(int j = 0; j < 3; ++j) {if(str[row][col][i][j] == '.') {flag = true;}}}if(flag) {for(int i = 0; i < 3; ++i) {for(int j = 0; j < 3; ++j) {if(str[row][col][i][j] == '.') {str[row][col][i][j] = '!';}}}} else {for(int i = 0; i < 3; ++i) {for(int j = 0; j < 3; ++j) {for(int ii = 0; ii < 3; ++ii) {for(int jj = 0; jj < 3; ++jj) {if(str[i][j][ii][jj] == '.') {str[i][j][ii][jj] = '!';}}}}}}for(int i = 0; i < 9; ++i) {for(int j = 0; j < 3; ++j) {if(j != 0) {printf(" ");}printf("%s", str[i / 3][j][i % 3]);}printf("\n");if(i % 3 == 2) {printf("\n");}}return 0;}
有一个人,他要猜一个字符,如果他说的单词中包含了这个字符,他就会被 一下,如果他说的单词中没有包含这个字符,他就没事,他还可以猜这个字符,如果他猜错了,他仍然会被 一下。因为这个人反应比较慢,所以他本来早就可以猜出答案了,结果却要被多 几下才能猜到最后的答案,问如果按照他的提问顺序,他可以少被 几下?
用两个集合 和 来维护,先把 初始化,把 到 的小写字符全都放进去,对于后面每一次被 的提问,都取当前单词和 里的字符的交集,对于每一次没有被 的提问,都把当前的单词记录到 集合里,每次都从 集合里删去 集合里的字符。当 集合的大小为 时,就可以得到答案,对于后面的提问,就按照题意来模拟就行了。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>#include <functional>#include <iomanip>using namespace std;#define LL long longconst int maxn = 100000 + 100;int n;char ch[2];char str[maxn];set<char> st, Not;char ans;int main() {#ifdef LOCALfreopen("test.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCAL// ios::sync_with_stdio(false);while(scanf("%d", &n) != EOF) {ans = '\0';int ccnt = 0;st.clear();Not.clear();for(char c = 'a'; c <= 'z'; ++c) {st.insert(c);}for(int i = 0; i < n; ++i) {scanf("%s%s", ch, str);if(ans != '\0') {if(ch[0] == '!') {++ccnt;} else if(ch[0] == '?' && str[0] != ans) {++ccnt;}} else {if(ch[0] == '!') {set<char> tmp;for(int j = 0; str[j]; ++j) {if(st.find(str[j]) != st.end()) {tmp.insert(str[j]);}}st = tmp;} else if(ch[0] == '.') {for(int j = 0; str[j]; ++j) {Not.insert(str[j]);}} else if(ch[0] == '?') {for(int j = 0; str[j]; ++j) {Not.insert(str[j]);}}for(set<char>::iterator it = Not.begin(); it != Not.end(); ++it) {st.erase(*it);}if(st.size() == 1) {set<char>::iterator it = st.begin();ans = *it;}}}printf("%d\n", ccnt);}return 0;}