题意:石头剪刀布,bot有一串字符,表示他要出什么,你需要事先确定你的出招方案,然后遍历bot的字符串,从\(i\)位置开始跑一个循环,每次跑都要记录你赢的次数贡献给\(sum\),现要求\(\frac{sum}{n}\)最大,求你的最佳处找方案. 题解:贪心,全输出bot出招次数最多的对应即可. 代码: int t; string s; map<char,int> mp; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>…
题目链接:https://codeforces.com/contest/1380/problem/B 题意 你在和一个机器人玩石头剪刀布,给出一个长为 $n$ 的出拳序列,机器人会从某一处开始出拳 $n$ 次,问你要怎么出拳才能赢尽可能多的回合. 题解 全部反制机器人会出的最多的拳即可. 代码 #include <bits/stdc++.h> using namespace std; map<char, char> mp{ {'R', 'P'}, {'S', 'R'}, {'P',…
题目链接:https://codeforces.com/contest/1380/problem/D 题意 给出一个大小为 $n$ 的排列 $a$ 和一个序列 $b$,有两种操作: 花费 $x$ 消除连续 $k$ 个数 花费 $y$ 选取两个相邻的数,消除较小的数 问能否将 $a$ 变为 $b$,以及最小花费. 题解 如果序列 $b$ 中元素的出现顺序与 $a$ 不一致,则无解. 否则根据 $b$ 将 $a$ 分割为一个个区间,对每一个区间进行单独操作. 对于一个长度小于 $k$ 的区间: 如果…
题目链接:https://codeforces.com/contest/1380/problem/C 题意 给 $n$ 个数分组,要求每组的最小值乘以该组数的个数不小于 $x$ . 题解 从大到小依次分即可. 代码 #include <bits/stdc++.h> using ll = long long; using namespace std; void solve() { int n, x; cin >> n >> x; int a[n] = {}; for (i…
题目链接:https://codeforces.com/contest/1380/problem/A 题意 给出一个大小为 $n$ 的排列,找出是否有三个元素满足 $p_i < p_j\ and\ p_j > p_k$ . 题解 如果排列为增序或降序则无解,否则一定存在三个相邻的元素满足 $p_i < p_{i+1}\ and\ p_{i+1} > p_{i+2}$ . 证明 若不存在,则 $p_i \ge p_{i+1}\ or\ p_{i+1} \le p_{i+2}$,即排列…
题意:有\(n\)个队员,每个队友都有一个能力值,构造队伍,要求队伍人数*队伍中最低能力值不小于\(x\),求能构造的最大队伍数. 题解:大水题,排个序,倒着模拟就行了. 代码: int t; int n,x; ll a[N]; int ans; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; while(t--){ cin>>n>>x; ans=0; for(int i=1;i<=n;++…
题意:有一长度为\(n\)的序列,问是否能找到\(a_{i}<a_{j},a_{j}>a_{k},(i<j<k)\),如果满足,输出其位置. 题解:直接暴力两头找即可,最坏复杂度:\(O(n^2)\). 代码: int t; int n; int a[N]; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; while(t--){ cin>>n; for(int i=1;i<=n;…
D. Credit Card Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are dep…
这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int m,n,k,t; ]; ],y[],z[]; ]; int check(int v){ memset(sum,,sizeof(sum)); ;i<=k;++i) if(z[i]>v) ++sum[x[i]],--sum[y[i]+]; ; ;i…
题意:给你一串长度为\(n\)的序列,有的位置被锁上了,你可以对没锁的位置上的元素任意排序,使得最后一个\(\le0\)的前缀和的位置最小,求重新排序后的序列. 题解:贪心,将所有能动的位置从大到小排个序就行了. 代码: struct misaka{ int a; int loc; }e[N]; int t; int n; int main() { //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); t=read(); while(t--)…