Multiplication Game

本文介绍了一款名为“乘法游戏”的策略游戏,探讨了如何通过选择素因子来达成目标值N并赢得游戏的方法。文章提供了详细的算法实现,并通过实例说明了如何确定玩家的最优策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

5121: Multiplication Game

时间限制: 5 Sec   内存限制: 128 MB
提交: 165   解决: 35
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

Alice and Bob are in their class doing drills on multiplication and division. They quickly get bored and instead decide to play a game they invented.
The game starts with a target integer N≥2, and an integer M = 1. Alice and Bob take alternate turns. At each turn, the player chooses a prime divisor p of N, and multiply M by p. If the player’s move makes the value of M equal to the target N, the player wins. If M > N, the game is a tie.
Assuming that both players play optimally, who (if any) is going to win?

输入

The first line of input contains T (1≤T≤10000), the number of cases to follow. Each of the next T lines  describe a case. Each case is specified by N (2≤N≤231-1) followed by the name of the player making  the first turn. The name is either Alice or Bob.

输出

For each case, print the name of the winner (Alice or Bob) assuming optimal play, or tie if there is no winner.

样例输入

10
10 Alice
20 Bob
30 Alice
40 Bob
50 Alice
60 Bob
70 Alice
80 Bob
90 Alice
100 Bob

样例输出

Bob
Bob
tie
tie
Alice
tie
tie
tie
tie
Alice
题意:两个人玩游戏,有一个目标值N,现在从N的一个素因子中取出一个P,另M*P(初始时M=1),某个人另M==P则这个人胜。

分析:求一下N的素数的个数num,素数的种类a。
对num分奇偶讨论。

若为奇数(先手必胜):

后手会想办法多拿使得先手无法获胜。那么对于当前状态,先手一定拿素数个数最多的那一种素数,而后手则拿素数个数最小的那一种。这样直接模拟就可以了。

若为偶数(后手必胜):
只要判断一下,先手拿的次数,是不是比所有种类的素数中个数最小那个大,如果大一定tie,如果不大一定后手胜。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
#define mem(a,b) memset(a,b,sizeof(a))
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e6+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;

inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}

ll prime[MAX],vis[MAX],cot,a[MAX];
char s[10];

void primeall()
{
    int i;
    for(i=2;i<MAX;i++)
        if(vis[i]==0)
        {
            prime[++cot]=i;
            for(int j=i*2;j<MAX;j+=i)
                vis[j]=1;
        }
}
int main()
{
    int t,i,j;
    ll n,minn=INF,p,q=0,num=0;
    primeall();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        scanf("%s",s);

        minn=INF;
        q=0;
        num=0;

        for(i=1;prime[i]*prime[i]<=n;i++)
        {
            p=0;
            while(n%prime[i]==0)
            {
                n=n/prime[i];
                p++;
            }
            if(p)
            {
                num=num+p;
                q++;
                a[q]=p;
                minn=min(minn,p);
            }
        }
        if(n>1)
        {
            num++;
            q++;
            minn=min(minn,1LL);
            a[q]=1;
        }
        //printf("%d %d %d\n",num,p,q);
        if(num%2)
        {
            int t1,t2,flag=0;
            t1=num/2;
            t2=num/2+1;
            while(1)
            {
                sort(a+1,a+1+q);
                a[q]--;
                t1--;
                if(t1<0)
                    break;

                sort(a+1,a+1+q);
                a[1]--;
                if(a[1]<0)
                {
                    flag=1;
                    break;
                }
                t2--;
                if(t2<0)
                    break;
            }
            if(flag)
                printf("tie\n");
            else if(t1<0)
                printf("%s",s[0]=='A'?"Alice\n":"Bob\n");
            else if(t2<0)
                printf("%s",s[0]=='B'?"Alice\n":"Bob\n");
        }
        else
        {
            int t=num/2;
            if(t>minn)
                printf("tie\n");
            else
                printf("%s",s[0]=='B'?"Alice\n":"Bob\n");
        }
    }
    return 0;
}

内容概要:《中文大模型基准测评2025年上半年报告》由SuperCLUE团队发布,详细评估了2025年上半年中文大模型的发展状况。报告涵盖了大模型的关键进展、国内外大模型全景图及差距、专项测评基准介绍等。通过SuperCLUE基准,对45个国内外代表性大模型进行了六大任务(数学推理、科学推理、代码生成、智能体Agent、精确指令遵循、幻觉控制)的综合测评。结果显示,海外模型如o3、o4-mini(high)在推理任务上表现突出,而国内模型如Doubao-Seed-1.6-thinking-250715在智能体Agent和幻觉控制任务上表现出色。此外,报告还分析了模型性价比、效能区间分布,并对代表性模型如Doubao-Seed-1.6-thinking-250715、DeepSeek-R1-0528、GLM-4.5等进行了详细介绍。整体来看,国内大模型在特定任务上已接近国际顶尖水平,但在综合推理能力上仍有提升空间。 适用人群:对大模型技术感兴趣的科研人员、工程师、产品经理及投资者。 使用场景及目标:①了解2025年上半年中文大模型的发展现状与趋势;②评估国内外大模型在不同任务上的表现差异;③为技术选型和性能优化提供参考依据。 其他说明:报告提供了详细的测评方法、评分标准及结果分析,确保评估的科学性和公正性。此外,SuperCLUE团队还发布了多个专项测评基准,涵盖多模态、文本、推理等多个领域,为业界提供全面的测评服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值