首页 > 其他分享 >Codeforces Round 929 (Div. 3)

Codeforces Round 929 (Div. 3)

时间:2024-02-28 19:44:51浏览次数:21  
标签:std end int Codeforces long 929 solve Div define

Codeforces Round 929 (Div. 3)

比赛链接

A. Turtle Puzzle: Rearrange and Negate

思路

根据题意,很明显数组中所有元素的绝对值总和就是答案

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()

#define int long long

void solve(){
    int n;
    cin>>n;
    std::vector<int> a(n+1);
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans+=abs(a[i]);
    }
    cout<<ans<<endl;
    return ;
    
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

B. Turtle Math: Fast Three Task

思路

对3取模后无非是0,1,2 如果一开始是0则不需要操作,如果是2只需要执行一次第二次操作,如果是1就要看序列当中是否有一个元素对3取模后是1,则只需要删除一次就可,否则就必须删除两个取模是2的

Code

//我写的有点复杂
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()

#define int long long

void solve(){
    int n;
    cin>>n;
    int ans=0;
    int ans1=0;

    std::vector<int> a(n+1);
    std::vector<int> b;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans+=a[i];
    }
    if(ans%3==0){
        cout<<0<<endl;
        return ;
    }
    if(ans%3==2){
        cout<<1<<endl;
        return ;
    }
    else{
        for(int i=1;i<=n;i++){
            b.push_back(a[i]%3);

        }
        sort(b.begin(),b.end());
        for(int i=0;i<b.size();i++){
            if(b[i]==1){
                cout<<1<<endl;
                return ;
            }
            else if(b[i]==2){
                ans1++;

            }

        }
        if(ans1>=2){
            cout<<2<<endl;
            return ;
            
        }

    }
    
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

C. Turtle Fingers: Count the Values of k

思路

貌似模拟就可以解决,数据量也不算很大

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()

#define int long long

void solve(){
    int a,b,l;
    cin>>a>>b>>l;
    set<int> s;

    for(int i=0;pow(a,i)<=l;i++){
        int res1=pow(a,i);
        if(l%res1){
            continue;
        }
        for(int j=0;pow(b,j)<=l;j++){
            int res2=pow(b,j);
            if(l%res2){
                continue;
            }
            if(l%(res1*res2)==0){
                s.insert(l/res1/res2);

            }

        }
    }
    cout<<s.size()<<endl;
    
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

D. Turtle Tenacity: Continual Mods

思路

如果我们想让一个数组的所有元素进行取模最后得数不为0的话,我们就需要让小数字在前面,但是因为数组中是可以出现重复元素的,所以我们又必须保证其他数字对最小的数取模不为0,这样就肯定可以

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()

void solve(){
	int n;
	cin>>n;
	std::vector<int> a(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int minn=*min_element(a.begin()+1,a.end());
	if(count(a.begin()+1,a.end(),minn)==1){
		cout<<"YES"<<endl;
		return ;
	}
	for(int i=1;i<=n;i++){
		if(a[i]%minn!=0){
			cout<<"YES"<<endl;
			return ;
		}
	}
	cout<<"NO"<<endl;
	return ;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;

}

标签:std,end,int,Codeforces,long,929,solve,Div,define
From: https://www.cnblogs.com/du463/p/18041587

相关文章

  • D. Vlad and Division
    原题链接题解对于一个数,我们将其转换成二进制,然后补零到31位我们发现,能和数x配对的数只有一个,那就是按位翻转后的x,即x和\(2^{31}-1\)异或的值所以我们要找有没有能互相配对的值,以及组数,配对用map?code#include<bits/stdc++.h>usingnamespacestd;constintval=2147483......
  • Codeforces 441E Valera and Number
    首先看到\(\times2\)\(+1\)和最后答案的计算方式,能想到看成二进制来处理。考虑到\(\times2\)就是在最后加了一个\(0\)。不妨倒过来看,\(\times2\)就相当于舍弃了最低位。于是可以考虑\(\text{DP}\),\(f_{i,j}\)为考虑后面的\(i\)个操作,目前\(+\)的值为\(j\)的......
  • 【vue】做一个从右边出来又回去的一个抽屉div
    前言:工作需要做一个从右往左出现的一个弹窗,要有抽屉效果,看了网上各种方法好多都不能用,最后试了一种可以用,但是忘记是哪个网址了,现在就是自己写一下这个随便以后用到方便找。做一个从右边出来又回去的一个抽屉divhtml代码<divclass="addBtn"@click="show">点击按钮出......
  • Codeforces 1705F Mark and the Online Exam
    先问全\(\texttt{T}\),记得到的数为\(a\)。接下来问\(len\)个位置为\(\texttt{T}\),得到的数为\(b\)。因为剩下\(n-len\)个位置肯定都会被刚好算上一次,对于这\(len\)个数里的\(\texttt{T}\)的个数\(x\)就有式子\((n-len)+2x=a+b\),可以解得\(x=\frac{......
  • 题解 NKOJ2929 【[THUSC2014] 函数求解】
    代码:#include<iostream>#include<queue>#include<cstdio>#include<cmath>usingnamespacestd;typedefstruct{ intnxt; intend; intdis; doublecost;}Edge;constintN=2e3,M=400+7,K=80800+7;constdoubleep......
  • 题解 CF1781G Diverse Coloring
    \(\texttt{link}\)题意给定一棵\(n\)个点的二叉树,现对其每个点染成黑色或白色。一种合法的染色方案满足:对于所有黑色的点,都存在白色的点与之相邻。对于所有白色的点,都存在黑色的点与之相邻。一种染色方案的权值是染成黑色的点数与染成白色的点数之差的绝对值。\(\foral......
  • Codeforces 286E Ladies' Shop
    考虑\(p_i\)满足什么不会被选。令当前选出来的\(p_j\)的集合为\(S\)。能发现当用\(S\)中的数能够凑(可多选,可选重)出\(p_i\)时\(p_i\)就不会被选。考虑凑出\(p_i\)的最后一步所用的\(2\)个数\(x+y=p_i\)。因为这\(2\)个数一定能被\(S\)中的数凑出且题目......
  • Codeforces Round 909 (Div
    CodeforcesRound909(Div.3)A.GamewithIntegers显然就是还要不是三的倍数就能赢!intn; cin>>n; intk; while(n--) { cin>>k; if(k%3==0){ cout<<"Second"<<endl; }else{ cout<<"First"<<endl; } }B......
  • Codeforces Round 905 (Div
    CodeforcesRound905(Div.3)A.Morning此题将其看为光标一直移动,其中移动次数就是坐标之差的绝对值,0看做10,由于其显示也需一次操作,所以加上四。#include<bits/stdc++.h>usingnamespacestd;intmain(){ intt; cin>>t; while(t--) { intarr[4],count=0; ......
  • Codeforces Round 900 (Div
    CodeforcesRound900(Div.3)A.HowMuchDoesDaytonaCost?这个题简单,在子段上最常见的元素其实只要这个元素出现就行intt; cin>>t; intn,k; while(t--) { cin>>n>>k; intarr[n]; intout=0; for(inti=0;i<n;i++) { cin>>arr[i]; } for(......