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

Codeforces Round 926 (Div. 2)

时间:2024-03-02 13:45:51浏览次数:23  
标签:int IOS cin long Codeforces tie Div 926 define




A - Sasha and the Beautiful Array

难度: ⭐

题目大意

给定一个长度为n的数组, 其分数为An - An-1 + An-1 - An-2 ... + A2 - A1; 问如何排列可以让该数组的分数最大;

解题思路

就是让An - A1最大;

神秘代码

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
using namespace std;
const int N = 1e6 + 10, mod = 998244353, inf = 1e18;
typedef pair<int, int> PII;
int n, m, cnt;
string s;
int p[N];
signed main(){
    IOS;
	int t;;
    cin >> t;
	while (t--) {
		cin >> n;
        for(int i = 1; i <= n; i++) cin >> p[i];
        sort(p + 1, p + 1 + n);
        cout << p[n] - p[1] << endl;
	}
	return 0;
}




B - Sasha and the Drawing

难度: ⭐⭐

题目大意

一个n * n的方格有4 * n - 2条对角线; 现在需要对这n * n个方格涂色, 要求让至少k条对角线都经过涂色的格子, 请问最少可以涂多少个格子;

解题思路

对于一个n * n的方格, 只要我们把第一行和最后一行都涂色后就可以包含所有对角线, 并且可以发现, 除了四个顶角的格子, 其他格子都必有两条对角线经过; 而这四个顶角, 先涂的前两个格子也会各自有两条对角线, 而后涂的两个虽然也各自有两条, 但是各自其中一条是重复的, 也就是只能算一条; 所以当k <= 4 * n - 4时就按每个格子包含两条对角线来算即可; 如果大于, 则多出来的按一个格子一条即可;

神秘代码

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
using namespace std;
const int N = 1e6 + 10, mod = 998244353, inf = 1e18;
typedef pair<int, int> PII;
int n, m, cnt;
string s;
int p[N];
signed main(){
    IOS;
	int t;;
    cin >> t;
	while (t--) {
		int a, b;
        cin >> a >> b;
        if(b <= 4 * a - 4) cout << b / 2 + b % 2 << endl;
        else cout << 2 * a - 2 + (b - 4 * a + 4) << endl;
	}
	return 0;
}




C - Sasha and the Casino

难度: ⭐⭐

题目大意

小莫去赌场赌钱, 现有本钱a元, 在某一轮中投入b元, 如果赌赢了则变为k * b元, 即赚了(k - 1) * b元; 赌输了则失去b元; 而且该赌场有一个福利, 即连续输x轮后下一轮必赢; 请问小莫是否可以在任意时刻稳定赢钱;

解题思路

本题题意有点模糊, 总之就是想着以最小的代价输x轮, 然后赢一轮赚回来; 而是每一轮都要想着赢钱; 比如说当前小莫已经输了x元, 那么一轮小莫必须想着赚回来, 也就是至少投入y元, 使得(k - 1) * y >= x; 知道这个逻辑后就可以进行模拟了, 因为x的范围很小, 所以模拟x轮即可;

神秘代码

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
using namespace std;
const int N = 1e6 + 10, mod = 998244353, inf = 1e18;
typedef pair<int, int> PII;
int n, m, res;
signed main(){
    IOS;
    int T;
    cin >> T;
    while(T--){
        int k, x, a;
        cin >> k >> x >> a;
        int now = 0;
        bool f = true;
        for(int i = 1; i <= x + 1; i++){
            if(a < now / (k - 1) + 1){
                f = false;
                break;
            }
            a -= now / (k - 1) + 1;
            now += now / (k - 1) + 1;
        }
        if(f) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
	return 0;
}




D - Sasha and a Walk in the City

难度: ⭐⭐⭐⭐

标签:int,IOS,cin,long,Codeforces,tie,Div,926,define
From: https://www.cnblogs.com/mostimali/p/18048557

相关文章

  • Codeforces Round 931 (Div. 2)
    CodeforcesRound931(Div.2)比赛链接A.TooMinTooMax思路这题一开始我以为就是简单的模拟一下,四个for循环可能就可以,事实上并不是,因为我们想让最后的值最大,所以我们可以将数组进行排序,之后我们从最左边取两个,最右边取两个,插着求绝对值的和就行Code#include<bits/stdc......
  • Codeforces Round 911 (Div. 2) vp D题
    前面三题,就B题一道900的题目让我wa了两发,而且有点难看出来主要是想不到。。不知道该怎么像。应该算是题目理解不清晰吧,很麻烦。。这个原因可以说是没有一个完整的思考路径,我能够直接想到答案接近的处理方法,但是细节上没有注意。在考虑问题的时候可能。。需要慢一些,太快了,容易漏......
  • CodeForces 1936D Bitwise Paradox
    洛谷传送门CF传送门和CF1004FSonyaandBitwiseOR很像。考虑一次询问怎么做。考虑分治,每次只计算左端点在\([l,mid]\),右端点在\([mid+1,r]\)的区间的贡献。对于每个\(i\in[l,mid]\),维护最小的\(j\in[mid+1,r]\)使得\([i,j]\)的或\(\gev\),那么\(\m......
  • Codeforces 839E Mother of Dragons
    令\(s_u\)为点\(u\)分配到的权值。结论:最后选出来有权值的肯定是一个最大团。考虑反证,如果\(x,y\)间没有连边,则\(x,y\)的贡献是独立的,若\(\sum\limits_{(u,x)\inE}s_u\ge\sum\limits_{(v,y)\inE}s_v\),那么就可以把\(s_y\)给\(s_x\),否则把\(s_x\)给\(s_......
  • div3笔记
     Problem-E-Codeforces这道题用了记录一个数末尾零的板子(敲重点)!!!再说一遍,简单博弈论就是贪心!1voidsolve(){2cin>>n>>m;3vector<int>a(n),b(n);4for(inti=0;i<n;i++)cin>>a[i];5intlen=0;//这组数字总共有几位,总长度6......
  • 2024 蓝桥杯模拟赛3(div1+div2)
    2024蓝桥杯模拟赛3(div1+div2)P8834[传智杯#3决赛]序列简单的模拟,数据范围很小,暴力即可点击查看代码#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1e5+5;voidsolve(){ lln,k,a[N],cnt=0; cin>>n>>k; for(inti=1;i<=n;i++)c......
  • vue项目引入高德地图报错:Map container div not exist (火狐浏览器不加载地图)
    问题描述:谷歌浏览器正常显示地图,火狐浏览器不加载,并且报错:  Mapcontainerdivnotexist错误代码如下:  修改后代码如下:  参考大佬:https://blog.csdn.net/white_777/article/details/128286558  ......
  • Codeforces 1406E Deleting Numbers
    考虑询问每个质因子及其次数最后组合得到\(n\)。注意到\(n\)最多只会有\(1\)个\(>\sqrt{n}\)的质因子。于是考虑分成\(\le\sqrt{n}\)和\(>\sqrt{n}\)来考虑。对于\(\le\sqrt{n}\)的\(p\)。考虑先\(\texttt{B}\p\),那么还剩下的\(p\)的倍数就只有\(x\)......
  • Codeforces Round 930 (Div. 2) - sol
    20240301由于笔者实力较弱,所以这只是Div2的题解。四年一次的比赛啊,还是要打。Dashboard-CodeforcesRound930(Div.2)-CodeforcesA.ShufflePartyYouaregivenanarray\(a_1,a_2,\ldots,a_n\).Initially,\(a_i=i\)foreach\(1\lei\len\).Theopera......
  • Codeforces 1446D1 Frequency Problem (Easy Version)
    考虑求出全局的众数\(A\)。那么有一个结论,就是答案区间的众数中绝对有\(A\)。考虑反证法,如果没有\(A\),\(A\)在序列中出现的个数一定\(\ge\)区间内众数的出现个数,所以可以一直往外扩展直到\(A\)出现的个数与区间内非\(A\)众数的个数持平,这样肯定更优。于是可以考虑钦......