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. jmeter从csv文件中取数据设置变量的方法

    从csv取数据是参数化方法之一 首先,CSV数据文件设置,选择数据文件,点击http请求,右键-添加-配置元件-csv data set config,添加CSV数据文件设置 添加后可对设置名称进行修 ...

  2. java泛型简单入门

    泛型 泛型 泛指某一种类型 ( 必须是 引用类型 ) 明确时机: 1.有时候 创建对象的时候, 明确泛型 2.有时候 调用一个方法时, 明确泛型 3.有时候 创建一个类型,然后实现一个接口的时候 明确 ...

  3. github仓库的README文件在线预览视频

    1. 新建一个 issue ,在 issue 里面上传 mp4 视频文件(有限制,不能超过10MB) 上传超过10MB的视频会提示报错 2. 拿到视频文件的上传地址 3. 将这个地址直接贴到 READ ...

  4. Modbus-RTU报文结构及常用功能码详解

    Modbus-RTU报文结构及常用功能码 Modbus是一种串行通讯协议,是Modicon公司(现在的施耐德电气)于1979年为使用可编程逻辑控制器(PLC)通信而发表的.现在的Modbus协议已经成 ...

  5. 1.3K star!VisActor团队开源神器,3秒生成商业级图表,程序员直呼真香!

    嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 项目速览 VChart 是VisActor团队推出的高性能可视化解决方案,GitHub斩获2 ...

  6. 操作系统综合题之“采用记录型信号量机制实现进程INPUT、PROCESS和OUTPUT的同步算法(代码补充)”

    1.问题:系统中有有三个进程INPUT.PROCESS和OUTPUT,共用两个缓冲区BUF1和BUF2.假期设BUF1中最多可放10个数据,现已放入了2个数据:BUF2最多可放5个数据.INPUT进程 ...

  7. quartz 读取xml文档执行任务

    xml 配置 <?xml version="1.0" encoding="UTF-8"?> <job-scheduling-data xmln ...

  8. Python基础 - 控制结构

    控制结构: 顺序, 分支, 循环, 理解了, 其实编程就入门一半了. 条件表达式 条件表达式的值只要不是:0 . None. False. 空列表. 空元组. 空集合. 空字典. 空字符串. 空ran ...

  9. VMware workstation 部署微软MDT系统

    一.环境准备 1. VMware Workstation 虚拟机配置 新建虚拟机 类型:Microsoft Windows Server 2022 Standard 内存:4GB+ 硬盘:100GB( ...

  10. RPC实战与核心原理之路由策略

    路由策略:怎么让请求按照设定的规则发到不同的节点上 回顾 健康检测在 RPC 中的作用,简单来讲就是帮助调用方应用来管理所有服务提供方的连接,并动态维护每个连接的状态,方便服务调用方在每次发起请求的时 ...