AtCoder Grand Contest 010 D - Decrementing
题目描述
有n个整数,其中第i个数为Ai。这些数字的gcd为1。两人轮流操作,每次操作把一个大于1的数减1,并把所有数除以所有数的最大公约数,最后无法操作者输,求是否先手必胜。
如果当前的sum为偶数,那么减一之后sum变为奇数,gcd必为奇数,而任意数除一个奇数后奇偶性不变,故这步走完后sum必然为奇数。
如果当前的sum为奇数,减一之后sum变为偶数,如果当前全为偶数,那么除完gcd后奇偶不一定,否则sum依然为偶数。
当局面全为1的时候先手必败,此时的奇偶为$n%2$,考虑先手怎样控制局面取得胜利。
假设先手的局面$sum\%2!=n\%2$,那么先手一定必胜,后手改变局面的唯一机会是使减完后gcd为2的倍数,则n个数都%2后必须只有一个1,先手只要每回把一个0变成1后手就无法翻盘。
那如果$sum\%2=n\%2$,如果满足n个数%2后只有一个1且先手必须要把1变0先手才可能赢,否则必败。
模拟一下过程,gcd为2的倍数的次数最多log次。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int a[];
ll sum=;
void print(int x)
{
if(!x)puts("First");
else puts("Second");
}
int gcd(int x,int y)
{
if(!y)return x;
return gcd(y,x%y);
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);sum+=a[i];
}
int now=;
while()
{
if(n%!=sum%)return print(now),;
int id=;
for(int i=;i<=n;i++)
{
if(a[i]%==&&a[i]!=)
{
if(!id)id=i;
else return print(now^),;
}
}
if(!id)return print(now^),;
a[id]--;
int g=a[];for(int i=;i<=n;i++)g=gcd(g,a[i]);
sum=;
for(int i=;i<=n;i++)a[i]/=g,sum+=a[i];
now^=;
}
return ;
}
AtCoder Grand Contest 010 D - Decrementing的更多相关文章
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- Atcoder Grand Contest 010 C - Cleaning 树贪心(伪)
C - Cleaning 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_c Description There is a tree with ...
- Atcoder Grand Contest 010 B - Boxes 差分
B - Boxes 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_b Description There are N boxes arrang ...
- AtCoder Grand Contest 010 C:Cleaning
题目传送门:https://agc010.contest.atcoder.jp/tasks/agc010_c 题目翻译 给你一棵树,每个点有个权值,每次操作可以选择两个度数为\(1\)的结点,然后让这 ...
- AtCoder Grand Contest 010 F - Tree Game
题目传送门:https://agc010.contest.atcoder.jp/tasks/agc010_f 题目大意: 给定一棵树,每个节点上有\(a_i\)个石子,某个节点上有一个棋子,两人轮流操 ...
- AtCoder Grand Contest 010题解
传送门 \(A\) 判一下奇数的个数就行了 const int N=1e5+5; int a[N],n,res; int main(){ scanf("%d",&n); f ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
随机推荐
- WPF制作带明细的环形图表
效果 明细用Popup实现的,录gif时,Popup显示不出来,不知道为什么,所以静态图凑合看吧 大体思路 图表使用Arc+Popup实现 图表分为两部分,一是环形部分,一是标注的明细部分. 环形部分 ...
- 使用ajax方法实现form表单的提交
作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 写在前面的话 在使用form表单的时候,一旦点击提交触发submit ...
- Mvc_ActionResult返回值
//ViewResult 表示HTML的页面内容 //EmptyResult 表示空白的页面内容 //RedirectResult 表示定位到另外一个URL //JsonResult 表示可以运用到A ...
- for...else 小记
for ......: ...... else: ...... 在 for 循环中,若没有执行 break ,正常结束,则会执行 else 中的语句. 若执行了 break , 则 不会 执行 els ...
- Python-注册登陆-20
username = input('请输入你要注册的用户名:') password = input('请输入你要注册的密码:') with open('list_of_info',mode='w',e ...
- sql 语句的先后执行顺序
例:查询语句中select from where group by having order by的执行顺序 一般以为会按照逻辑思维执行,为: 查询中用到的关键词主要包含六个,并且他们的顺序依次为 ...
- 选择J2EE的SSH框架的理由
选择J2EE的SSH框架的理由 Struts2框架: Struts2框架的基本思想是采用MVC设计模式,即将应用设计成模型(Model).视图(View)和控制器(Control)三个部分:控制部分由 ...
- 单工程搭建springmvc+spring+mybatis(maven,idea)
单工程搭建springmvc+spring+mybatis(maven,idea) 1.pom.xml <properties> <project.build.sourceEncod ...
- 自己实现数据结构系列二---LinkedList
一.先上代码: 1.方式一: public class LinkedList<E> { //节点,用来存放数据:数据+下一个元素的引用 private class Node{ privat ...
- activiti engine.schema.update DB_SCHEMA_UPDATE_FALSE
engine.properties # engine propertiesengine.schema.update=trueengine.activate.jobexecutor=falseengin ...