题解:Codeforces Round 962 (Div. 3) A&B

由于A和B太简单了,我就放在一起讲了

A. Legs

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output

It’s another beautiful day on Farmer John’s farm.

After Farmer John arrived at his farm, he counted n n n legs. It is known only chickens and cows live on the farm, and a chicken has 2 2 2 legs while a cow has 4 4 4.

What is the minimum number of animals Farmer John can have on his farm assuming he counted the legs of all animals?

农夫约翰的农场又迎来了美好的一天。

农夫约翰来到农场后,数了数 n n n 条腿。众所周知,农场里只住着鸡和牛,一只鸡有 2 2 2 条腿,而一头牛有 4 4 4 条腿。

假设约翰农场主数清了所有动物的腿,那么他的农场里至少有多少种动物?

Input

The first line contains single integer t t t ( 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103) — the number of test cases.

Each test case contains an integer n n n ( 2 ≤ n ≤ 2 ⋅ 1 0 3 2 \leq n \leq 2 \cdot 10^3 2n2103, n n n is even).

输入

第一行包含一个整数 t t t ( 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103 ) - 测试用例数。

每个测试用例包含一个整数 n n n 2 ≤ n ≤ 2 ⋅ 1 0 3 2 \leq n \leq 2 \cdot 10^3 2n2103 n n n 为偶数)。

Output

For each test case, output an integer, the minimum number of animals Farmer John can have on his farm.

输出

针对每个测试用例,输出一个整数,即农场主约翰的农场可以拥有的最少动物数量。

Example

Input
3
2
6
8
Output
1
2
2

题意

就是鸡兔同笼
给你腿的总数
问你里面最少有多少只生物

题解

假设兔子(四条腿的)尽量多
还能放就放鸡(两条腿的)

ans = n/4 + (n%4  ? : 1 : 0);

我的代码

#include <bits/stdc++.h>

#define int long long
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()

using i64 = long long;

int t = 1;

void solve(){
    int n;
    std::cin >> n;
    n/=2;
    std::cout << n/2 + n%2 <<"\n";
}

signed main(){
    std::cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

B. Scale

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output

Tina has a square grid with n n n rows and n n n columns. Each cell in the grid is either 0 0 0 or 1 1 1.

Tina wants to reduce the grid by a factor of k k k ( k k k is a divisor of n n n). To do this, Tina splits the grid into k × k k \times k k×k nonoverlapping blocks of cells such that every cell belongs to exactly one block.

Tina then replaces each block of cells with a single cell equal to the value of the cells in the block. It is guaranteed that every cell in the same block has the same value.

For example, the following demonstration shows a grid being reduced by factor of 3 3 3.

Original grid

0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0

Reduced grid

0 0 0 1 1 1
1 1 1 0 0 0

Help Tina reduce the grid by a factor of k k k.

蒂娜有一个行数为 n n n 列数为 n n n 的正方形网格。网格中的每个单元格要么是 0 0 0 要么是 1 1 1

蒂娜希望将网格缩小 k k k 倍(** k k k n n n **的除数)。为此,蒂娜将网格分割成 k × k k \times k k×k 个不重叠的单元格块,这样每个单元格都正好属于一个单元格块。

然后,蒂娜将每个单元格块替换为与单元格块中单元格值相等的单个单元格。保证同一区块中的每个单元格都具有相同的值

例如,下面的演示显示一个网格被缩小了 3 3 3 倍。

原始网格

0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0

缩小网格

0 0 0 1 1 1
1 1 1 0 0 0

帮助 Tina 将网格缩小 k k k 倍。

Input

The first line contains t t t ( 1 ≤ t ≤ 100 1 \leq t \leq 100 1t100) – the number of test cases.

The first line of each test case contains two integers n n n and k k k ( 1 ≤ n ≤ 1000 1 \leq n \leq 1000 1n1000, 1 ≤ k ≤ n 1 \le k \le n 1kn, k k k is a divisor of n n n) — the number of rows and columns of the grid, and the factor that Tina wants to reduce the grid by.

Each of the following n n n lines contain n n n characters describing the cells of the grid. Each character is either 0 0 0 or 1 1 1. It is guaranteed every k k k by k k k block has the same value.

It is guaranteed the sum of n n n over all test cases does not exceed 1000 1000 1000.

输入

第一行包含 t t t ( 1 ≤ t ≤ 100 1 \leq t \leq 100 1t100 ) - 测试用例数。

每个测试用例的第一行包含两个整数 n n n k k k 1 ≤ n ≤ 1000 1 \leq n \leq 1000 1n1000 1 ≤ k ≤ n 1 \le k \le n 1kn ,** k k k n n n 的除数**)–网格的行数和列数,以及蒂娜希望缩小网格的因子。

下面每 n n n 行包含 n n n 个描述网格单元格的字符。每个字符要么是 0 0 0 要么是 1 1 1 。保证每个 k k k x k k k 块都具有相同的值。

保证所有测试用例中 n n n 的总和不超过 1000 1000 1000

Output

For each test case, output the grid reduced by a factor of k k k on a new line.

输出

对于每个测试用例,在新的一行输出网格缩小了 k k k 倍的结果。

Example

Input
4
4 4
0000
0000
0000
0000
6 3
000111
000111
000111
111000
111000
111000
6 2
001100
001100
111111
111111
110000
110000
8 1
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
Output
0
01
10
010
111
100
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111

题意

一个 n × n n \times n n×n 01 01 01 矩阵被均等分成了 k × k k \times k k×k
每一块里面的数保证全部相同,
求原矩阵缩小 k k k 倍的矩阵

题解

只要输出每一块的左上角那个数字就可以了
也就是输出(假设坐标范围是 0 ≤ i , j < n 0 \le i,j \lt n 0i,j<n
a [ i ] [ j ] ( i % k = 0 , j % k = 0 ) a[i][j](i\%k = 0,j\%k=0) a[i][j](i%k=0,j%k=0)

代码

#include <bits/stdc++.h>

#define int long long
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()

using i64 = long long;

int t = 1;

void solve(){
    int n,k;
    std::cin >> n >> k;
    std::string s[n];
    for(int i = 0 ; i < n ; i ++) {
        std::cin >>s[i];
    }
    for(int i = 0 ; i < n ; i += k) {
        for(int j = 0 ; j < n ; j += k ) {
            std::cout << s[i][j];
        }
        std::cout << "\n";
    }
}

signed main(){
    std::cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

转载自博客https://www.cnblogs.com/jiejiejiang2004/p/18331592
博主已同意,我就是博主

  • 12
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值