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. 🎀Mybatis-Plus中的MetaObjectHandler

    简介 MetaObjectHandler 是一个非常有用的组件,用于处理实体对象中的字段填充逻辑,比如自动填充创建时间.更新时间.创建人.修改人等字段. 组件介绍 MetaObjectHandler ...

  2. JVM 有那几种情况会产生 OOM(内存溢出)?

    JVM 有哪些情况会产生 OOM(内存溢出)? JVM 的内存溢出(OutOfMemoryError, OOM)是指程序在运行过程中,JVM 无法从操作系统申请到足够的内存,导致程序抛出内存溢出异常. ...

  3. MCP Server Java 开发框架的体验比较(spring ai mcp 和 solon ai mcp)

    目前已知的两个 mcp-server java 应用开发框架(ID类的,封装后体验都比较简洁): spring-ai-mcp,支持 java17 或以上 solon-ai-mcp,支持 java8 或 ...

  4. JAVA安全之JDK8u141版本绕过研究

    基本介绍 从JDK8u141开始JEP290中针对RegistryImpl_Skel#dispatch中bind.unbind.rebind操作增加了checkAccess检查,此项检查只允许来源为本 ...

  5. jdbcTemplate之“rowMapper内部类写法”

    jdbcTemplate的rowMapper内部类写法 String sql ="select sku,feature from product"List<Product&g ...

  6. HarmonyOS数据防泄漏服务(DLP)开发实战

    系统级数据防护的核心能力解析 在企业级文档管理.教育课件分发.金融合同处理等场景中,数据泄露风险贯穿文件生命周期.HarmonyOS提供的数据防泄漏服务(DLP),通过沙箱隔离.端云协同认证.细粒度权 ...

  7. IT/互联网行业突围之路:ChatGPT驱动下的未来

    @charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...

  8. 驾驭FastAPI多数据库:从读写分离到跨库事务的艺术

    title: 驾驭FastAPI多数据库:从读写分离到跨库事务的艺术 date: 2025/05/16 00:58:24 updated: 2025/05/16 00:58:24 author: cm ...

  9. OS期末复习总结

    期末样题 : 链接:https://pan.baidu.com/s/12Mfi_lnhBDbuke6B_qCiJg 提取码:khp7 一.易错易混点: 下列进程调度算法中,可能引起进程长时间得不到运行 ...

  10. django-channels自定义中间件验证token的方法

    测试版本: python 3.8 djnago 3.2 channels 3.0 需求 在使用channels 建立websocket连接的时候,需要验证客户端的token,并保存一些关键信息 实现原 ...