2021ICPC冬令营集训日志day1【Liar】
作者:互联网
杂谈
啊呀能进灵动实验室真不容易,早上路上堵得很结果迟到了还让老师等了将近半小时,罪过啊,好对不起我坤哥。坤哥yyds,吹爆坤哥!谢谢坤坤带我~
一、初来乍到
啊!这! vjudge是啥!? 怎么用啊! 题目怎么都是英文的! 啊,这! 还好有ppt,芜湖,起飞~
二、今日总结
1.课堂听讲
早上好困啊好热啊,听着听着眼皮就打架了。还是得强撑着疲惫的身躯,挺老师讲题,好高端啊,都是外国的题,长见识了,人生视野又拓宽了呢。
一个半小时讲完我一学期学的知识点并且还讲了好多道题目。。
吴永辉老师,强的吧。
接下来就是满徐州的找电源线环节,最后以581的价格买到了我的电源线,拯救大兵韩佩霖。
2.题目练习
链接放到这里
密码:2021WinterCamp
1.签到题,没啥好说的
2.Pig Latin (字符串处理)
大体思路:重复读入一行字符串buffer,遍历这个字符串,如果找到字母就向下截取这个单词,根据题目要求判断元音之类的并进行相应操作然后输出
3.井字棋
WA代码:
#include <stdio.h>
int main (void) {
char a[4][4] = {0};
int cnto = 0, cntx = 0;
int win[2] = {-1, -1}, cnt = 0;
int n;
scanf("%d", &n);
getchar();
while (n--) {
for (int i = 0; i < 3; ++i)
gets(a[i]);//input the blank
cnto = 0, cntx = 0, cnt = 0;
//1 and 2
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
if (a[i][j] == 'O') cnto++;
else if (a[i][j] == 'X') cntx++;
}
if (cnto > cntx || cntx - cnto >= 2) {
printf("no\n");
continue;
}
for (int i = 0; i < 3; ++i) {
if (a[i][0] == a[i][1] && a[i][0] == a[i][2] && a[i][0] != '.') win[cnt++] = a[i][0];
}
for (int i = 0; i < 3; ++i) {
if (a[0][i] == a[1][i] && a[0][i] == a[2][i] && a[0][i] != '.') win[cnt++] = a[0][i];
}
if (a[0][0] == a[1][1] && a[0][0] == a[2][2] && a[0][0] != '.') win[cnt++] = a[0][0];
if (a[0][2] == a[1][1] && a[1][1] == a[2][0] && a[0][2] != '.') win[cnt++] = a[0][2];
if (win[1] != -1 && win[0] != -1 || win[0] == 'O' && cnto != cntx || win[0] == 'X' && cntx == cnto) {
printf("no\n");
continue;
}
printf("yes\n");
if (n) getchar();
}
return 0;
}
思路:五种情况,满足一种就输出no。前两种不用说了,后面三中就是对出现赢家的情况进行分析,但是貌似是这里出现了逻辑漏洞,导致没有AC, 想不太明白怎么办,这里贴上我的AC代码
#include <stdio.h>
char a[3][3] = {0};
int findwinnerX () {
char win;
for (int i = 0; i < 3; ++i) {
if (a[0][i] == a[1][i] && a[0][i] == a[2][i] && a[0][i] == 'X') win = 1;
else if (a[i][0] == a[i][1] && a[i][0] == a[i][2] && a[i][0] == 'X') win = 1;
}
if (a[0][0] == a[1][1] && a[0][0] == a[2][2] && a[0][0] == 'X'|| a[1][1] == a[0][2] && a[1][1] == a[2][0] && a[0][2] == 'X') win = 1;
return win;
}
int findwinnerO () {
char win;
for (int i = 0; i < 3; ++i) {
if (a[0][i] == a[1][i] && a[0][i] == a[2][i] && a[0][i] == 'O') win = 1;
else if (a[i][0] == a[i][1] && a[i][0] == a[i][2] && a[i][0] == 'O') win = 1;
}
if (a[0][0] == a[1][1] && a[0][0] == a[2][2] && a[0][0] == 'O'|| a[1][1] == a[0][2] && a[1][1] == a[2][0] && a[0][2] == 'O') win = 1;
return win;
}
int main (void) {
int n;
scanf("%d", &n);
// getchar();
while (n--) {
for (int i = 0; i < 3; ++i)
{
scanf("%s", a[i]);
// gets(a[i]);
}
int cnto = 0, cntx = 0, win;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
{
if (a[i][j] == 'O') cnto++;
else if (a[i][j] == 'X') cntx++;
}
if (cnto > cntx || cntx - cnto > 1) {
printf("no\n");
continue;
}
else if (cnto == cntx) {
if (findwinnerX() == 1) {
printf("no\n");
continue;
}
else {
printf("yes\n");
continue;
}
}
else {
if (findwinnerO() == 1) {
printf("no\n");
continue;
}
else {
printf("yes\n");
continue;
}
}
printf("yes\n");
// if(n) getchar();
}
return 0;
}
4.5.递归!
等等,今天我学到了一个重要的知识点:记忆化
简单的说,就是用数组记录递归结果已达到简化运算过程,防止重复运算的目的。
下面放一个我自己写的和学长写的
自己的:
long long v[21][21][21] = {0};
long long 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 (a < b && b < c) {
if (v[a][b][c - 1] == 0) v[a][b][c - 1] = w(a, b, c - 1);
if (v[a][b - 1][c - 1] == 0) v[a][b - 1][c - 1] = w(a, b - 1, c - 1);
if (v[a][b - 1][c] == 0) v[a][b - 1][c] = w(a, b - 1, c);
return v[a][b][c - 1] + v[a][b - 1][c - 1] - v[a][b - 1][c];
}
else {
if (v[a - 1][b][c] == 0) v[a - 1][b][c] = w(a - 1, b, c);
if (v[a - 1][b - 1][c] == 0) v[a - 1][b - 1][c] = w(a - 1, b - 1, c);
if (v[a - 1][b][c - 1] == 0) v[a - 1][b][c - 1] = w(a - 1, b, c - 1);
if (v[a - 1][b - 1][c - 1] == 0) v[a - 1][b - 1][c - 1] = w(a - 1, b - 1, c - 1);
return v[a - 1][b][c] + v[a - 1][b - 1][c] + v[a - 1][b][c - 1] - v[a - 1][b - 1][c - 1];
}
}
学长的
long long v[21][21][21] = {0};
long long 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 (v[a][b][c]) return v[a][b][c];
if (a < b && b < c) {
return v[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
}
else {
return v[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);
}
}
#### 6.数据太大,递归太久,找规律 #### 7.结构体,慢慢写,没啥说的
总结
坐着编程,编了很久。写不出来,感觉还行。
今天就这,上床睡觉。再接再厉,争创辉煌。
标签:cnto,Liar,冬令营,int,win,2021ICPC,++,&&,20 来源: https://blog.csdn.net/m0_52407463/article/details/112794989