40求助!!!
查看原帖
40求助!!!
1152154
Chinami_Nagisa楼主2024/8/18 10:51

2,4,5,6,7,10全WA

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int T,p;
int x,y;
ostringstream oss;
short f[10005][10005];
short judge(int a,int b,int turn)
{
    if(f[a][b]) return f[a][b];
    if(a==0) return 1;
    if(b==0) return 2;
    if(a==x&&b==y&&turn!=1) return 3;
    int sum=a+b;
    if(turn%2==0) f[a][b]=judge(a,sum%p,turn+1);
    else f[a][b]=judge(sum%p,b,turn+1);
    return f[a][b];
}
int main(){
    cin>>T>>p;
    for(int i=0;i<T;i++)
    {
        cin>>x>>y;
        switch(judge(x,y,1))
        {
            case 1:oss<<1<<endl;break;
            case 2:oss<<2<<endl;break;
            case 3:oss<<"error"<<endl;break;
            default:break;
        }
    }
    cout<<oss.str();
}
2024/8/18 10:51
加载中...