首页 > 其他分享 >Codeforces Round 922 (Div. 2)

Codeforces Round 922 (Div. 2)

时间:2024-01-31 12:11:28浏览次数:17  
标签:std return int Codeforces long -- solve 922 Div

Codeforces Round 922 (Div. 2)

比赛链接

A. Brick Wall

思路

简单的模拟,要想实现最高的稳定性,就横着放就可以了,因为长度必须大于等于2,所以最后即使不能被2整除,也可以算在里面

Code

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


void solve() {
	int n,m;
	cin>>n>>m;
	int res=m/2*n;
	// int 
	cout<<res<<endl;
	
}

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

B. Minimize Inversions

思路

比赛时候没有仔细证明,因为a数组和b数组是同时改变的,所以是一对一对改变的,因此我们可以稍微贪心的处理一下

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	int a,b;
	node(int x,int y){
		a=x;
		b=y;

	};
	friend bool operator < (node x,node y){//利用友元函数来创建
		return (x.a+x.b)<(y.a+y.b);

	}

};

void solve() {
	int n;
	cin>>n;
	std::vector<int> a(n+1),b(n+1);
	vector<node> c;

	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(int i=1;i<=n;i++){
		c.push_back(node(a[i],b[i]));

	}
	sort(c.begin(),c.end());
	for(auto x:c){
		cout<<x.a<<" ";
	}
	cout<<endl;

	for(auto x:c){
		cout<<x.b<<" ";
	}
	cout<<endl;
	return ;


}

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

C. XOR-distance

思路

贪心,当然我这个没做出来,这是ctgg写的solve,我赛后参考了一下

Code

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

void solve()
{
    ll a,b,r;
    cin>>a>>b>>r;

    if(a>b) swap(a,b);//a<b
    int flag=0;
 
    for(int i=60;i>=0;i--)
    {
        int t1=a>>i&1;
        int t2=b>>i&1;
        if(t1==t2) continue;
        else
        {
            if(flag==0)
            {
                flag=1;
                continue;
            }
 
            if((1ll<<i)>r) continue;
            
            if((a>>i&1)==0&&(b>>i&1)==1)
            {
                a^=(1ll<<i);
                b^=(1ll<<i);
                r-=(1ll<<i);
            }
        }
    }
    cout<<b-a<<endl;
    
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t; cin >> t; while(t--)
    solve();
    return 0;
}

标签:std,return,int,Codeforces,long,--,solve,922,Div
From: https://www.cnblogs.com/du463/p/17998994

相关文章

  • Codeforces Round 922 (Div.2)
    题目链接点这里CF1918ABrickWallvoidsolve(){lln,m;cin>>n>>m;cout<<n*(m/2)<<endl;}CF1918BMinimizeInversions注意到,当其中一个排列有序时,总的逆序对数量最少()今天找个时间补上证明对于任意一对\(i,j\)位置,其可能的逆序对总......
  • Codeforces Round 922 (Div. 2) A-C
    这次还好,虽然还是不够满意,因为D题没写出来。。A一个明显的贪心,都竖着放就好了#include<bits/stdc++.h>#definelllonglongusingnamespacestd;inlineintread(){ charc=getchar();inta=0,b=1; for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1; for(;c......
  • Codeforces Round 922 (A-C)
    第一次打Div2,对我来说还是很难,写篇博客记录一下~A题题意:T组输入,每组输入一个n,m,代表nm大小的地板,以1k大小的地砖完全覆盖地板(k>=2,且同一地板中k可以不同)。将水平放置的地砖与垂直放置的地砖相减的值定义为稳定性,求最大的稳定性是多少。思路:尽可能的使得水平放置的地砖多,垂......
  • CodeForces 1239E Turtle
    洛谷传送门CF传送门放放/ll/ll/ll。这题是个性质题。首先第一排一定是升序,第二排一定是降序。考虑第一排若存在\(i<j\)使得\(a_{1,i}>a_{1,j}\),那么交换这两个数不会变劣。第二排类似。然后发现在\(1\)走下去或在\(n\)走下去最优。考虑先求出从\(1\)走下去的......
  • 2024 蓝桥杯模拟赛 2 (div1+div2)
    A.根据题目模拟#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;voidsolve(){inta,p;cin>>a>>p;if(p<16)a=max(0ll,a-10);elseif(p>20){inttmp=p-20;a=max(0ll,a-tmp)......
  • Codeforces Round 921 (Div. 2)
    目录写在前面ABCDE写在最后写在前面比赛地址:https://codeforces.com/contest/1925。在床上躺了两天终于复活了妈的。A发现字符串\(s\)合法当且仅当\(s\)可以被分为至少\(n\)段,其中每段都包含\(k\)种字符至少1次。正确性可以归纳证明,这里懒得写了感性理解下。于是......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)比赛链接A.JaggedSwaps思路:考虑到题目要求,给定的排列第一位必须是1才会构造出可行性序列,如果不是就是没有办法Code#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){ intn; cin......
  • 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......