CF152A - Marks(思维)

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
55
56
//https://codeforces.com/problemset/problem/152/A
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

const int N = 100 + 10;

int n, m;
int num[N][N];
int f[N];
bool visited[N];
int ans;

int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
char tmp;

cin >> tmp;
num[i][j] = tmp - '0';
}
}

for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
f[j] = max(f[j], num[i][j]);
}
}

for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (num[i][j] == f[j] && visited[i] == false)
{
ans++;
visited[i] = true;
}
}
}

cout << ans << endl;

return 0;
}

给出n个学生的m科成绩,如果某个学生的某个成绩在该科是第一名,则称这个学生是成功。

非常简单的思维题,直接使用一个数组保存各个科目的最高成绩,然后逐个判断即可。

CF152B - Steps(模拟)

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
55
56
57
58
59
60
61
62
//https://codeforces.com/problemset/problem/152/B
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

long long n, m;
long long x, y;
int k;
long long ans = 0;

int main()
{
cin >> n >> m;
cin >> x >> y;
cin >> k;

while (k--)
{
int xi, yi;

cin >> xi >> yi;
if (x + xi <= n && y + yi <= m && x + xi >= 1 && y + yi >= 1)
{
long long cnt = 0;

if (xi == 0 && yi == 0) continue;

if (xi == 0)
{
if (yi > 0) cnt = (m - y) / yi;
else cnt = (y - 1) / abs(yi);
}
if (yi == 0)
{
if (xi > 0) cnt = (n - x) / xi;
else cnt = (x - 1) / abs(xi);
}

if (yi != 0 && xi != 0)
{
if(xi > 0 && yi > 0) cnt = min((n - x) / xi, (m - y) / yi);
else if(xi < 0 && yi < 0) cnt = min((x - 1) / abs(xi), (y - 1) / abs(yi));
else if(xi > 0 && yi < 0) cnt = min((n - x) / xi, (y - 1) / abs(yi));
else if(xi < 0 && yi > 0) cnt = min((x - 1) / abs(xi), (m - y) / yi);
}

x += cnt * xi;
y += cnt * yi;

ans += cnt;
}
}

cout << ans << endl;

return 0;
}

根据题目模拟即可,关键在于处理负数和计算出最大能走多少步。

CF152C - Pocket Book(组合数)

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
//https://codeforces.com/problemset/problem/152/C
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

const int mod = 1e9 + 7;
const int N = 100 + 10;

int n, m;
int cnt[N];
char name[N][N];

long long ans = 1;

int main()
{
cin >> n >> m;

for (int i = 1; i <= n; i++)
{
cin >> (name[i] + 1);
}

for (int j = 1; j <= m; j++)
{
bool visited[26] = { false };
for (int i = 1; i <= n; i++)
{
if (visited[name[i][j] - 'A'] == false)
{
visited[name[i][j] - 'A'] = true;
cnt[j]++;
}
}
}

for (int j = 1; j <= m; j++) ans = (ans * (cnt[j] % mod)) % mod;

cout << ans % mod << endl;

return 0;
}

题目的意思即给出每个位置的字母种类数,问能排列出多少种名字。

直接使用组合数,把各个位置字母种类数相乘即可。