A. Omkar and Password

题意:每次可以将相邻不相等的两项替换成他们的和(原来的两个数变成一个数),问最短能变成多短。

思路:其实会发现,如果这个序列里但凡存在一对a[i]!=a[i+1]的,不管i+1后面有多少相同的,我们都可以产生连锁反应把整个序列变成只有一项。如 3 7 7 7.... ,不管后面7有多少,我一个3就可以把它们全部打乱。所以只需要判断序列是否全相等即可。

#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 = 2e5+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();
if(n==1)
{
cout<<1<<endl;
}
else
{
int flag = 1;
rep(i,2,n) if(a[i]!=a[i-1]) flag = 0;
if(flag) cout<<n<<endl;
else cout<<1<<endl;
}
}
return 0;
}

B. Omkar and Infinity Clock

题意: 有k个操作,每次把所有a[i]变成最大值 - a[i],问最后序列。

思路:随便写几个例子会发现有规律存在,其实就只在两个序列里面来回变动。所以只需要考虑奇偶性就行。

#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 = 2e5+200;
const int inf=0x3f3f3f3f3f3f3f3f;
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(); ll k = read();
ll ma = -inf, mi = inf;
rep(i,1,n) a[i] = read(), ma = max(ma,a[i]), mi = min(mi, a[i]);
if(k&1)
{
rep(i,1,n) cout<<ma - a[i]<<' '; cout<<'\n';
}
else
{
rep(i,1,n) cout<<(ma - mi) - (ma - a[i])<<' '; cout<<'\n';
}
}
return 0;
}

C. Omkar and Waterslide

题意:每次可以将序列里面一段非降子串全部+1,问最少多少步可以使得最后整体变为一个非降序列。

思路:贪心+差分。我们先拿一个例子来说,如图

我们发现从下标2->4的元素都是递减的,这一部分是肯定至少要加到a[1]那么大的。我们看看怎么加最少,首先最小的a[4]先自增,等增到a[3]那么大的时候就和a[3]一起增,同理他们俩和a[2]一样大的时候再拉上a[2]一起增,然后一路到a[1]。这样我们发现只需要考虑第一位和第四位的差分就行了。换句话说,我们这个要增加的区间里面只需要考虑最大值和最小值。因为其中间的元素我们都可以搭顺风车一起增。那到a[5]的时候发现比a[4]大了,如果它是直接比a[1]都大,我们就先把前面四个增到a[1]就行了。但是如果像图里这样刚好处于前面的最大最小值之间的话,我们就贪心一下,反正a[5]也要增加到那么大,我们先看看他后面有多少能先增加到它那么大的然后一起搭顺风车。然后发现a[6]就是,所以当a[6]增加到a[5]的时候,就可以和前面几个的一起到a[1]了。em。。。如果还不明白的话就看代码吧,非常简便。

#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 = 2e5+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 pre = a[1];
ll ans = 0;
ll cur = 0;
rep(i,1,n)
{
if(a[i] < a[i-1]) cur += a[i-1] - a[i];
else
{
ans += cur, cur = 0, pre = a[i];
}
}
ans += cur;
cout<<ans<<endl;
}
return 0;
}

D. Omkar and Bed Wars

题意:n个人环形坐下,每个人可以给相邻的人扇耳光,如果只有一个人扇了你一耳光,你就扇回去。反之可以扇左右随便一个。现在给你一个可能不按照规则来的,问你最小改变多少个人可以所有人遵循上述规则。

思路:这题看了dalao思路才明白。

1.我们定义一个联通块为一个连续有相同方向的序列。如RRRLRL,前三个R就是一个联通块。然后发现我们操作一个联通块最小只需要len/3次就够了。即隔两位改变一个,如上述RRR变成RLR就满足题意。

2.所以就统计一下这个序列有多少个联通块,每个联通块的贡献就是len/3 。 最后注意如果尾部的联通块和开头的朝向相同,他们其实是一个来的,所以合并一下。

3.如果全局就一个联通块,如RRRRR,就需要(n+2)/3,即向上取整的意思。

#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 = 2e5+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();
string s;
cin>>s;
if(n<=2)
{
cout<<0<<endl;
continue;
}
int len = 1;
int ans = 0;
int First = 0;
rep(i,1,s.size()-1)
{
if(s[i] == s[i-1]) len ++;
else
{
if(!First) First = len;
else ans += len/3;
len = 1;
}
}
if(!First) cout<<(n+2)/3<<endl;
else
{
if(s[0] == s[n-1]) cout<<ans + (len + First)/3<<endl;
else cout<<ans + len/3 + First/3 <<endl;
}
}
return 0;
}

Codeforces Global Round 10 ABCD题解的更多相关文章

  1. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  2. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  3. Codeforces Global Round 2部分题解

    传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...

  4. Codeforces Global Round 2 部分题解

    F.Niyaz and Small Degrees 挺sb的一题,为什么比赛时只过了4个呢 考虑当\(x\)固定的时候怎么做.显然可以树形DP:设\(f_{u,i=0/1}\)表示只考虑\(u\)子树 ...

  5. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  6. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  7. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  8. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  9. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  10. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

随机推荐

  1. STM32 开发环境用哪个呢?

    我的STM32开发环境血泪史:从入门到精通,少走弯路才是硬道理 说起STM32开发环境的选择,我真是有太多想说的了.作为一个已经在嵌入式领域摸爬滚打近十年的老兵,从当年刚入行时的懵懂无知,到现在能够从 ...

  2. should contain指令的用法,校验结果

    上图案例 商品添加后,匹配"商品名称","现价","库存" 首先获取"商品名称","现价",&quo ...

  3. yolov8 框架自带模型体验页面

    简介 YOLOv8 是 ultralytics 公司在 2023 年 1月 10 号开源的 YOLOv5 的下一个重大更新版本,目前支持图像分类.物体检测和实例分割任务. YOLOv8 是一个 SOT ...

  4. Web前端入门第 38 问:CSS flex 弹性盒子与 grid 网格布局区别及应用场景

    弹性盒子又称为 Flexbox,然而我更喜欢 flex 的叫法. flex 弹性盒子和 grid 网格布局作为前端开发中两把利器,它们的分界线没那么明显,虽然按照 MDN 的说法 flex 多用于一维 ...

  5. NetSpectre:通过网络读取任意内存

    摘要 推测执行是现代处理器能够实现高性能的一个关键因素.在推测执行过程中,处理器可能会执行程序一般不会执行到的操作.如果推测执行被中止,这些操作对体系结构的影响和结果会被丢弃,但对微架构的影响可能会保 ...

  6. Netty 心跳机制实现(客户端与服务端)

    Netty 心跳机制实现(客户端与服务端) Netty 的心跳机制是保持长连接有效性的重要手段,可以检测连接是否存活并及时释放无效连接.下面介绍客户端和服务端的完整实现方案. 一.服务端实现 1. 基 ...

  7. 5.3K star!硅基生命新纪元,这个开源数字人框架要火!

    嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 "只需3分钟视频素材,就能打造专属数字分身!""开源免费商用, ...

  8. 漏洞预警 | Ivanti Connect Secure栈溢出漏洞

    0x00 漏洞编号 CVE-2025-0282 0x01 危险等级 高危 0x02 漏洞概述 Ivanti Connect Secure是一款远程访问和零信任安全解决方案,它提供了SSL VPN功能, ...

  9. 数据库问题之“字符编码问题 Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x8E\x81\xE7\x88...' for column 'product_name' at row 41”

    1)表1和表2的产品名称[数据库字段]字符编译方式不一致 ①问题 org.springframework.jdbc.UncategorizedSQLException: Error updating ...

  10. 自动安装node---auto_install_k8s_node.sh

    #!/bin/bash /usr/bin/yum install lrzsz wget vim -y cd /etc/yum.repos.d/ wget https://mirrors.aliyun. ...