C题
#include
#include
using namespace std;
char mp[3][3];
int x, o;
int flag;
bool cal(char tar) {
for (int i = 0; i < 3; ++i) {
if (mp[0][i] == tar) {
if (mp[1][i]==tar && mp[2][i]==tar) {
return true;
}
}
}
for (int i = 0; i < 3; ++i) {
if (mp[i][0] == tar) {
if (mp[i][1]==tar && mp[i][2]==tar) {
return true;
}
}
}
if (mp[0][0]==tar && mp[1][1]==tar && mp[2][2]==tar) {
return true;
}
if (mp[0][2]==tar && mp[1][1]tar && mp[2][0]tar) {
return true;
}
return false;
}
int main() {
int n;
cin >> n;
while (n–) {
flag = x = o = 0;
for (int i = 0; i < 3; ++i) {
scanf("%s", mp[i]);
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (mp[i][j] == ‘X’) {
x++;
}
else if (mp[i][j] == ‘O’) {
o++;
}
}
}
if (x >= o) {
if (x == o) {
flag = cal(‘X’) ? 0 : 1;
}
else if (x - o == 1) {
flag = cal(‘O’) ? 0 : 1;
}
else {
flag = 0;
}
}
else {
flag = 0;
}
printf("%s\n", flag1 ? “yes” : “no”);
}
return 0;
}
这题刚开始也不会做,看了答案后有了一点思路。这题主要是要把思路理清,条件一定要考虑全面。
难点在于不知道怎么改成c语言。
D题
#include <bits/stdc++.h>
using namespace std;
const long long FACT1 = 10000;
const long long FACT2 = 6227020800;
const int N = 13;
long long fact[N + 1];
void init()
{
fact[0] = 1;
for(int i=1; i<=N; i++) {
fact[i] = i * fact[i - 1];
}
}
int main()
{
init();
int n;
while(~scanf("%d", &n))
if(n > N || (n < 0 && (n * -1 & 1) 1))
printf(“Overflow!\n”);
else if(fact[n] < FACT1 || (n < 0 && (n * -1 & 1) == 0))
printf(“Underflow!\n”);
else
printf("%lld\n", fact[n]);
return 0;
}
开始也不会做,看了答案后还行。感觉题目迷惑性很大但读懂后就是简单的递归。
难点在于不知道怎么改成c语言。
E题
#include
#include
using namespace std;
int f[21][21][21];
int w(int a,int b,int c){
if (a <= 0 || b <= 0 || c <= 0)return 1;
if (a > 20 || b > 20 || c > 20)return w(20, 20, 20);
if (f[a][b][c])return f[a][b][c];
return f[a][b][c] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a -
1, b, c - 1) - w(a - 1, b - 1, c - 1);
}
int main() {
memset(f, 0, sizeof(f));
int a, b, c;
while (cin >> a >> b >> c) {
if (a == -1 && b == -1 && c == -1)break;
cout <<“w(”<<a<<", “<<b<<”, “<<c<<”) = “<< w(a, b, c) <<
endl;
}
return 0;
}
这题刚开始也不会做,听了讲解后发现是递归,重点在于去掉重复的计算,节省时间。
难点在于不知道怎么改成c语言。
|