60分,其他4个TLE了,求解
查看原帖
60分,其他4个TLE了,求解
1290314
hdh1103楼主2024/3/14 01:15
#include <iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include <math.h>
#include <set>
#include <map>
using namespace std;
int a[11]= {0};
int x;
int n,g,f;
int main()
{
    // int n,g;
    cin>>n>>g;
    a[n]=n;

    for(int j=1;;j++)
    {
        //最后一只猫给自己了j条鱼
        a[n] = j;
        //a[n]待分配的鱼
        x = j*n+g;
        //  cout<<"x:"<<x<<endl;
        for(int k=n-1; k>=1; k--)
        {
            //a[k-1]待分配的鱼
            x = x/(n-1) +x+g;
            f = x%n;
            //  cout<<x;
            //验证是否满足
            if(f!=g)
            {
                break;
            }

            if(k==1)
            {
                cout<<x;
                return 0;
            }


        }
    }






    return 0;
}

2024/3/14 01:15
加载中...