Codeforces Round #682 (Div. 2)总结

A. Specific Tastes of Andre

  这个挺简单的,就输出1就行了

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    int a[10001];
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            if(i==0)
                cout<<1;
            else
                cout<<" "<<1;
        }
        cout<<endl;
    }
    return 0;
}

B. Valerii Against Everyone

   这个当时实在是没什么思路,b的值太大了,也不能计算出来,想到二进制的计算,但是写不出来,就放弃去看C题了。看完题解才知道只要找有没有两个相同的数就行了

You’re given an array b of length n. Let’s define another array a, also of length n, for which ai=2bi (1≤i≤n).

Valerii says that every two non-intersecting subarrays of a have different sums of elements. You want to determine if he is wrong. More formally, you need to determine if there exist four integers l1,r1,l2,r2 that satisfy the following conditions:

1≤l1≤r1<l2≤r2≤n;
al1+al1+1+…+ar1−1+ar1=al2+al2+1+…+ar2−1+ar2.
If such four integers exist, you will prove Valerii wrong. Do they exist?

An array c is a subarray of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). Description of the test cases follows.

The first line of every test case contains a single integer n (2≤n≤1000).

The second line of every test case contains n integers b1,b2,…,bn (0≤bi≤109).

Output
For every test case, if there exist two non-intersecting subarrays in a that have the same sum, output YES on a separate line. Otherwise, output NO on a separate line.

Also, note that each letter can be in any case.

Example
inputCopy
2
6
4 3 0 1 2 0
2
2 5
outputCopy
YES
NO
Note
In the first case, a=[16,8,1,2,4,1]. Choosing l1=1, r1=1, l2=2 and r2=6 works because 16=(8+1+2+4+1).
In the second case, you can verify that there is no way to select to such subarrays.

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    cin>>t;
    int a[1001];
    while(t--)
    {
        map<long long,long long>ma;
        cin>>n;
        bool flag=false;
        for(int i=0;i<n;i++) cin>>a[i];
        for(int i=0;i<n;i++){
            ma[a[i]]++;
            if(ma[a[i]]==2)
            {
                flag=true;
                break;
            }
        }
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

最近在学Python,看了一个Python大佬写的代码:(着实看不懂呀。。。)

for s in[*open(0)][2::2]:b=s.split();print('YNEOS'[len(b)==len({*b})::2])
# 另一个。。。
for tc in range(int(input())):
    n = int(input())
    arr = input().split()
    if len(arr) != len(set(arr)):
        print('YES')
    else:print('NO')

1438C - Engineer Artem

当时就一股脑的觉得是道BFS题,最后交了两次就是WA,看完题解发现只要一行奇数一行偶数,一列奇数一列偶数就行了
Artem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value ai,j written in it.

If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side.

Artem wants to increment the values in some cells by one to make a good.

More formally, find a good matrix b that satisfies the following condition —

For all valid (i,j), either bi,j=ai,j or bi,j=ai,j+1.
For the constraints of this problem, it can be shown that such a matrix b always exists. If there are several such tables, you can output any of them. Please note that you do not have to minimize the number of increments.

Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10). Description of the test cases follows.

The first line of each test case contains two integers n,m (1≤n≤100, 1≤m≤100) — the number of rows and columns, respectively.

The following n lines each contain m integers. The j-th integer in the i-th line is ai,j (1≤ai,j≤109).

Output
For each case, output n lines each containing m integers. The j-th integer in the i-th line is bi,j.

Example
inputCopy
3
3 2
1 2
4 5
7 8
2 2
1 1
3 3
2 2
1 3
2 2
outputCopy
1 2
5 6
7 8
2 1
4 3
2 4
3 2
Note
In all the cases, you can verify that no two adjacent cells have the same value and that b is the same as a with some values incremented by one.

题意:让你把这个矩阵变成每个相邻的元素都不一样,而且最多在这个数的基础上加1;(好傻呀,奇偶呀。。。)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        long long a[101][101];
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                cin>>a[i][j];
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(i%2==0)
                {
                    if(j%2==0)
                    {
                        if(a[i][j]%2!=0)
                            a[i][j]++;
                    }
                    else
                    {
                        if(a[i][j]%2==0)
                            a[i][j]++;
                    }
                }
                else
                {
                    if(j%2==0)
                    {
                        if(a[i][j]%2==0)
                            a[i][j]++;
                    }
                    else
                    {
                        if(a[i][j]%2!=0)
                            a[i][j]++;
                    }
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(j==0)
                cout<<a[i][j];
                else
                    cout<<" "<<a[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

JdiLfc

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

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

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

打赏作者

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

抵扣说明:

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

余额充值