Codeforces Round 900 (Div. 3)

题目涉及查找数组中元素k是否在某个连续子集中是最常出现的,通过检查每个测试用例的元素分布来确定答案。

How Much Does Daytona Cost?

We define an integer to be the most common on a subsegment, if its number of occurrences on that subsegment is larger than the number of occurrences of any other integer in that subsegment. A subsegment of an array is a consecutive segment of elements in the array a.

Given an array a of size n, and an integer k, determine if there exists a non-empty subsegment of a where k is the most common element.

Input

Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers n and k (1≤n≤1001≤k≤100) — the number of elements in array and the element which must be the most common.

The second line of each test case contains n integers a1a2a3……an (1≤ai≤100) — elements of the array.

Output

For each test case output "YES" if there exists a subsegment in which k is the most common element, 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).

Example
input
7
5 4
1 4 3 4 1
4 1
2 3 4 4
5 6
43 5 60 4 2
2 5
1 5
4 1
5 3 3 1
1 3
3
5 3
3 4 1 5 5
output
YES
NO
NO
YES
YES
YES
YES
Note

In the first test case we need to check if there is a subsegment where the most common element is 4.

On the subsegment [2,5] the elements are 4, 3, 4, 1

  • 4 appears 2 times;
  • appears 1 time;
  • appears 1 time.

This means that 4 is the most common element on the subsegment [2,5], so there exists a subsegment where 4 is the most common element.

题目大意

t组数据,输入n,g,n个数据,询问是否存在数组的非空子集中的最大出现次数的元素为g

HINT

只要查询到g出现就满足条件 

代码

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int a[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n,k,flag=0;//设置标记
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
            if(a[i]==k){
                flag=1;//找到就退出
            }
        }
        if(flag==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Aleksa and Stack

After the Serbian Informatics Olympiad, Aleksa was very sad, because he didn't win a medal (he didn't know stack), so Vasilije came to give him an easy problem, just to make his day better.

Vasilije gave Aleksa a positive integer n(n≥3) and asked him to construct a strictly increasing array of size n of positive integers, such that

  • 3⋅ai+2 is not divisible by ai+ai+1 for each i(1≤i≤n−2).
Note that a strictly increasing array aof size n is an array where ai<ai+1 for each i (1≤i≤n−1).

Since Aleksa thinks he is a bad programmer now, he asked you to help him find such an array.

Input

Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer n (3≤n≤2⋅10^5) — the number of elements in array.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output n integers a1,a2,a3,…,an (1≤ai≤10^9).

It can be proved that the solution exists for any n. If there are multiple solutions, output any of them.

Example
input
3
6
7
output
6 8 12
7 11 14 20 22 100
9 15 18 27 36 90 120
Note

In the first test case, a1=6a2=8a3=12, so a1+a2=14 and 3⋅a3=36, so 3⋅a3 is not divisible by a1+a2.

题目大意

t组数据,每组数据由n项严格递增的数组组成,3*an不能被(an-1+an-2)整除,输出这样的数列

HINT

提前设置a0,a1,循环2~n,count持续递增,直至count不能被(ai-1+ai-2)整除,把count值赋给ai

代码

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        a[0]=2;a[1]=3;//遵循递增的条件下任意设置值
        int count=4; 
        for(int i=2;i<n;i++){
            int add=a[i-1]+a[i-2];
            while(count*3%(add)==0){
                 count++;
            }
            a[i]=count;count++;//记得每轮count++
        }
        for(int i=0;i<n;i++){
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

 

Vasilije in Cacak

Aca and Milovan, two fellow competitive programmers, decided to give Vasilije a problem to test his skills.

Vasilije is given three positive integers: nk, and x, and he has to determine if he can choose k distinct integers between 1 and n, such that their sum is equal to x.

Since Vasilije is now in the weirdest city in Serbia where Aca and Milovan live, Cacak, the problem seems weird to him. So he needs your help with this problem.

Input

The first line contains a single integer t (1≤t≤10^4) — the number of test cases.

The only line of each test case contains three integers nk and x (1≤n≤2⋅10^51≤k≤n1≤x≤4⋅10^10) — the maximum element he can choose, the number of elements he can choose and the sum he has to reach.

Note that the sum of n over all test cases may exceed 2⋅1052⋅105.

Output

For each test case output one line: "YES", if it is possible to choose k distinct integers between 1and n, such that their sum is equal to x, and "NO", if it isn't.

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

Example
input
12
5 3 10
5 3 3
10 10 55
6 5 20
2 1 26
187856 87856 2609202300
200000 190000 19000000000
28 5 2004
2 2 2006
9 6 40
47202 32455 613407217
185977 145541 15770805980
output
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
Note

In the first test case n=5, k=3, x=10, so we can choose the numbers: 235, whose sum is 10, so the answer is "YES".

In the second test case n=5, k=3, x=3, there is no three numbers which satisfies the condition, so the answer is "NO". It can be shown that there are no three numbers whose sum is 3.

题目大意

t组数据,在1~n中,选择k个数字,和可能为x输出“YES”,否则输出“NO”

   HINT

在1~n中,选择k个数字,和的值从min=(1+2...+k),到max=(n-k+1,n-k+2...n),所以只要x在min~max区间中,即满足条件。

·min,max求值要直接公式计算,用for循环累加会超时

代码 

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        long long n,k,x;cin>>n>>k>>x;
        long long min=((1+k)*k)/2,max=(((n-k+1)+n)*k)/2;
        //cout<<max<<" "<<min<<endl;
        if(x<=max&&x>=min){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

### Codeforces Round 927 Div. 3 比赛详情 Codeforces是一个面向全球程序员的比赛平台,定期举办不同级别的编程竞赛。Div. 3系列比赛专为评级较低的选手设计,旨在提供更简单的问题让新手能够参与并提升技能[^1]。 #### 参赛规则概述 这类赛事通常允许单人参加,在规定时间内解决尽可能多的问题来获得分数。评分机制基于解决问题的速度以及提交答案的成功率。比赛中可能会有预测试案例用于即时反馈,而最终得分取决于系统测试的结果。此外,还存在反作弊措施以确保公平竞争环境。 ### 题目解析:Moving Platforms (G) 在这道题中,给定一系列移动平台的位置和速度向量,询问某时刻这些平台是否会形成一条连续路径使得可以从最左端到达最右端。此问题涉及到几何学中的线段交集判断和平面直角坐标系内的相对运动分析。 为了处理这个问题,可以采用如下方法: - **输入数据结构化**:读取所有平台的数据,并将其存储在一个合适的数据结构里以便后续操作。 - **时间轴离散化**:考虑到浮点数精度误差可能导致计算错误,应该把整个过程划分成若干个小的时间间隔来进行模拟仿真。 - **碰撞检测算法实现**:编写函数用来判定任意两个矩形之间是否存在重叠区域;当发现新的连接关系时更新可达性矩阵。 - **连通分量查找技术应用**:利用图论知识快速求解当前状态下哪些节点属于同一个集合内——即能否通过其他成员间接相连。 最后输出结果前记得考虑边界条件! ```cpp // 假设已经定义好了必要的类和辅助功能... bool canReachEnd(vector<Platform>& platforms, double endTime){ // 初始化工作... for(double currentTime = startTime; currentTime <= endTime ;currentTime += deltaT){ updatePositions(platforms, currentTime); buildAdjacencyMatrix(platforms); if(isConnected(startNode,endNode)){ return true; } } return false; } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值