A - “atcoder”.substr()

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100100 points

Problem Statement

Print the LLL-th through RRR-th characters of the string atcoder.

Constraints

LLL and RRR are integers.
1≤L≤R≤71≤L≤R≤71≤L≤R≤7

Input

Input is given from Standard Input in the following format:

LLL RRR

Output

Print the answer.

题面翻译

给定左右边界LLL和RRR,求截取[L,R][L,R][L,R]后的atcoder字符串。

Sample Input 1

3 6

Sample Output 1

code

The 333-rd through 666-th characters of atcoder are code.

Sample Input 2

4 4

Sample Output 2

o

Sample Input 3

1 7

Sample Output 3

atcoder

题解部分

我们用一个string类型变量记录一下字符串atcoder
再用一重循环输出区间内的字符即可。

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;int main () {string str = " atcoder";int l, r;scanf ("%d %d", &l, &r);for (int i = l; i <= r; i ++) {printf ("%c", str[i]);}return 0;
}

B - Nice Grid

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200200 points

Problem Statement

Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.

Constraints

1≤R,C≤151≤R,C≤151≤R,C≤15
RRR and CCC are integers.

Input

Input is given from Standard Input in the following format:

RRR CCC

Output

In the grid above, if the color of the cell at the RRR-th row from the top and CCC-th column from the left is black, then print black; if the cell is white, then print white. Note that the judge is case-sensitive.

题面翻译

给出坐标(R,C)(R,C)(R,C),判断上图第RRR行,第CCC列的颜色。

Sample Input 1

3 5

Sample Output 1

black

In the grid above, the cell at the 333-rd row from the top and 555-th column from the left is black. Thus, black should be printed.

Sample Input 2

4 5

Sample Output 2

white

In the grid above, the cell at the 444-th row from the top and 555-th column from the left is white. Thus, white should be printed.

题解部分

我们可以用用两重循环标记整个图的颜色,再输出对应字符串即可。

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;bool fl[20][20];int main () {int a, b;scanf ("%d %d", &a, &b);for (int i = 1; i <= 7; i += 2) {for (int j = i; j <= 15 - i + 1; j ++) {//每一圈正方形的上、左边fl[i][j] = 1;fl[j][i] = 1;}for (int j = 15 - i + 1; j >= i; j --) {//每一圈正方形的下、右边fl[15 - i + 1][j] = 1;fl[j][15 - i + 1] = 1;}}printf ("%s", fl[a][b] == 1 ? "black" : "white");return 0;
}

C - Matrix Reducing

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300300 points

Problem Statement

You are given a matrix AAA with H1H_1H1​ rows and W1W_1W1​ columns, and a matrix BBB with H2H_2H2​ rows and W2W_2W2​ columns.

  • For all integer pairs (i,j)(i,j)(i,j) such that 1≤i≤H11≤i≤H_11≤i≤H1​ and 1≤j≤W11≤j≤W_11≤j≤W1​ , the element at the iii-th row and jjj-th column of matrix AAA is Ai,jA_{i,j}Ai,j​ .

  • For all integer pairs (i,j)(i,j)(i,j) such that 1≤i≤H21≤i≤H_21≤i≤H2​ and 1≤j≤W21≤j≤W_21≤j≤W2​, the element at the iii-th row and jjj-th column of matrix BBB is Bi,jB_{i,j}Bi,j​.
    You may perform the following operations on the matrix AAA any number of (possibly 000) times in any order:

  • Choose an arbitrary row of AAA and remove it.

  • Choose an arbitrary column of AAA and remove it.
    Determine if it is possible to make the matrix AAA equal the matrix BBB.

Constraints

  • 1≤H2≤H1≤101≤H_2≤H_1≤101≤H2​≤H1​≤10
  • 1≤W2≤W1≤101≤W_2≤W_1≤101≤W2​≤W1​≤10
  • 1≤Ai,j≤1091≤A_{i,j}≤10^91≤Ai,j​≤109
  • 1≤Bi,j≤1091≤B_{i,j}≤10^91≤Bi,j​≤109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H1H_1H1​ W1W_1W1​
​ A1,1A_{1,1}A1,1​ A1,2A_{1,2}A1,2​ … A1,W1A_{1,W_1}A1,W1​​
​ A2,1A_{2,1}A2,1​ A2,2A_{2,2}A2,2​ … A2,W1A_{2,W_1}A2,W1​​

​ AH1,1A_{H_1,1}AH1​,1​ AH1,2A_{H_1,2}AH1​,2​ … AH1,W1A_{H_1,W_1}AH1​,W1​​
H2H_2H2​ W2W_2W2​
​ B1,1B_{1,1}B1,1​ B1,2B_{1,2}B1,2​ … B1,W2B_{1,W_2}B1,W2​​
​ B2,1B_{2,1}B2,1​ B2,2B_{2,2}B2,2​ … B2,W2B_{2,W_2}B2,W2​​

​ BH2,1B_{H_2,1}BH2​,1​ BH2,2B_{H_2,2}BH2​,2​ … BH2,W2B_{H_2,W_2}BH2​,W2​​

Output

Print Yes if it is possible to make the matrix AAA equal the matrix BBB; print No otherwise. Note that the judge is case-sensitive.

题面翻译

给出两个二维数组AAA、BBB,你可以删除若干次AAA的任意一行(列),判断是否能将AAA转化为BBB。

Sample Input 1

4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
2 3
6 8 9
16 18 19

Sample Output 1

Yes

Removing the 222-nd column from the initial AAA results in:

1 3 4 5
6 8 9 10
11 13 14 15
16 18 19 20

Then, removing the 333-rd row from AAA results in:

1 3 4 5
6 8 9 10
16 18 19 20

Then, removing the 111-st row from AAA results in:

6 8 9 10
16 18 19 20

Then, removing the 444-th column from AAA results in:

6 8 9
16 18 19

Now the matrix equals the matrix BBB.
Thus, we can make the matrix AAA equal the matrix BBB by repeating the operations, so Yes should be printed.

Sample Input 2

3 3
1 1 1
1 1 1
1 1 1
1 1
2

Sample Output 2

No

Regardless of how we perform the operations, we cannot make the matrix AAA equal the matrix BBB, so No should be printed.

题解部分

注意数据范围,长和宽都≤10\le 10≤10,所以我们选择用两个dfs暴搜整个矩阵,如果两个矩阵完全一致,输出Yes,搜完了仍然没有输出,则输出No

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;const int MAXN = 10 + 5;
int a[MAXN][MAXN], b[MAXN][MAXN];
bool line[MAXN], col[MAXN];
int n1, m1, n2, m2;bool check () {//判断搜索后的矩阵A是否与B相等int I = 1, J;for (int i = 1; i <= n1; i ++) {if (col[i]) {J = 1;for (int j = 1; j <= m1; j ++) {if (line[j]) {if (a[i][j] != b[I][J]) {return 0;}J ++;}}I ++;}}return 1;
}void dfs_col (int step, int x) {//搜索每一列if (step > n2) {if (check ()) {printf ("Yes");exit (0);}return;}for (int i = x + 1; i <= n1 - (n2 - step); i ++) {if (!col[i]) {col[i] = 1;dfs_col (step + 1, i);col[i] = 0;}}
}void dfs_line (int step, int x) {//搜索每一行if (step > m2) {dfs_col (1, 0);return;}for (int i = x + 1; i <= m1 - (m2 - step); i ++) {if (!line[i]) {line[i] = 1;dfs_line (step + 1, i);line[i] = 0;}}
}int main () {scanf ("%d %d", &n1, &m1);for (int i = 1; i <= n1; i ++) {for (int j = 1; j <= m1; j ++) {scanf ("%d", &a[i][j]);}}scanf ("%d %d", &n2, &m2);for (int i = 1; i <= n2; i ++) {for (int j = 1; j <= m2; j ++) {scanf ("%d", &b[i][j]);}}dfs_line (1, 0);printf ("No");return 0;
}

D - “redocta”.swap(i,i+1)

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400400400 points

Problem Statement

You are given a string SSS that is a permutation of atcoder.
On this string S,S,S, you will perform the following operation 000 or more times:

  • Choose two adjacent characters of SSS and swap them.

Find the minimum number of operations required to make SSS equal atcoder.

Constraints

  • SSS is a string that is a permutation of atcoder

Input

Input is given from Standard Input in the following format:

SSS

Output

Print the answer as an integer.

题面翻译

给出字符串SSS,每次可以交换相邻的两个字母,求最少需要几次可以把SSS转化为atcoder

Sample Input 1

catredo

Sample Output 1

8

You can make SSS equal atcoder in 888 operations as follows:
catredo[ac]tredoactre[od]actr[oe]dactro[de]act[or]deacto[dr]ea[tc]odreatcod[er]
This is the minimum number of operations achievable.

Sample Input 2

atcoder

Sample Output 2

0

In this case, the string S is already atcoder.

Sample Input 3

redocta

Sample Output 3

21

题解部分

这道题我们可以运用冒泡排序的思想,按照顺序,将指定字母交换至指定位置。由于atcoder不包含两个相同的字母,所以不用考虑最小的移动方法。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;int main () {int cnt = 0;string str = "atcoder", s;cin >> s;for (int i = 0; i < 7; i ++) {int p = s.find(str[i]);//寻找子串str[i]第一次出现的位置if (p < i) {//往后移(理论来说不需要判断)for (int j = p; j < i; j ++) {swap (s[j], s[j + 1]);cnt ++;}} else if (p > i) {//往前移for (int j = p; j > i; j --) {swap (s[j], s[j - 1]);cnt ++;}}}printf ("%d", cnt);return 0;
}

freee Programming Contest 2022(AtCoder Beginner Contest 264) 题解 (A~D)相关推荐

  1. Caddi Programming Contest 2021(AtCoder Beginner Contest 193) 题解

    Caddi Programming Contest 2021(AtCoder Beginner Contest 193) A - Discount 打折浮点数除即可 B - Play Snuke 枚举 ...

  2. NEC Programming Contest 2021(AtCoder Beginner Contest 229) B - Hard Calculation

    题目链接:B - Hard Calculation (atcoder.jp) Problem Statement You are given positive integers A and B. Le ...

  3. Atcoder TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) B - Takahashi‘s Secret

    题目链接:B - Takahashi's Secret (atcoder.jp) Problem Statement Takahashi has N friends. They have nickna ...

  4. Atcoder TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) C - Final Day

    题目链接:C - Final Day (atcoder.jp) Problem Statement N students are taking a 4-day exam. There is a 300 ...

  5. KYOCERA Programming Contest 2021 (AtCoder Beginner Contest 200) A~E 题解

    ABC200/KYOCERA2021 A~E [A - Century](https://atcoder.jp/contests/abc200/tasks/abc200_a) 题目大意 输入格式 输出 ...

  6. Mynavi Programming Contest 2021 (AtCoder Beginner Contest 201) A~E 题解

    ABC201/Mynavi2021 A~E [A - Tiny Arithmetic Sequence](https://atcoder.jp/contests/abc201/tasks/abc201 ...

  7. NEC Programming Contest 2021 (AtCoder Beginner Contest 229)

    终于开始补提了 重点 : C, E的倒着算, F的染色,G的相邻的转换: B - Hard Calculation #include <iostream> #include <alg ...

  8. TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) ABCD

    A 题意: 有一个开关,每天s点开,t点关(可能在第2天或第n天),判断x点时开着还是关着. 思路: 按照是否需要隔夜分个类. #include<bits/stdc++.h> using ...

  9. Caddi Programming Contest 2021(AtCoder Beginner Contest 193) F.Zebraness

    题目链接 Problem Statement We have a grid with N horizontal rows and N vertical columns. Let (i,j) denot ...

最新文章

  1. C# GUID的使用
  2. Science:中英合作揭示拟南芥三萜化合物特异调控根系微生物组
  3. PIL实现两张图片合成一张,和图片加文字
  4. Linux:常用命令大全
  5. Android中的Broadcast Action大全
  6. Micro-CMS v2(持续更新中)
  7. STP状态切换详述(Cisco实现)
  8. 获取Django中model字段名 字段的verbose_name
  9. apache poi使用例_4.Apache POI使用详解
  10. Go语言编程17课:切片,步入数组的窗口(附pdf百度云)
  11. 系统监视器(Sysmon)工具的使用
  12. 创造生命奇迹的幸存者
  13. AD13如何导出坐标文件
  14. JAVA实现AES加密、解密
  15. 客户服务管理(CSM)
  16. ccf有趣的数java_CCF CSP 有趣的数
  17. R SMOTE 报错 length of 'dimnames' [2] not equal to array extent
  18. 苹果自带相册打马赛克_剪映app怎么给视频局部打马赛克
  19. 上海交大考研823网络空间安全经验分享
  20. 久坐伤身,这个3D坐垫能让危害降到最低,办公自驾必备!

热门文章

  1. topcoder开发
  2. 终于等到了 xp黑屏了
  3. 数据库里怎么修改服务器爆率,关于数据库点窜爆率及点窜和增加掉落的教程(纯小白版)...
  4. 明天16:00 | AI与自动驾驶——人工智能有可能实现人类智能的挑战性任务吗
  5. Bag of Words Meets Bags of Popcorn(3)-Word2Voc
  6. PAT乙级1005 继续(3n+1)猜想//散列初级运用
  7. Java开发教程入门!java核心技术卷一
  8. thinkphp5 url重写后,如何引用静态资源文件?
  9. 什么是异质性群体?(32)
  10. 【出现bug:Could not GET ‘https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle无标题】