当前位置:网站首页>[atcoder2305] declining (game)
[atcoder2305] declining (game)
2022-06-11 07:37:00 【CaptainHarryChen】
The question
It's on the blackboard n Number , Their greatest common divisor is 1. therefore A and B Decided to play a game , Two people operate in turn ,A First of all .
Choose one of the numbers on the blackboard that is not less than 2 Number of numbers , Subtract... From this number 1, And then for this n Number , Divided by their greatest common divisor .
When one cannot operate, he loses . If you want to get ahead, you have to win .
Answer key
Define the State 1: There are odd and even numbers , At least one odd number
Define the State 2: There are even numbers , And the number of odd numbers ≥2
Define the State 3: There are even numbers , Odd one
All numbers are 1, It is a state of inevitable failure , Belong to the State 2
state 2, No matter which number operation you choose ,gcd Are not even numbers , After the operation , Even numbers -1, Can only be transferred to state 1
And state 1 Ensure that it can be switched to the state after operation 2, So state 2 It is a state of inevitable failure
state 3, If even operation is selected , Transition to state 2, You will lose . Choose the odd number , Continue to solve recursively .
Code
#include<cstdio> #include<algorithm> using namespace std; const int MAXN=100005; int n,A[MAXN]; bool solve() {
if(n==1) return false; int cnt[2]={
0,0}; for(int i=1;i<=n;i++) cnt[A[i]&1]++; if(cnt[0]&1) return true; if((cnt[0]&1)==0&&cnt[1]>=2) return false; int pos=-1; for(int i=1;i<=n&&pos==-1;i++) if(A[i]&1) pos=i; if(A[pos]==1) {
int sum=0; for(int i=1;i<=n;i++) sum^=(A[i]-1)&1; return sum; } A[pos]--; int g=A[1]; for(int i=2;i<=n;i++) g=__gcd(g,A[i]); for(int i=1;i<=n;i++) A[i]/=g; return solve()^1; } int main() {
scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&A[i]); if(solve()) puts("First"); else puts("Second"); return 0; } 边栏推荐
- 2022 low voltage electrician operation certificate test question simulation test platform operation
- Cartland number application
- C language Yanghui triangle code
- What exactly is PMP?
- .NET C#基础(6):命名空间 - 有名字的作用域
- 【AtCoder1981】Shorten Diameter(图论思维)
- [Oracle database] mammy tutorial day02 use of database management tool sqlplus
- [STL source code analysis] summary notes (5): a good helper for understanding iterators --list
- [STL source code analysis] summary notes (10): hashtable exploration
- [analysis of STL source code] summary note (4): behind the scenes hero allocator
猜你喜欢

学 SQL 必须了解的10个高级概念

2022 melting welding and thermal cutting exam exercises and answers
![[STL source code analysis] summary notes (7): ingenious deque](/img/da/8ec42bfdbbf1b5bd1c2e396c2213e2.jpg)
[STL source code analysis] summary notes (7): ingenious deque

After 4 years of naked resignation from the test, the test post of 15K interview was rubbed on the ground, and the result made me collapse and cry

2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings

You got 8K in the 3-year function test, but you were actually pretending to work hard

@Jsonproperty annotation

RTMP protocol

【CodeForces1019E】Raining season(边分治+斜率优化)

Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies
随机推荐
Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...
【AtCoder2387】+/- Rectangle
gaussDB for redis和 redis的区别?
2022.5.30-6.5 AI行业周刊(第100期):三年时光
[STL source code analysis] summary notes (1): Opening
Seata的几种事务模式
[analysis of STL source code] summary notes (3): vector introduction
黑群晖DSM7.0.1物理机安装教程
JVM Learning record (7) - - class Loading Process and parent delegation Model
QT table display data
Pat class A by category
QObject usage skills -- control function class
远程办公经验 | 社区征文
@Jsonproperty annotation
Compound RateModel合约解析
Directrix of ellipse
Summary of classic interview questions
C language inherits memory management mechanism (unfinished)
R language Parallel Computing practice tutorial
Djikstra solves the shortest circuit with negative weight