【101】特殊的正方形(5.3)
链接:特殊的正方形 - 题目 - Daimayuan Online Judge
大意:
奇数圈是‘+’,偶数圈是‘.’
解题思路:
模拟就好
代码:
#include <bits/stdc++.h>
using namespace std;
char ch[103][103];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
ch[i][j] = '#';
}
}
int t = n / 2;
if (n & 1) t++;
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= n; j++) {
if (i & 1) {
if (ch[i][j] == '#') {
ch[i][j] = '+';
}
if (ch[n - i + 1][j] == '#') {
ch[n - i + 1][j] = '+';
}
if (ch[j][i] == '#') {
ch[j][i] = '+';
}
if (ch[j][n - i + 1] == '#') {
ch[j][n - i + 1] = '+';
}
} else {
if (ch[i][j] == '#') {
ch[i][j] = '.';
}
if (ch[n - i + 1][j] == '#') {
ch[n - i + 1][j] = '.';
}
if (ch[j][i] == '#') {
ch[j][i] = '.';
}
if (ch[j][n - i + 1] == '#') {
ch[j][n - i + 1] = '.';
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cout << ch[i][j];
}
cout << "\n";
}
}
【102】走楼梯2(div2)(5.3)
链接:
走楼梯2 - 题目 - Daimayuan Online Judge
大意:
n阶台阶,可以上一阶或者两阶,但不能连续上三次2阶
解题思路:
定义f[i][j]为当前是第i个台阶,已经连续走了j个二阶。
对于j!=2的情况,f[i+2][j+1] += f[i][j]//走两阶
其他 f[i+1][0]+=f[i][j]//走一阶
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int f[103][3];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
f[0][0] = 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 2; j++) {
if (j != 2) f[i + 2][j + 1] += f[i][j];
f[i + 1][0] += f[i][j];
}
}
cout << f[n][0] + f[n][1] + f[n][2];
}
【103】走路
链接:走路 - 题目 - Daimayuan Online Judge
大意:
走n步,可以向右走a[i],也可以向左走b[i],问0-m,哪些可以走到
解题思路:
类似背包
f[i][j]表示当前第i步,走到j。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 107;
bool f[103][N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
f[0][0] = true;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
for (int j = m; j >= min(a,b); j--) {
f[i][j] |= f[i - 1][j - min(a,b)];
if (j >= max(a,b)) f[i][j] |= f[i - 1][j - max(a,b)];
}
}
for (int i = 0; i <= m; i++) {
if (f[n][i]) cout << "1";
else cout << "0";
}
}
【104】简单分数统计
链接:简单分数统计 - 题目 - Daimayuan Online Judge
大意:
告诉你人和题目分数,以及人的过题状态,统计最终分数。
解题思路:
模拟就好
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 107;
string a[N];
set<string>st;
map<string,int>mp, ans;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
st.insert(a[i]);
}
for (int i = 1; i <= m; i++) {
string s;
int t;
cin >> s >> t;
mp[s] = t;
}
for (int i = 1; i <= k; i++) {
string name, ques, t;
cin >> name >> ques >> t;
if (st.count(name)) {
if (t == "AC") {
ans[name] += mp[ques];
}
}
}
for (int i = 1; i <= n; i++) {
cout << a[i] << " " << ans[a[i]] << "\n";
}
return 0;
}
【105】Alice的德州扑克
链接:Alice的德州扑克 - 题目 - Daimayuan Online Judge
大意:
告诉你德扑的花形,根据优先级判断输出
解题思路:
模拟就好
代码:
#include <bits/stdc++.h>
using namespace std;
int a[5], b[5];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 5; i++) cin >> a[i];
for (int i = 0; i < 5; i++) cin >> b[i];
int f1 = 1, f2 = 1;
for (int i = 0; i < 4; i++) {
if (a[i] + 1 != a[i + 1]) {
f1 = 0;
break;
}
}
for (int i = 0; i < 4; i++) {
if (b[i] != b[i + 1]) {
f2 = 0;
break;
}
}
if (f1 && f2) {
if (a[4] == 14) {
cout << "ROYAL FLUSH\n";
return 0;
} else {
cout << "STRAIGHT FLUSH\n";
return 0;
}
}
int f = 1;
for (int i = 0; i < 4; i++) {
if (a[i] != a[i + 1]) {
f = 0;
break;
}
}
if (f) {
cout << "FOUR OF A KIND\n";
return 0;
}
int num = 0;
for (int i = 0; i < 4; i++) {
if (a[i] == a[i + 1]) num++;
}
if (num == 3) {
if (a[0] != a[1] || a[3] != a[4]) {
cout << "FOUR OF A KIND\n";
return 0;
} else {
cout << "FULL HOUSE\n";
return 0;
}
}
if (f2) {
cout << "FLUSH\n";
return 0;
}
if (f1) {
cout << "STRAIGHT\n";
return 0;
}
cout << "FOLD\n";
return 0;
}
1622

被折叠的 条评论
为什么被折叠?



