首页 > 其他分享 >CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)

CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)

时间:2024-01-29 12:23:54浏览次数:15  
标签:cnt Rated int cin long solve Prizes Div

CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)

比赛链接

A. Jagged Swaps

思路:

考虑到题目要求,给定的排列第一位必须是1才会构造出可行性序列,如果不是就是没有办法

Code

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


void solve() {
	int n;
	cin>>n;
	std::vector<int> a;
	for(int i=1;i<=n;i++){
		int x; cin>>x;
		a.push_back(x);
	}
	if(a[0]!=1){
		cout<<"NO"<<endl;
		return ;
	}
	else{
		cout<<"YES"<<endl;
		return ;
		
	}
	
}

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

B. AB Flipping

思路:

根据题意,我们不难发现如果存在合理的交换,每个连续的B都会交换一次,而与之有关系的A如果也是连续的,自然也是可以每个都可以交换一次,从后往前考虑

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	int cnt=0;
	for(int  i=n-1;i>=0;i--){
		if(!cnt&&s[i]=='A'){
			continue;
		}
		if(s[i]=='B') cnt++;
		else{
			ans+=cnt;
			cnt=1;
		}
	}
	cout<<ans<<endl;
	

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

C. Matching Arrays

思路:

考虑一个贪心的思路,我们要求a中最大的x个数与b中最小的x个数字匹配
a中最小的n-x个数与b中最大的n-x个数匹配,一旦两者之中都出现不匹配的情况那就是无法构成一组可行性答案,直接输出NO

Code

#include<bits/stdc++.h>
 
using namespace std;
 
typedef pair<int, int> PII;
typedef long long ll;

const int N = 200010;

int n, x;
int b[N], ans[N];
bool st[N];

void solve()
{
    cin >> n >> x;
    memset(st, false, sizeof st);
    vector<PII> a;
    
    for(int i = 0; i < n; i ++)
    {
        int ai;
        cin >> ai;
        a.push_back({ai, i});
    }
    for(int i = 0; i < n; i ++)cin >> b[i];
    sort(a.begin(), a.end());
    sort(b, b + n);
    
    int f = 1;
    for(int i = n - x, j = 0; j < x; j ++, i ++)
    {
        if(a[i].first <= b[j])
        {
            f = 0;
            break;
        }
        ans[a[i].second] = b[j];
    }
    if(!f)
    {
        cout << "NO" << endl;
        return;
    }
    
    for(int j = x; j < n; j ++)
    {
        int i = j - x;
        if(a[i].first > b[j])
        {
            f = 0;
            break;
        }
        ans[a[i].second] = b[j];
    }
    if(!f)
    {
        cout << "NO" << endl;
        return;
    }
    
    cout << "YES" << endl;
    for(int i = 0; i < n; i ++)cout << ans[i] << ' ';
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin >> _;
    while(_ --)
    {
        solve();
    }
    
    return 0;
}

标签:cnt,Rated,int,cin,long,solve,Prizes,Div
From: https://www.cnblogs.com/du463/p/17994244

相关文章

  • Codeforces Round 921 (Div. 2)
    A-WeGotEverythingCovered!难度:⭐题目大意给定n和k两个整数,要求用前k个小写字母组成一个字符串;该字符串的子串应包含所有由前k个字母组成的长度为n的字符串全排列;要求输出最短的满足条件的字符串;解题思路这题题目挺唬人,但其实是个水题;所谓最短,其实......
  • CF337E Divisor Tree
    题意简述定义DivisorTree为一棵树:叶子上的数为质数。非叶子上的数为其所有儿子上的数的乘积。给定\(n\)个数\(a_i\),你需要让每个\(a_i\)都在DivisorTree上出现,并最小化DivisorTree的节点数量。\(n\le8,a_i\le10^6\)。分析显然DivisorTree上只能有质数......
  • Codeforces Round 921 (Div. 2)(A~E)
    好久不打用小号水了一场,赛时坑坑拌拌勉强四题,以为美美上分,结果重测时卡掉了我没细想复杂度就交了的B题,这下小丑了 A.WeGotEverythingCovered!直接输出n次连续前k个字母即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongsignedmain(){ ios......
  • Codeforces Round 921 (Div. 2)
    CodeforcesRound921(Div.2)A-WeGotEverythingCovered!解题思路:以前\(k\)个字符都出现过至少一次为一轮,构造\(n\)轮即可。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecon......
  • Codeforces Round 920 (Div. 3)
    A-Square难度:⭐题目大意给定正方形的四个顶点,求该正方形的面积;解题思路根据四个点找出长和宽即可,因为数据范围有负数,为了方便我都进行了移位;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false);cin.tie(0......
  • Codeforces Round 921 (Div. 2) A-D
    倒叙讲题预警()传送门:https://codeforces.com/contest/1925D.GoodTrip题意:有n个小盆友,其中m对是好盆友,每队好盆友有友谊度fi。老师要举办k次远足,每次挑一对小盆友去,被挑到的小盆友友谊值+1。如果一对儿童不是朋友,那么他们的友谊值为0,在以后的游览中不会改变。求所有被选中参......
  • Codeforces Round 921 (Div. 1) 记录(A-D)
    比赛链接:https://codeforces.com/contest/1924官解链接:https://codeforces.com/blog/entry/125137这场整体来说表现还可以,最终performance\(2431\),delta\(+33\)。A.DidWeGetEverythingCovered?还不错的贪心题。进入状态有点慢,写了几个小错误B.SpaceHarbourC.Frac......
  • Codeforces Round 921 (Div. 2) 赛后总结
    搜索替换int->longlong是一个好习惯赛后5分钟就改对E题了,好可惜。不过1个小时都没能做出来,也说明自己不太熟练吧线段树善于维护满足区间可加性的一类信息,这与本题中的代价和相契合。特殊之处在于其修改方式。每个区间会在线段树上被划分为\(O(log_{2}n)\)个小区间即使是最......
  • Codeforces Round 921 (Div. 2)
    CodeforcesRound921(Div.2)比赛地址A.WeGotEverythingCovered!思路这个就是一个简单的拼接,这里很容易的发现我们最后最优的方法就是将所要拼写的字母按顺序拼接成n份就好了,但是这里需要主义一下简单的优化Code#include<bits/stdc++.h>usingnamespacestd;#define......
  • CF Round 921 (Div. 2)
    linkA一种可行的方案是将前\(k\)个字母重复\(n\)次,对于每个要找的字符串,从\(n\)段中分别选取一个字符就可以得到。B如果\(x\)是答案的话,它一定满足\(x|n,\frac{x}{n}\leqm\),直接枚举答案,时间复杂度\(O(\sqrtn)\)。C沿着A的思路继续思考,如果能将\(s\)分成至......