2026.04.23
T754793 智商测试
题意
有一个
目的
求是否能通过将最多一个单元格重新涂成另一种颜色,让这幅图包含一个完全由相同颜色单元格组成的
思路
以
代码
#include <bits/stdc++.h>
using namespace std;
char c[5][5];
int main()
{
for(int i = 1; i <= 4; i++)
{
for(int j = 1; j <= 4; j++)
{
cin >> c[i][j];
if(i >= 2 && j >= 2)
{
int t = (c[i - 1][j - 1] == '#')
+ (c[i][j - 1] == '#') + (c[i - 1][j] == '#')
+ (c[i][j] == '#');
if(max(t, 4 - t) >= 3)
{
cout << "YES";
return 0;
}
}
}
}
cout << "NO";
return 0;
}
T754802 品牌重造
题意
一家公司的名称由
目的
求最终名称。
思路
建立一个字符数组,将每个索引位置的数值改为对应 ASCII 码的字符,随后按照设计师的方案更改(将数组中对应 ASCII 码的索引位置的数值更改),最后依照原名的每个字符改为数组中对应 ASCII 码的索引位置的数值。
代码
#include <bits/stdc++.h>
using namespace std;
char a[200005], b[200005];
int main()
{
int n, m;
string s;
cin >> n >> m >> s;
while(m--)
{
char x, y;
cin >> x >> y;
if(x != y)
{
for(int i = 0; i < s.size(); i++)
{
if(s[i] == x)
{
s[i] = y;
}
else if(s[i] == y)
{
s[i] = x;
}
}
}
}
cout << s;
return 0;
}
AC 代码
#include <bits/stdc++.h>
using namespace std;
char a[int('z')];
int main()
{
int n, m;
string s;
cin >> n >> m >> s;
for(char i = 'a'; i <= 'z'; i++)
{
a[int(i)] = i;
}
while(m--)
{
char x, y;
cin >> x >> y;
for(char i = 'a'; i <= 'z'; i++)
{
if(a[int(i)] == x)
{
a[int(i)] = y;
}
else if(a[int(i)] == y)
{
a[int(i)] = x;
}
}
}
for(int i = 0; i < s.size(); i++)
{
s[i] = a[int(s[i])];
}
cout << s;
return 0;
}
错因
按照题意模拟而导致超时。
T754804 新年礼物
题意
把
- 前往当前钱包左边的钱包(如果有的话)
- 前往当前钱包右边的钱包(如果有的话)
- 向当前钱包投币。
由于某些技术故障,机器人无法连续执行两个 投币 指令。
目的
输出最多
思路
先输出 RLP,再在第 LRP。
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, x;
cin >> n;
cin >> x;
if(x)
{
cout << 'P';
x--;
for(int i = 1; i <= x; i++)
{
cout << "LRP";
}
}
n--;
while(n--)
{
cout << 'R';
cin >> x;
if(!x)
{
continue;
}
cout << 'P';
x--;
for(int i = 1; i <= x; i++)
{
cout << "LRP";
}
}
return 0;
}
AC 代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, x;
cin >> n;
if(n)
{
cin >> x;
if(x)
{
cout << 'P';
x--;
for(int i = 1; i <= x; i++)
{
cout << "RLP";
}
}
n--;
}
while(n--)
{
cout << 'R';
cin >> x;
if(!x)
{
continue;
}
cout << 'P';
x--;
for(int i = 1; i <= x; i++)
{
cout << "LRP";
}
}
return 0;
}
错因
未考虑到再第一个钱包时不可使用 L 指令。