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

Codeforces Round 957 (Div. 3)

时间:2024-07-17 12:11:01浏览次数:7  
标签:typedef int Codeforces long cin -- 957 Div define

知识点

1.几个数相乘时,更小的数增加会比更大的数增加得到的乘积来得大

题解

A. Only Pluses
1.几个数相乘时,当更小的数增大时,得到的乘积会比更大的数增大来得大,也就是更小的数字权重会比较大,那么在5次+1的过程中,每次找最小值++即可

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
#define x first
#define y second
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};


void solve()
{
    int a,b,c; cin>>a>>b>>c;
    int minn=1e9;
    for(int i=0;i<5;i++)
    {
        minn=min({a,b,c});
        if(a==minn) a++;
         else if(b==minn) b++;
        else if(c==minn) c++;
    }
    cout<<a*b*c<<endl;
}


signed main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}

B. Angry Monk
1.把元素从小到大排序以后,拆开那些不是1的,假设数字为k,需要k-1次,拆完以后,合并需要的次数为除最后一个元素外所有元素加起来

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define x first
#define y second
typedef pair<int,int> pii;
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};

signed main()
{
	int t=1;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		vector<int>ve(k);
		for(int i=0;i<k;i++) cin>>ve[i];
		sort(all(ve));
		int ans=0,sum=0;
		for(int i=0;i<k-1;i++)
		{
			ans+=ve[i]-1;
			sum+=ve[i];
		}
		ans+=sum;
		cout<<ans<<endl;
		
	} 	
}

C. Gorilla and Permutation
1.简单的构造,只要让最大值排在第一个,可以保证fi的和尽量大,让m排在最后一个,可以保证gi的和尽量小,然后左边递减,右边递减,直到用完所有元素即可

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define x first
#define y second
typedef pair<int,int> pii;
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};

signed main()
{
	int t=1;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		cin>>n>>m>>k;
		int cnt=n-m;
		int te=n;
		int ts=1;
		for(int i=0;i<n-m;i++) cout<<te--<<" ";
		for(int i=0;i<m;i++) cout<<ts++<<" ";
		cout<<endl;
	} 	
}

D. Test of Love
1.如果可以跳到岸边就直接跳,如果不行,我们就要寻找可以跳的木头,当下一个木头无法抵达的时候,跳到水里,就检查游泳的距离够不够,或者有无鳄鱼即可。尽可能跳的远以避开鳄鱼,并尽可能少游泳

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
#define x first
#define y second
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};


void solve()
{
    int n,m,k; cin>>n>>m>>k;
    string s; cin>>s;
    vector<int>p;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='L') p.push_back(i); 
    }
    p.push_back(n);
    int i=-1;//当前位置
    int pos=0;//代表下一个木头的位置
    while(i<n-1)
    {
        if(m>=p[pos]-i) i=p[pos]; //下一个木头的位置到当前位置的距离小于m
        else {
            i+=m;//跳不到下一个木头或者没木头直接跳到终点了
            if(i>n-1){
                cout<<"YES"<<endl;
                return ;
            }
            //到下一个木头前只能游泳
            while(i<n&&i<p[pos]){
                if(s[i]!='C'&&k>0){//当没有鳄鱼的时候可以游,且不能游超过k
                    i++;
                    k--;
                }else{
                    cout<<"NO"<<endl;
                    return ;
                }
            }
  
        }
        pos++;
    }
    cout<<"YES"<<endl;
    
    
}


signed main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}

E. Novice's Mistake

标签:typedef,int,Codeforces,long,cin,--,957,Div,define
From: https://www.cnblogs.com/swjswjswj/p/18305934

相关文章

  • Codeforces Round 898 (Div. 4)(A~H)
    目录A.ShortSortB.GoodKidC.TargetPracticeD.1DEraserE.BuildinganAquariumF.MoneyTreesG.ABBCorBACBH.MadCityA.ShortSortProblem-A-Codeforces暴力枚举每个位置的交换即可。#include<iostream>#include<algorithm>#include<queue......
  • Codeforces Round 957 (Div. 3)
    题目链接:CodeforcesRound957(Div.3)总结:E不懂,F差一个set去重A.OnlyPlusesfag:枚举B.AngryMonkfag:模拟Solution:分裂的花费为\(a_i-1\),添加的花费为\(a_i\)。C.GorillaandPermutationfag:思维Solution:大于等于\(k\)的数,逆序放在最前面,小于等于\(m\)的数,从最后面......
  • Codeforces Round 958 (Div. 2)补题
    文章目录A题(拆分多集)B题(获得多数票)C题(固定OR的递增序列)A题(拆分多集) 本题在赛时卡的时间比较久,把这题想复杂了,导致WA了两次。后来看明白之后就是将n每次转换成k-1个1,到最后分不出来k-1个1直接一次就能分完,即结果加一;#include<bits/stdc++.h>#definein......
  • CodeForces 1983A Array Divisibility
    题目链接:CodeForces1983A【ArrayDivisibility】思路    按规律可得,当a[i]=i时满足题目要求。代码#include<functional>#include<iostream>#include<algorithm>#include<queue>#include<stdio.h>#include<string>#include<cstring......
  • CodeForces 1983B Corner Twist
    题目链接:CodeForces1983B【CornerTwist】思路    可以发现操作一次,被操作位置的对应每一横行和每一纵行的加减数都是3,所以可以根据网格a和b的横纵状态确定是否通过操作使得网格a到达网格b。代码#include<bits/stdc++.h>usingnamespacestd;#definelllonglo......
  • CodeForces 1992A Only Pluses
    题目链接:CodeForces1992A【OnlyPluses】思路    代码#include<functional>#include<iostream>#include<algorithm>#include<queue>usingnamespacestd;#definelllonglongconstintN=500+10;inta[N];voidsolve(){intn......
  • CodeForces 1992D Test of Love
    题目链接:CodeForces1992D【TestofLove】思路    从起点开始起跳,找出下一个木头的位置,若与当前位置的距离小于等于m,则可以直接跳过去,否则判断当前位置与下一个木头之间有没有鳄鱼,有鳄鱼则不能到达对岸,否则继续查找下一个木头,直到对岸。代码#include<functional>......
  • CodeForces 1992E Novice's Mistake
    题目链接:CodeForces1992E【Novice'sMistake】思路    直接对a,b枚举肯定会超时,因为a,b数数字过大,但是通过结果a*n-b可以发现结果最多为6位数,所以对结果的位数进行枚举,然后枚举a,来计算出b并判断是否符合题意,同时需要去掉b不符合题目的范围的情况。代码#includ......
  • CodeForces - 1485F
    题目大意给定数组\(b\),求有多少\(a\)数组满足\(a_i=b_i\or\\sum\limits_{k=1}^ia_k=b_i\)。分析既然有前缀和,不妨将前缀和计入状态中,设\(dp_{i,j}\)为前\(i\)个前缀和为\(j\)的方案数。考虑两种条件的转移方程。若选第一种,有\(dp_{i,j}=dp_{i-1,j-b_i}\)若......
  • Codeforces Round #956 (Div. 2) and ByteRace 2024
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1983孩子们我回来了。这场实在是太对胃口,vp不到1h就4题了之后EF也口出来了,然而赛时睡大觉去了没打真是亏死。感觉自己的文字能力已经很牛逼了,不需要再多练了,以后的题解都会写得简略些。A......