codeforcesABC

文章涉及两个编程题目:一是计算马拉松比赛中蒂穆尔前面的参赛者数量,根据给定的距离;二是确定一个8x8棋盘上主教的位置,给定棋盘上受攻击的方格。
摘要由CSDN通过智能技术生成

A

A. Marathon

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DeepL 翻译

A.马拉松

每次测试的时间限制:1 秒

每次测试的内存限制:256 兆字节

输入:标准输入

输出:标准输出

You are given four distinct integers a�, b�, c�, d�.

Timur and three other people are running a marathon. The value a� is the distance that Timur has run and b�, c�, d� correspond to the distances the other three participants ran.

Output the number of participants in front of Timur.

DeepL 翻译

给你四个不同的整数 a� 、 b� 、 c� 、 d� 。

蒂穆尔和其他三个人正在跑马拉松。值 a� 是铁木尔跑过的距离, b� 、 c� 、 d� 分别对应其他三位参赛者跑过的距离。

输出 Timur 前面的参赛者人数。

Input

The first line contains a single integer t� (1≤t≤1041≤�≤104) — the number of test cases.

The description of each test case consists of four distinct integers a�, b�, c�, d� (0≤a,b,c,d≤1040≤�,�,�,�≤104).

DeepL 翻译

输入

第一行包含一个整数 t� ( 1≤t≤1041≤�≤104 ) - 测试用例的数量。

每个测试用例的描述由四个不同的整数 a� , b� , c� , d� 组成。( 0≤a,b,c,d≤1040≤�,�,�,�≤104 ).

Output

For each test case, output a single integer — the number of participants in front of Timur.

DeepL 翻译

输出

对于每个测试用例,输出一个整数 - Timur 前面的参与者人数。

Example

input

Copy

 

4

2 3 4 1

10000 0 1 2

500 600 400 300

0 9999 10000 9998

output

Copy

2
0
1
3

Note

For the first test case, there are 22 people in front of Timur, specifically the participants who ran distances of 33 and 44. The other participant is not in front of Timur because he ran a shorter distance than Timur.

For the second test case, no one is in front of Timur, since he ran a distance of 1000010000 while all others ran a distance of 00, 11, and 22 respectively.

For the third test case, only the second person is in front of Timur, who ran a total distance of 600600 while Timur ran a distance of 500500.

#include <iostream>
using namespace std;
int main(){
    int n;
    //yonglishu
    long long a[4];
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[0]>>a[1]>>a[2]>>a[3];//shu ru shi ge ren
        int it = 3;//it
        int ct=0;//count
        while(it){
            if(a[it]>a[0])
                ct++;//

            it--;//3to 0
        }
        printf("%d\n",ct);

    }

    return 0;
}

B

B. All Distinct

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DeepL 翻译

B.全然不同

每次测试的时间限制:1 秒

每次测试的内存限制:256 兆字节

输入:标准输入

输出:标准输出

Sho has an array a� consisting of n� integers. An operation consists of choosing two distinct indices i� and j� and removing ai�� and aj�� from the array.

For example, for the array [2,3,4,2,5][2,3,4,2,5], Sho can choose to remove indices 11 and 33. After this operation, the array becomes [3,2,5][3,2,5]. Note that after any operation, the length of the array is reduced by two.

After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible.

More formally, the array after Sho has made his operations respects these criteria:

  • No pairs such that (i<j�<�) and ai=aj��=�� exist.
  • The length of a� is maximized.

Output the length of the final array.

DeepL 翻译

Sho 有一个由 n� 个整数组成的数组 a� 。操作包括选择两个不同的索引 i� 和 j� 并从数组中删除 ai�� 和 aj�� 。

例如,对于数组 [2,3,4,2,5][2,3,4,2,5] ,肖可以选择删除索引 11 和 33 。操作完成后,数组变为 [3,2,5][3,2,5] 。注意,任何操作之后,数组的长度都会减少 2。

经过一些操作后,翔得到了一个只有个不同元素的数组。此外,他还进行了一些操作,使得得到的数组尽可能**长。

更正式地说,阿翔操作后的数组符合这些条件:

  • 不存在 ( i<j�<� ) 和 ai=aj��=�� 这样的数对。
  • a� 的长度最大。

输出最终数组的长度。

Input

The first line contains a single integer t� (1≤t≤1031≤�≤103) — the number of test cases.

The first line of each test case contains a single integer n� (1≤n≤501≤�≤50) — the length of the array.

The second line of each test case contains n� integers ai�� (1≤ai≤1041≤��≤104) — the elements of the array.

DeepL 翻译

输入

第一行包含一个整数 t� ( 1≤t≤1031≤�≤103 ) - 测试用例的数量。

每个测试用例的第一行包含一个整数 n� ( 1≤n≤501≤�≤50 ) - 数组的长度。

每个测试用例的第二行包含 n� 个整数 ai�� ( 1≤ai≤1041≤��≤104 ) - 数组的元素。( 1≤ai≤1041≤��≤104 ) - 数组的元素。

Output

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.

DeepL 翻译

输出

对于每个测试用例,输出一个整数 - 最终数组的长度。记住,在最终数组中,所有元素都是不同的,其长度是最大值。

Example

input

Copy

 

4

6

2 2 2 3 3 3

5

9 1 9 9 1

4

15 16 16 15

4

10 100 1000 10000

output

Copy

2
1
2
4

Note

For the first test case Sho can perform operations as follows:

  1. Choose indices 11 and 55 to remove. The array becomes [2,2,2,3,3,3]→[2,2,3,3][2,2,2,3,3,3]→[2,2,3,3].
  2. Choose indices 11 and 44 to remove. The array becomes [2,2,3,3]→[2,3][2,2,3,3]→[2,3].

The final array has a length of 22, so the answer is 22. It can be proven that Sho cannot obtain an array with a longer length.

For the second test case Sho can perform operations as follows:

  1. Choose indices 33 and 44 to remove. The array becomes [9,1,9,9,1]→[9,1,1][9,1,9,9,1]→[9,1,1].
  2. Choose indices 11 and 33 to remove. The array becomes [9,1,1]→[1][9,1,1]→[1].

The final array has a length of 11, so the answer is 11. It can be proven that Sho cannot obtain an array with a longer length.

#include <iostream>
#include<set>
using namespace std;
int main(){

  int n;//ex num;
  cin>>n;
  for(int i = 0;i<n;i++){
      set<int> arr;//int set;
      int len=0;
      int j=0;
      int t=0;//temp;
      //record original num;
      cin>>len;
      while(j<len){
          cin>>t;
          arr.insert(t);
          j++;
      }
      int sum=arr.size();
      if((len-sum)%2!=0)sum--;
      printf("%d\n",sum);
  }
}

C. Where's the Bishop?

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DeepL 翻译

C.主教在哪里?

每次测试的时间限制:1 秒

每次测试的内存限制:256 兆字节

输入:标准输入

输出:标准输出

Mihai has an 8×88×8 chessboard whose rows are numbered from 11 to 88 from top to bottom and whose columns are numbered from 11 to 88 from left to right.

Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edges of the board. (In other words, the row and column of the bishop are between 22 and 77, inclusive.)

The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked.

An example of a bishop on a chessboard. The squares it attacks are marked in red.

Mihai has marked all squares the bishop attacks, but forgot where the bishop was! Help Mihai find the position of the bishop.

DeepL 翻译

米哈伊有一个 8×88×8 棋盘,棋盘的行从上到下编号为 11 到 88 ,列从左到右编号为 11 到 88 。

米哈伊在棋盘上正好放置了一只象。象没有放在棋盘的边缘(换句话说,象的行和列都在 22 和 77 之间(包括 22 和 77 )。

象可以向对角线的所有方向攻击,而且攻击距离没有限制。需要注意的是,放置主教的单元格也被视为受到攻击。

 象在棋盘上的示例。象攻击的格用红色标出。

米哈伊已经标出了象攻击的所有位置,但却忘记了象的位置!帮助 Mihai 找到主教的位置。

Input

The first line of the input contains a single integer t� (1≤t≤361≤�≤36) — the number of test cases. The description of test cases follows. There is an empty line before each test case.

Each test case consists of 88 lines, each containing 88 characters. Each of these characters is either '#' or '.', denoting a square under attack and a square not under attack, respectively.

DeepL 翻译

输入

输入的第一行包含一个整数 t� ( 1≤t≤361≤�≤36 ) - 测试用例的数量。随后是测试用例说明。每个测试用例前都有一行空行。

每个测试用例由 88 行组成,每行包含 88 个字符。每个字符都是 "#"或".",分别表示受攻击方格和未受攻击方格。

Output

For each test case, output two integers r� and c� (2≤r,c≤72≤�,�≤7) — the row and column of the bishop.

The input is generated in such a way that there is always exactly one possible location of the bishop that is not on the edge of the board.

DeepL 翻译

输出

对于每个测试用例,输出两个整数 r� 和 c� ( 2≤r,c≤72≤�,�≤7 ) - 主教的行和列。

输入的生成方式是,主教总有一个可能的位置不在棋盘边缘。

Example

input

Copy

 

3

.....#..

#...#...

.#.#....

..#.....

.#.#....

#...#...

.....#..

......#.

#.#.....

.#......

#.#.....

...#....

....#...

.....#..

......#.

.......#

.#.....#

..#...#.

...#.#..

....#...

...#.#..

..#...#.

.#.....#

#.......

output

Copy

4 3
2 2
4 5

Note

The first test case is pictured in the statement. Since the bishop lies in the intersection row 44 and column 33, the correct output is 4 3.

DeepL 翻译

第一个测试案例如语句所示。由于主教位于行 44 和列 33 的交叉点上,因此正确的输出是 4 3。

 

#include <iostream>
#include<cstring>

using namespace std;
int h, l;

void slove(const char a[][8]) {
    int b, c, hh, ll;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            if (a[i][j] == '#') {
                c++;
                hh = i;
                ll = j;
            }
        }
        if (c == 1 && b == 2) {
            h = hh, l = ll;
            return;
        }
        b = c;
        c = 0;
    }

}

int main() {
    int n;
    //yonglishu
    cin >> n;
    for (int i = 0; i < n; i++) {
        char q[8][8];
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                cin >> q[i][j];
            }
        }
        slove(q);
        cout << h+1 <<' '<< l+1 << endl;
    }


    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小宇宙中微子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值