A、构造二阶行列式
数字不大,直接四重循环暴力枚举
#include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
for (int i = 1; i <= 20; i++) {
for (int j =1; j < 20;j++) {
for (int x1 = 1;x1 <= 20;x1++) {
for (int y = 1;y<=20;y++){
if (i * j - x1 * y == x) {
cout << i << ' ' << y << endl;
cout << x1 << ' ' << j << endl;
return 0;
}
}
}
}
}
cout << -1 << endl;
return 0;
}
B、挑战boss
回合制游戏模拟,相当于循环轮次更新状态。主要是有普通攻击和连击伤害两种。连击伤害有权重,权重在每回合躲开boss技能后自增,被击中清0。代码如下:
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, a, b;
string s;
cin >> n >> a >> b;
cin >> s;
int k = 0;
long int sum = 0;
for (int i = 0; i < n; i++) {
sum += a + k * b;
if (s[i] == 'x') k = 0;
else k++;
}
cout << sum << endl;
}
C、国际象棋
首先要说明下我觉得这题有点问题,给的判定示例中倒数第三个示例我觉得应该是2。依据如下:
首先将x方向和y方向的距离相减取绝对值得到dx和dy。象可以让dx和dy同时减k(k为任意整数),马可以让dx-2,dy-1或者dx-1,dy-2。我们这里简化下取l为两者中最大值,w为两者中最小值。那么要是l==w,用象可以一步到达。l != x时,有下图可以说明当l-w为偶数时可以两步到达
当l-w为奇数时先走一步马将l-=2,w-=1后l-w仍为偶数,此时如果l == w,再走一步即可到达,否则继续走两步也可到达。但判题样例中有些样例给的走的步数是偏多了的。希望能够给到网站制作者和其他刷题者以帮助和借鉴。
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == 0 && x2 == 0) {
cout << 1 << endl;
continue;
}
int l = abs(x2 - x1);
int w = abs(y2 - y1);
if (l == w) {
cout << 1 << endl;
continue;
} else {
if ((l - w) % 2 == 0) {
cout << 2 << endl;
continue;
}
if (abs(l - 2) == abs(w - 1)) {
cout << 2 << endl;
continue;
} else {
cout << 3 << endl;
continue;
}
}
}
return 0;
}