zoukankan      html  css  js  c++  java
  • Gym


    题意:

    A是固定出的, Rock for the first X​rounds, Paper for the next Y​rounds, andScissors for the last Z​rounds.,加起来为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;
    }


  • 相关阅读:
    浏览器的同源策略及跨域解决方案
    前端开发工具系列
    初始Vue
    form表单组件
    聚合和分组F,Q和事物,cookie,session
    js循环找id
    div模拟textarea文本域轻松实现高度自适应
    prototype原型
    Javascript异步编程方法
    js中map、filter用法
  • 原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256610.html
Copyright © 2011-2022 走看看