话说每天都在写水题啊,难题也不想写,算法也不想学,工程技术也不想学,就想着打游戏看小说,好颓废hh

狗和猫

超级水,看清题意模拟就好了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int n, d, c, m;

signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int t;
cin >> t;
for (int cas = 1; cas <= t; cas ++)
{
cin >> n >> d >> c >> m;
string s;
cin >> s;
bool flag = true;
for (int i = 0; i < s.size(); i ++)
{
if (s[i] == 'D')
if(d)
{
c += m;
d--;
}
else
{
flag = false;
break;
}
else
if (c)
c--;
else
{
for (int j = i; j < s.size(); j ++)
if (s[j] == 'D')
{
flag = false;
}
break;
}
}

if (flag)
cout << "Case #" << cas << ": " << "YES" << endl;
else
cout << "Case #" << cas << ": " << "NO" << endl;

}
}

3326. 最大硬币数

由于每个格子里没有负数,所以直接累加对角线就行了,
// 主对角线的坐标, 坐标差值是相等的, 即 i - j 相同, 加n是为了防止负数出现
// 斜对角线的坐标 i + j 相同
这个处理方式在n皇后问题中出现过

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 1005;
int a[N][N];
LL f[2 * N + 5]; // 对角线数组

signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int t;
cin >> t;
for (int cas = 1; cas <= t; cas ++)
{
int n;
cin >> n;
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= n; j ++)
{
cin >> a[i][j];
f[i - j + n] += a[i][j];
}
}
LL maxn = 0;
for (int i = 1; i <= 2 * n - 1; i ++ )
{
maxn = max(f[i], maxn);
}

cout << "Case #" << cas << ": " << maxn << endl;
}
}