首页 > 其他 > 详细

Educational Codeforces Round 91 (Rated for Div. 2) B. Universal Solution (贪心)

时间:2020-07-16 16:05:32      阅读:41      评论:0      收藏:0      [点我收藏+]

技术分享图片

  • 题意:石头剪刀布,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>>t;
      	 while(t--){
      	 	cin>>s;
      	 	mp.clear();
      	 	for(int i=0;i<s.size();++i){
      	 		if(s[i]==‘R‘) mp[‘r‘]++;
      	 		else if(s[i]==‘S‘) mp[‘s‘]++;
      	 		else mp[‘p‘]++;
      	 	}
      	 	int mx=0;
      	 	for(auto w:mp) mx=max(mx,w.se);
      	 	if(mp[‘r‘]==mx){
      	 		for(int i=0;i<s.size();++i){
      	 			cout<<"P";
      	 		}
      	 	}
      	 	else if(mp[‘s‘]==mx){
      	 		for(int i=0;i<s.size();++i){
      	 			cout<<"R";
      	 		}
      	 	}
      	 	else{
      	 		for(int i=0;i<s.size();++i){
      	 			cout<<"S";
      	 		}
      	 	}
      	 	cout<<endl;
      	 }
     
        return 0;
    }
    

Educational Codeforces Round 91 (Rated for Div. 2) B. Universal Solution (贪心)

原文:https://www.cnblogs.com/lr599909928/p/13322080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!