Codeforces Round 918 (Div. 4)Finished

A. Odd One Out

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

You are given three digits 𝑎, 𝑏, 𝑐. Two of them are equal, but the third one is different from the other two.

Find the value that occurs exactly once.

Input

The first line contains a single integer 𝑡 (1≤𝑡≤270) — the number of test cases.

The only line of each test case contains three digits 𝑎, 𝑏, 𝑐 (0≤𝑎, 𝑏, 𝑐≤9). Two of the digits are equal, but the third one is different from the other two.

Output

For each test case, output the value that occurs exactly once.

模拟判断三个数字的过程,随后直接输出换行

#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int t;
  cin>>t; 
  while(t--){
    int a,b,c;
    cin>>a>>b>>c; 
    if(a==b) cout<<c<<endl;
    else if(a==c) cout<<b<<endl;
    else cout<<a<<endl;
  }
  return 0; 
 
}

B. Not Quite Latin Square

time limit per test: 1 second

memory limit per test; 256 megabytes

input: standard input

output: standard output

A Latin square is a 3×3 grid made up of the letters 𝙰, 𝙱, and 𝙲 such that:

  • in each row, the letters 𝙰, 𝙱, and 𝙲 each appear once, and
  • in each column, the letters 𝙰, 𝙱, and 𝙲 each appear once.

For example, one possible Latin square is shown below.

You are given a Latin square, but one of the letters was replaced with a question mark ?. Find the letter that was replaced.

Input

The first line of the input contains a single integer 𝑡 (1≤𝑡≤108) — the number of testcases.

Each test case contains three lines, each consisting of three characters, representing the Latin square. Each character is one of 𝙰, 𝙱, 𝙲, or ?.

Each test case is a Latin square with exactly one of the letters replaced with a question mark ?.

Output

For each test case, output the letter that was replaced.

确定了3x3的矩阵每一行都有a,b,c,其中会有问好代替字母,找出这个字母的过程可以直接枚举,或者标记三个字母出现的true or false再判断。这道题可以采用简单的计数

#include<bits/stdc++.h>
using namespace std;

int main(){
	int t;
  cin>>t; 
  while(t--){
      int a=0,b=0,c=0;
        char latin[5][5];
        for(int i=1;i<=3;i++){
            for(int j=1;j<=3;j++){
                cin>>latin[i][j];
                if(latin[i][j]=='A') a++;
                else if(latin[i][j]=='B') b++;
                else if(latin[i][j]=='C') c++; 
            }
        }
        if(a!=3)cout<<'A'<<endl;
        else if(b!=3)cout<<'B'<<endl;
        else cout<<'C'<<endl; 
  }
  return 0; 

}

C. Can I Square?

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

Calin has 𝑛 buckets, the 𝑖-th of which contains 𝑎𝑖 wooden squares of side length 1.

Can Calin build a square using all the given squares?

Input

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

The first line of each test case contains a single integer 𝑛 (1≤𝑛≤2⋅105) — the number of buckets.

The second line of each test case contains 𝑛𝑛 integers 𝑎1,…,𝑎𝑛 (1≤𝑎𝑖≤109) — the number of squares in each bucket.

The sum of 𝑛𝑛 over all test cases does not exceed 2⋅105.

Output

For each test case, output "YES" if Calin can build a square using all of the given 1×1 squares, and "NO" otherwise.

如果需要用木桶组成1*1,那么数量必须是一个完全平方数n*n,所以在这个数组中build square意思是这么多个木桶中能不能组成完全平方数,例如9可以是3*3,1 2 3 4 5 6 7 之和是28,不可组成完全平方在for循环中判断即可。

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n, sum = 0;  // Reset sum for each test case
        cin >> n;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            sum += x;
        }
        long long t = sqrt(sum);
        bool flag = false;
        for (long long i = t - 1; i <= t + 1; i++) {
            if (i >= 0 && i * i == sum) {
                cout << "YES\n";
                flag= true;
                break;   
            }
        }
        if (!flag)
            cout << "NO\n";
    }
    return 0;
}

D. Unnatural Language Processing

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

Lura was bored and decided to make a simple language using the five letters 𝚊, 𝚋, 𝚌, 𝚍, 𝚎. There are two types of letters:

  • vowels — the letters 𝚊 and 𝚎. They are represented by 𝖵.
  • consonants — the letters 𝚋, 𝚌, and 𝚍. They are represented by 𝖢.

There are two types of syllables in the language: 𝖢𝖵 (consonant followed by vowel) or 𝖢𝖵𝖢 (vowel with consonant before and after). For example, 𝚋𝚊, 𝚌𝚎𝚍, 𝚋𝚊𝚋 are syllables, but 𝚊𝚊, 𝚎𝚍𝚊, 𝚋𝚊𝚋𝚊 are not.

A word in the language is a sequence of syllables. Lura has written a word in the language, but she doesn't know how to split it into syllables. Help her break the word into syllables.

For example, given the word 𝚋𝚊𝚌𝚎𝚍𝚋𝚊𝚋, it would be split into syllables as 𝚋𝚊.𝚌𝚎𝚍.𝚋𝚊𝚋  (the dot .. represents a syllable boundary).

Input

The input consists of multiple test cases. The first line contains an integer 𝑡𝑡 (1≤𝑡≤1001≤𝑡≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer 𝑛𝑛 (1≤𝑛≤2⋅1051≤𝑛≤2⋅105) — the length of the word.

The second line of each test case contains a string consisting of 𝑛𝑛 lowercase Latin characters  — the word.

All words given are valid words in the language; that is, they only use the letters 𝚊a, 𝚋b, 𝚌c, 𝚍d, 𝚎e, and each word is made up of several syllables.

The sum of 𝑛𝑛 over all test cases does not exceed 2⋅105.

Output

For test case, output a string denoting the word split into syllables by inserting a dot .. between every pair of adjacent syllables.

If there are multiple possible splittings, output any of them. The input is given in such a way that at least one possible splitting exists.

这道题可以以O(n)的复杂度解决,反向遍历字符串(从右到左)。如果最后一个字符是元音,它必须是𝖢𝖵的一部分音节, 不然就是𝖢𝖵𝖢音节。所以我们可以回到2 或 3适当地插入 ,反复便利这个solution循环。

#include <bits/stdc++.h>
 
using namespace std;
 
void solution() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string res = "";
    while (!s.empty()) {
        int x;
        if (s.back() == 'a' || s.back() == 'e') {x = 2;}
        else {x = 3;}
        
        while (x--) {
            res += s.back();
            s.pop_back();
        }
        res += '.';
    }
    res.pop_back();
    reverse(res.begin(), res.end());
    cout << res << '\n';
}
 
int main() {
    ios::sync_with_stdio(false); 
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++) {
       solution();
    }
    
    return 0;
}

E. Romantic Glasses

Iulia has 𝑛𝑛 glasses arranged in a line. The 𝑖𝑖-th glass has 𝑎𝑖𝑎𝑖 units of juice in it. Iulia drinks only from odd-numbered glasses, while her date drinks only from even-numbered glasses.

To impress her date, Iulia wants to find a contiguous subarray of these glasses such that both Iulia and her date will have the same amount of juice in total if only the glasses in this subarray are considered. Please help her to do that.

More formally, find out if there exists two indices 𝑙𝑙, 𝑟𝑟 such that 1≤𝑙≤𝑟≤𝑛1≤𝑙≤𝑟≤𝑛, and 𝑎𝑙+𝑎𝑙+2+𝑎𝑙+4+⋯+𝑎𝑟=𝑎𝑙+1+𝑎𝑙+3+⋯+𝑎𝑟−1𝑎𝑙+𝑎𝑙+2+𝑎𝑙+4+⋯+𝑎𝑟=𝑎𝑙+1+𝑎𝑙+3+⋯+𝑎𝑟−1 if 𝑙𝑙 and 𝑟𝑟 have the same parity and 𝑎𝑙+𝑎𝑙+2+𝑎𝑙+4+⋯+𝑎𝑟−1=𝑎𝑙+1+𝑎𝑙+3+⋯+𝑎𝑟𝑎𝑙+𝑎𝑙+2+𝑎𝑙+4+⋯+𝑎𝑟−1=𝑎𝑙+1+𝑎𝑙+3+⋯+𝑎𝑟 otherwise.

Input

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

The first line of each test case contains a single integer 𝑛𝑛 (1≤𝑛≤2⋅1051≤𝑛≤2⋅105) — the total number of glasses.

The second line of each test case contains 𝑛𝑛 integers 𝑎1,…,𝑎𝑛𝑎1,…,𝑎𝑛 (1≤𝑎𝑖≤1091≤𝑎𝑖≤109) — the amount of juice in each glass.

The sum of 𝑛𝑛 over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output "YES" if there exists a subarray satisfying the condition, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值