D. Deleting Divisors(博弈)

文章描述了一个在Codeforces平台上的编程竞赛问题,玩家爱丽丝和鲍勃轮流从一个正整数n开始减去非1和n的除数。爱丽丝先手,无法移动的玩家失败。题目要求判断在最优策略下,谁会获胜。给定测试用例展示了不同情况下(如n为奇数或偶数,n是否为质数等)的赢家。解决方案涉及到对n的奇偶性、因子的分析以及如何避免变为奇数的情况。
摘要由CSDN通过智能技术生成

Problem - D - Codeforces

爱丽丝和鲍勃在玩游戏。它们从一个正整数n开始,轮流对其进行操作。玩家每回合可以从n中减去一个不是1或n的除数。在他/她的回合中不能移动的玩家失败。爱丽丝总是先动。注意,他们在每个回合中减去当前数字的除数。你被要求找出如果两个玩家都发挥最佳,谁将赢得游戏。输入第一行包含一个整数t (1 < t < 104)——测试用例的数量。然后是测试用例。每个测试用例都包含一个整数n (1 <n < 109)——初始值。输出对于每个测试用例,如果Alice将赢得游戏,则输出“Alice”,如果Bob将赢得游戏,则输出“Bob”,如果双方都采用最佳玩法。

Example

input

Copy

4
1
4
12
69

output

Copy

Bob
Alice
Alice
Bob

请注意在第一个测试案例中,游戏立即结束,因为Alice无法移动。在第二个测试案例中,Alice可以减去2,使n= 2,那么Bob不能移动,所以Alice赢了。在第三个测试案例中,Alice可以减去3,使n =9。Bob唯一的动作是减去3,使n = 6。爱丽丝可以再减去3和n3。然后鲍勃不能动,所以爱丽丝赢了。

题解:
假如n为奇数

1.如果n为质数,那么A直接输

2.如果n不是质数,那么n可以分为两个奇数的乘积,a操作后,n一定是个偶数(并且奇数因子,一定不是2),b操作后,再减去一个奇数,n又变成奇数,所以b必不可能输

假如n为偶数

1.如果n有不为1的奇数因子,可以减去一个奇数因子,变成上述情况,A必赢

2.n无不为1的奇数因子,n的形式为2^k

为了不变成奇数情况每个人会减2 ^(k-1),所以看谁先变成2

k%2 B赢

k%2 == 0 A输

#include<iostream>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
int pri[200050];
int vis[200050];
int cnt = 0;
void solve()
{
	int n;
	scanf("%d",&n);
	if(n % 2)
	{
		printf("Bob\n");
		return ;
	}
	int k = 0;
	while(n%2 == 0)
	{
		n /= 2;
		k++;
	}
	if(n!=1)
	{
		cout <<"Alice\n";
	}
	else
	{
		if(k%2)
		{
			cout <<"Bob\n";
		}
		else
		{
			printf("Alice\n");
		}
	}
}
signed main() 
{
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	int t = 1;
    scanf("%d",&t);
	while (t--) 
	{
		solve();
	}
	return 0;
}

 

SELECT PIS.SHOW_FLT_DETAIL AS SHOW_FLT_DETAIL -- new , PIS.SHOW_AWB_DETAIL AS SHOW_AWB_DETAIL -- new , PIS.DISPLAY_AIRLINE_CODE AS CARRIER_CODE , DECODE(PIS.REVERT_FLOW,'N',PIS.FLOW_TYPE,DECODE(PIS.FLOW_TYPE,'I','E','I')) AS FLOW_TYPE , PIS.SHIP_TO_LOCATION AS SHIP_TO_LOCATION , PIS.INVOICE_SEQUENCE AS INVOICE_SEQUENCE , PFT.FLIGHT_DATE AS FLIGHT_DATE , PFT.FLIGHT_CARRIER_CODE AS FLIGHT_CARRIER_CODE , PFT.FLIGHT_SERIAL_NUMBER AS FLIGHT_SERIAL_NUMBER , PFT.FLOW_TYPE AS AIRCRAFT_FLOW , FAST.AIRCRAFT_SERVICE_TYPE AS AIRCRAFT_SERVICE_TYPE , PPT.AWB_NUMBER AS AWB_NUMBER , PPT.WEIGHT AS WEIGHT , PPT.CARGO_HANDLING_OPERATOR AS CARGO_HANDLING_OPERATOR , PPT.SHIPMENT_PACKING_TYPE AS SHIPMENT_PACKING_TYPE , PPT.SHIPMENT_FLOW_TYPE AS SHIPMENT_FLOW_TYPE , PPT.SHIPMENT_BUILD_TYPE AS SHIPMENT_BUILD_TYPE , PPT.SHIPMENT_CARGO_TYPE AS SHIPMENT_CARGO_TYPE , PPT.REVENUE_TYPE AS REVENUE_TYPE , PFT.JV_FLIGHT_CARRIER_CODE AS JV_FLIGHT_CARRIER_CODE , PPT.PORT_TONNAGE_UID AS PORT_TONNAGE_UID , PPT.AWB_UID AS AWB_UID , PIS.INVOICE_SEPARATION_UID AS INVOICE_SEPARATION_UID , PFT.FLIGHT_TONNAGE_UID AS FLIGHT_TONNAGE_UID FROM PN_FLT_TONNAGES PFT , FZ_AIRLINES FA , PN_TONNAGE_FLT_PORTS PTFP , PN_PORT_TONNAGES PPT , FF_AIRCRAFT_SERVICE_TYPES FAST , SR_PN_INVOICE_SEPARATIONS PIS --new , SR_PN_INVOICE_SEP_DETAILS PISD--new , SR_PN_INV_SEP_PORT_TONNAGES PISPT --new WHERE PFT.FLIGHT_OPERATION_DATE >= trunc( CASE :rundate WHEN TO_DATE('01/01/1900', 'DD/MM/YYYY') THEN ADD_MONTHS(SYSDATE,-1) ELSE ADD_MONTHS(:rundate,-1) END, 'MON') AND PFT.FLIGHT_OPERATION_DATE < trunc( CASE :rundate WHEN TO_DATE('01/01/1900', 'DD/MM/YYYY') THEN TRUNC(SYSDATE) ELSE TRUNC(:rundate) END, 'MON') AND PFT.TYPE IN ('C', 'F') AND PFT.RECORD_TYPE = 'M' AND (PFT.TERMINAL_OPERATOR NOT IN ('X', 'A') OR (PFT.TERMINAL_OPERATOR <> 'X' AND FA.CARRIER_CODE IN (SELECT * FROM SPECIAL_HANDLING_AIRLINE) AND PPT.REVENUE_TYPE IN (SELECT * FROM SPECIAL_REVENUE_TYPE) AND PPT.SHIPMENT_FLOW_TYPE IN (SELECT * FROM SPECIAL_SHIPMENT_FLOW_TYPE) AND PFT.FLIGHT_OPERATION_DATE >= (select EFF_DATE from SPECIAL_HANDLING_EFF_DATE) )) AND PFT.DELETING_DATETIME IS NULL AND FA.AIRLINE_UID = PFT.AIRLINE_UID AND FA.DELETING_DATETIME IS NULL AND PTFP.FLIGHT_TONNAGE_UID = PFT.FLIGHT_TONNAGE_UID AND PTFP.RECORD_TYPE = 'M' AND PTFP.DELETING_DATETIME IS NULL AND PPT.TONNAGE_FLIGHT_PORT_UID (+)= PTFP.TONNAGE_FLIGHT_PORT_UID AND PPT.RECORD_TYPE (+)= 'M' AND PPT.DISCREPANCY_TYPE (+)= 'NONE' AND PPT.ADJUSTMENT_INC_FLAG (+)= 'Y' AND PPT.DELETING_DATETIME (+) IS NULL AND FAST.AIRCRAFT_SERVICE_TYPE_UID = PFT.AIRCRAFT_SERVICE_TYPE_UID AND FAST.DELETING_DATETIME IS NULL AND PIS.TEMPORAL_NAME = TO_CHAR((CASE :rundate --new WHEN TO_DATE('01/01/1900', 'DD/MM/YYYY') THEN TRUNC(SYSDATE) ELSE TRUNC(:rundate) END ), 'YYYYMM') || '00' AND PIS.INVOICE_SEPARATION_UID = PISD.INVOICE_SEPARATION_UID --new AND PISD.INVOICE_SEP_DETAIL_UID = PISPT.INVOICE_SEP_DETAIL_UID --new AND PISPT.PORT_TONNAGE_UID = PPT.PORT_TONNAGE_UID --new AND PIS.PRINT_SUPPORTING_DOC = 'Y';上面是oracle的写法,请转成spark SQL的写法。
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值