Gym
来源:互联网 发布:sql 不等于 编辑:程序博客网 时间:2024/05/20 06:51
题意:
A是固定出的, Rock for the first Xrounds, Paper for the next Yrounds, andScissors for the last Zrounds.,加起来为n,每个大于等于0.
给出B的出拳,问怎么赢:
思路:
直接枚举的话需要三段0~i,i~j,j~n三重有超时风险。这里预处理,把三种出法的n次情况全部存在数组里。
然后最后判断r[i]+p[j]-p[i]+s[n]-s[j] > 0即可。p[j]减去超重的p[i]得到二段,s[n]减去s[j]得到第三段
#include <bits/stdc++.h>using namespace std;const int maxn = 1000 + 10;string str;int r[maxn], s[maxn], p[maxn];int n;int main(){// freopen("in.txt","r",stdin);int T;cin>>T;while (T--){cin>>n;cin>>str;for (int i=1; i<=n; ++i){r[i] = r[i-1]+(str[i-1]=='R' ? 0 : (str[i-1]=='S' ? 1 : -1));s[i] = s[i-1]+(str[i-1]=='S' ? 0 : (str[i-1]=='P' ? 1 : -1));p[i] = p[i-1]+(str[i-1]=='P' ? 0 : (str[i-1]=='R' ? 1 : -1));}int ans = 0;for (int i=0; i<=n; ++i)for (int j=i; j<=n; ++j)if (r[i]+p[j]-p[i]+s[n]-s[j] > 0)ans++;cout<<ans<<endl;}return 0;}
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- 深入理解JVM-类加载
- 为什么JDK源码中,无限循环大多使用for(;;)而不是while(true)?
- POJ 1815 Friendship(字典序最小最小割)
- 第一章动态网页开发基础
- 活动调度
- Gym
- RabbitMQ使用理解
- webpack配置
- 二分贪心练习题-V22
- 蒟蒻DP专题训练1--HDU2955
- [Leetcode] #322 Coin Change (DP)
- 栈和队列
- Javascript面向对象(九)——类继承
- 关于Form_Load和Public Form()那些事