srm 558 backup 1 DIV 2

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、Unity、Cocos2d等,以及AI音视频处理技术的应用,如视频分割、语义识别、语音识别等。通过实例解析,为开发者提供了一站式的技术解决方案。

Problem Statement

 Cat and Rabbit are going to play the following game.

There are some tiles in a row. Each of the tiles is colored white or black. You are given a stringtiles, describing the initial arrangement of tiles. The characters '.' and '#' represent a white tile and a black tile, respectively.

Cat and Rabbit take alternating turns. Cat plays first. In each turn, the following actions must be performed:
  • First, the player must select a black tile and step on it.
  • Then, the player must make some steps (as many as they want, but at least one). In each step, the player must select an adjacent white tile, move to that tile, and change its color to black.
The animal who is unable to take a valid turn loses the game. Return the string "Cat" if Cat will win, "Rabbit" if Rabbit will win, assuming both animals play optimally.

Definition

 
Class:CatAndRabbit
Method:getWinner
Parameters:string
Returns:string
Method signature:string getWinner(string tiles)
(be sure your method is public)
 
 

Constraints

-tiles will contain between 1 and 50 characters, inclusive.
-Each character in tiles will be '.' or '#'.

Examples

0) 
 
"#.."
Returns: "Cat"
In the first turn, Cat will select the leftmost tile and can move to the right twice. Then Rabbit has no legal move and loses.
1) 
 
".#."
Returns: "Rabbit"
In the first turn, Cat must select the middle tile. Then, Cat can decide whether to step to the left or to the right. In the second turn, Rabbit will select the middle tile and then step in the opposite direction.
2) 
 
"###"
Returns: "Rabbit"
Cat has no legal move at the beginning of the game.
3) 
 
"#..##.#"
Returns: "Cat"
 
4) 
 
"..."
Returns: "Rabbit"
5) 
 
"###...####....###...####...."
Returns: "Rabbit"

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.     



#include<math.h>
#include<vector>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>




using namespace std;


#define FOR(I,A,B) for (int I=int(A);I<int(B);I++)
#define PUSH(X,N,n) {FOR(q,0,N){X.push_back(n);}}
#define  ll _int64


template<class T>  T max (T A, T B){if(A>B) return A; else return B;} 
template<class T>  T min (T A, T B){if(A<B) return A; else return B;} 


//#define ll long long
//typedef  __int64 ll


#define oo (1<<25)
#define SZ(x) (int)x.size()






#define MAX 100


string rabbit="Rabbit";
string cat="Cat";


class CatAndRabbit{
public:
string getWinner(string tiles)
{
int ok=0;
for(int q=0;q<SZ(tiles);q++)
if(tiles[q]=='#') ok=1;
if(!ok) return rabbit;

int i,j,ans=0;
for( i=0;i<SZ(tiles);)
{
if(tiles[i]=='#') i++;
else if(tiles[i]=='.')
{
int len=1;
for(int j=i+1;j<SZ(tiles);j++)
{
if(tiles[j]=='.') len++;
else break;
}
i=j;
if(len) ans^=len;
}
}
if(ans) return cat;
else 
return rabbit;
}
};

前面讲的错了,看了别人的我突然发现自己弱了。。。。。。。

比如一个数据 2 4  6   好像很难发现到底谁先走完。

后来我想到吧他分解  2 2+2  2+4  可是这样并没什么用。因为 你分解成2+2 别人去3 就没办法了。

可是如果分解成2进制 0010   0100 0110 就可以发现。无论怎么改变其中的一个数,总是可以出现互补的。(就是各个位都有偶数个1)

第一步 0001 0100 0110

那么第2步很容易想到  0001 01000101

也就是无论第一个怎么走他都摆脱不了输的命啊


内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值