Codeforces Round #706 (Div. 2) D. Let's Go Hiking 博弈 思维
思路:A要赢的大前提就是当前x是一个波峰。
因为如果是一个直线单调的话如1 2 3 4 5(或者5 4 3 2 1),不管A选哪个位置,B直接在他下一个位置封死,A就直接GG。
现在考虑波峰的时候,那A就有两条路可以走,走左边或者走右边都可以(这个时候B就不能直接封死A了)。但是如果B能在别的地方挑一条比这两条路还长的路,那A还是输。当B选不到更长的路的时候,就会尽量的恶心A,走两条路中较长的那一条,这个时候A走较短的话必输,所以AB这时候必须相向而行。这个时候这条路的长度是奇数的话A就能赢了,且是唯一的一种赢法。
看看图解吧。

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 endl '\n'
#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} };
ll n;
ll a[maxn];
ll dp[maxn][2];
int main()
{
n = read();
rep(i,1,n) a[i] = read();
dp[1][0] = dp[n][1] = 1;
map<ll,ll> cnt1;
map<ll,ll> cnt2;
ll ma = 0;
rep(i,2,n)
{
if(a[i]>a[i-1]) dp[i][0] = dp[i-1][0] + 1;
else dp[i][0] = 1;
}
per(i,n-1,1)
{
if(a[i]>a[i+1]) dp[i][1] = dp[i+1][1] + 1;
else dp[i][1] = 1;
}
rep(i,1,n)
{
cnt1[dp[i][0]]++;
cnt2[dp[i][1]]++;
ma = max(ma,max(dp[i][0],dp[i][1]));
}
ll ans = 0;
rep(i,1,n)
{
if(dp[i][0]==1||dp[i][1]==1) continue;
ll ma1 = max(dp[i][0], dp[i][1]);
ll mi1 = min(dp[i][0],dp[i][1]);
if(ma>ma1||ma==ma1&&(cnt1[ma]>1||cnt2[ma]>1)||(ma==ma1&&(cnt1[ma]==1&&cnt2[ma]==1&&ma%2==0)) ) continue;
if(ma1-mi1<=0) ans++;
}
cout<<ans<<endl;
return 0;
}
Codeforces Round #706 (Div. 2) D. Let's Go Hiking 博弈 思维的更多相关文章
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)
Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...
- Codeforces Round #706 (Div. 2)B. Max and Mex __ 思维, 模拟
传送门 https://codeforces.com/contest/1496/problem/B 题目 Example input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 ...
- Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈
C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...
- Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...
- Codeforces Round #703 (Div. 2)__ B. Eastern Exhibition__ 纯纯的思维
原题链接https://codeforces.com/contest/1486/problem/B 题目 解题思路 这是个思维题, 算是货仓选址的变式, 想要到达各个点距离最小,我们的目标可以化为先 ...
- Codeforces Round #553 (Div. 2)B. Dima and a Bad XOR 思维构造+异或警告
题意: 给出一个矩阵n(<=500)*m(<=500)每一行任选一个数 异或在一起 求一个 异或在一起不为0 的每行的取值列号 思路: 异或的性质 交换律 x1^x2^x3==x3^x2 ...
- Codeforces Round #512 (Div. 2) D. Vasya and Triangle(几何+思维)
题目 题意: 给出 n,m,k ,让你在长为 n,宽为 m 的坐标系里构建一个三角形,使得面积= n*m/k.如果存在,输出“YES”,输出三角形三个顶点的坐标: 如果不存在,输出“NO”. 思路: ...
- Codeforces Round #600 (Div. 2) D题【并查集+思维】
题意:给你n个点,m条边,然后让你使得这个这个图成为一个协和图,需要加几条边.协和图就是,如果两个点之间有一条边,那么左端点与这之间任意一个点之间都要有条边. 思路:通过并查集不断维护连通量的最大编号 ...
- Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- Python科学计算系列2—不等式和不等式组
1.一元二次不等式求解 例1:求下列不等式的解 代码如下: from sympy import symbols, solve x = symbols('x') f = x ** 2 + x - 6 p ...
- MySQL的limit优化2
一.底层原理 在 MySQL 8.0 中,当使用 LIMIT offset, count 进行分页查询时,如果 offset 非常大(例如 LIMIT 200000, 10),性能会显著下降. 这是因 ...
- ShardingJdbc学习笔记
Mysql主从复制遇到问题 安装mysql Install/Remove of the Service Denied!错误的解决办法
- elemengui分页
<!-- 分页模块 --> <template> <div class="block" style="margin-top:20px&quo ...
- Win10/win11系统如何禁用笔记本自带键盘、笔记本键盘禁用后无法恢复解决办法【靠谱】
原文:[靠谱]Win10/win11系统如何禁用笔记本自带键盘.禁用后无法恢复解决办法 - 搜栈网 (seekstack.cn)
- Linux限制可通过SSH登录到服务器的IP——hosts.allow
Linux服务器针对固定的IP进行禁止.允许登录 linux 服务器通过设置/etc/hosts.allow和/etc/hosts.deny这个两个文件进行限制. 优先级:hosts.allow大于h ...
- 【代码】Processing笔触手写板笔刷代码合集(包含流速、毛笔笔触、压感笔触等多种)
代码来源于openprocessing,考虑到国内不是很好访问,我把我找到的比较好的搬运过来! @ 目录 合集1 笔触4(流速笔触,速写) 笔触5(流速笔触,晕染) 笔触6(流速笔触,毛笔) 合集2 ...
- Day.js 2kb日期时间处理javascript库
Day.js 与 Moment.js 的比较 优点 体积小:Day.js 的体积仅为 2KB 左右,而 Moment.js 的体积约为 67KB. API 相似:Day.js 的 API 与 Mome ...
- GStreamer开发笔记(三):测试gstreamer/v4l2+sdl2/v4l2+QtOpengl打摄像头延迟和内存
前言 前面测试了多种技术路线,本篇补全剩下的2种主流技术,v4l2+sdl2(偏底层),v4l2+QtOpengl(应用),v4l2+ffmpeg+QtQImage(Image的方式转图低于1ms ...
- 参考案例之“对象调用方法时,如何在方法中使用对象,例如(root.display()的display方法中使用root)”
一.对象调用方法时,如何在方法中使用对象,例如(root.display()的display方法中使用root) 1.测试方法 @Test public void suanfa24() { TreeN ...