A. Three Strings

题意:每次可以把c[i]拿去和a[i]或b[i]交换。 问你能否把ab变成相等。

思路:在ab不相等的时候看看c能不能与一方相等来中和。不能的话就不行。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; int main()
{
int kase;
cin>>kase;
while(kase--)
{
string a, b , c;
cin>>a>>b>>c;
int flag = 1;
for(int i=0; i<a.size(); i++)
{
if(c[i]==a[i]||c[i]==b[i]) continue;
flag = 0; break;
}
puts(flag?"YES":"NO");
}
return 0;
}

B. Motarack's Birthday

题意:给一个序列,除了若干-1外全是正数,问把所有-1替换成k后,这个序列的max(abs(a[i+1] - a[i]))的最小值为多少。

思路:其实-1改变后能产生影响的也就是它相邻的非-1的数。我们只需要统计一下和-1相邻的值的最大值和最小值找出来。k为(最大值+最小值)/2是最优的。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 4e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn]; int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,n) a[i] = read();
ll ma = -1, mi = inf;
a[0] = a[n+1] = -1;
int flag = 0;
rep(i,1,n)
{
if(a[i]!=-1) flag=1;
if(a[i]==-1)
{
if(a[i-1]!=-1)
ma = max(ma, a[i-1]), mi = min(mi, a[i-1]);
if(a[i+1]!=-1)
ma = max(ma, a[i+1]), mi = min(mi, a[i+1]);
}
}
if(!flag) cout<<0<<' '<<0<<'\n';
else
{
ll m = max(ma-(ma+mi)/2, (ma+mi)/2 - mi);
rep(i,1,n) if(a[i]==-1) a[i] = (ma+mi)/2;
rep(i,1,n-1)
{
m = max(m, abs(a[i+1] - a[i]));
}
cout<<m<<' '<<(ma+mi)/2<<'\n';
}
}
return 0;
}

C. Ayoub's function

题意:定义f(s)为s串在长度1<=l,r<=|s|的满足有一个1的区间个数总和。

思路:容斥定理。 想到要直接通过1统计f(x)会很麻烦。我们可以考虑从0的角度入手。

f(x)区间里面有1就行,那就相当于是全排列 - 全为0的方案数。

考虑有一块长度为l的0串,f(x) = n(n+1)/2 - l(l+1)/2 。我们想要后者越小越好,所以想到把0的块分散开来。

而我们有m个1,可以分开m+1个0,每块有(n-m)/(m+1)个0 。 然后用余下来的0尽量均摊,多出来的贡献是((n-m)/(m+1)+1)*(n-m)/(m+1)。最后用总数减去即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), m = read();
ll zeros = n - m;
ll len = zeros/(m+1);
ll Left = zeros%(m+1);
ll ans_zeros = ( (len+1)*len/2 ) * (m+1) + Left*(len+1);
ll ans_all = (n+1)*n/2;
cout<<ans_all - ans_zeros<<'\n';
}
return 0;
}

Codeforces Round #619 (Div. 2) ABC 题解的更多相关文章

  1. Codeforces Round #312 (Div. 2) ABC题解

    [比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...

  2. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  3. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  4. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  5. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  6. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  7. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  8. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  10. Codeforces Round #545 (Div. 1) 简要题解

    这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...

随机推荐

  1. Vue的前端项目开发环境搭建

    一.本机window端:安装Node.js,其实质性功能相当于,java的maven https://nodejs.org/en/download/ 二.本机window端:检查Node.js的版本 ...

  2. B站插入外站链接地址(现已禁用)

    问题描述: B站中插入链接时,无法插入外站链接,提示[请输入正确的站内链接地址]: 日常文章编写中,经常需要插入外站链接跳转,以便于用户快速定位 分析: B站专栏文章编辑使用的富文本编辑器,应该是支持 ...

  3. .NET周刊【3月第5期 2025-03-30】

    国内文章 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp智能体框架开发语音交互 https://www.cnblogs.com/GreenShad ...

  4. Sentinel源码—5.FlowSlot借鉴Guava的限流算法

    大纲 1.Guava提供的RateLimiter限流使用示例 2.Guava提供的RateLimiter简介与设计 3.继承RateLimiter的SmoothBursty源码 4.继承RateLim ...

  5. ctf.show刷题记录_web(1-10)

    ctf平台(ctfshow) `https://ctf.show/ 1.签到 解题:base64解码 ctfshow{0da357d0-359b-47e1-80dc-5c02212725e5} 2.w ...

  6. 深入解析Tortoise-ORM关系型字段与异步查询

    title: 深入解析Tortoise-ORM关系型字段与异步查询 date: 2025/05/01 00:12:39 updated: 2025/05/01 00:12:39 author: cmd ...

  7. 解决MySQL 8.0 设置简单密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy require...

    MySQL8.0下设置简单密码出现错误提示:ERROR 1819 (HY000): Your password does not satisfy the current policy requirem ...

  8. BP算法完整推导 2.0 (下)

    上篇主要阐述 BP算法的过程, 以及 推导的 4 大公式的结论, 现在呢要来逐步推导出这写公式的原理. 当理解到这一步, 就算真正理解 BP算法了. 也是先做一个简单的回顾一下, 不是很细, 重点在推 ...

  9. Java Solon-MCP 实现 MCP 实践全解析:SSE 与 STDIO 通信模式详解

    参文参考自:https://blog.csdn.net/lingding_cn/article/details/147355620 一.MCP简介 MCP(Model Context Protocol ...

  10. 使用torch pruning工具进行结构化剪枝

    网络结构定义 import torch import torch.nn as nn import torch.nn.functional as F import torch_pruning as tp ...