数论:
C. Alice and Bob
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).

If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

Input

The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

Output

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

Examples
input
22 3

output
Alice

input
25 3

output
Alice

input
35 6 7

output
Bob

Note

Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

题意:

两人游戏,最初给出n个数集合当轮到一个人时他要从中选两个数x,y,使得|x-y|不在集合中,然后把|x-y|加进集合。当没法挑选时输。Alice先Bob后。

代码:

//并非1~n的每一个数都能得到。得到的数只可能是最初的n个数的最大公约束数的倍数。
//因为不断地作减法可以看成求gcd的运算,最终减到的最小的数就是他们的gcd.
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],c[100005];
int main()
{cin>>n;int cnt=0,flag=0;for(int i=0;i<n;i++) cin>>a[i];for(int i=0;i<n;i++){if(a[i]==i) cnt++;else if(a[a[i]]==i) flag=1;}if(cnt==n) cout<<cnt<<endl;else if(flag) cout<<cnt+2<<endl;else cout<<cnt+1<<endl;return 0;
}

贪心 dp
E. Number Transformation II
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can perform the following moves:

  • subtract 1 from the current a;
  • subtract a mod xi (1 ≤ i ≤ n) from the current a.

Operation a mod xi means taking the remainder after division of number a by number xi.

Now you want to know the minimum number of moves needed to transform a into b.

Input

The first line contains a single integer n (1 ≤  n ≤ 105). The second line contains n space-separated integers x1, x2, ..., xn (2 ≤  xi ≤ 109). The third line contains two integers a and b (0  ≤ b ≤  a ≤ 109, a - b ≤ 106).

Output

Print a single integer — the required minimum number of moves needed to transform number a into number b.

Examples
input
33 4 530 17

output
6

input
35 6 71000 200

output
206

题意:

给出n个数x[1...n]和a,b问从a变到b的最少步数。a每次可以减1或者减a%x[i]。

代码:

//每次减去1和a%x[i](0<=i<=n-1)中大的那个,直到a<=b。
//剪枝:x数组去重;显然如果a-a%x[i]<b,x[i]就可以去掉,下次不用计算他了
#include<bits/stdc++.h>
using namespace std;
int n,num[100005],a,b;
int main()
{cin>>n;for(int i=0;i<n;i++) cin>>num[i];cin>>a>>b;sort(num,num+n);int len=unique(num,num+n)-num;int ans=0,tmp;while(a>b){tmp=a-1;for(int i=0;i<len;i++){int tmpp=a-a%num[i];if(tmpp<b) num[i--]=num[--len];else tmp=min(tmp,tmpp);}a=tmp;ans++;}cout<<ans<<endl;return 0;
}

转载于:https://www.cnblogs.com/--ZHIYUAN/p/6561790.html

Codeforces Round #201 (Div. 2)C,E相关推荐

  1. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  2. Codeforces Round #702 (Div. 3)A-G题解

    Codeforces Round #702 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1490 这场F读错题意白给一发,G二分的if(dp[mi ...

  3. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  4. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  5. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  6. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  7. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  8. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  9. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

最新文章

  1. 后盾网lavarel视频项目---lavarel使用模型进行增删改查操作
  2. sqoop 1.4.4-cdh5.1.2快速入门
  3. python cgi打印html代码
  4. 秦九韶算法matlab程序,数值分析matlab程序实例.doc
  5. 【R】语言第二课----- 变量的使用方法
  6. mysql表设计要注意什么?
  7. 怎么解决python遇到问题_新手常见Python错误及异常解决处理方案
  8. 为下半年圣诞节提前准备素材模板,可临摹psd分层模板!
  9. 如歌将两个数组合并_将数组数据拆分后再合并,作为字典的键,实现多条件数据汇总...
  10. redis stream持久化_带你彻底理解 Redis 持久化
  11. 强化学习进阶【逆强化学习】
  12. LINQToSQL中如何更好的手动设置导航字段,并返回实名类型而不是匿名类型
  13. 5G终端难占用锚点小区导致无法驻留5G
  14. Java List 集合取 交集、并集、差集、补集 Java集合取交集、Java集合并集
  15. 零基础Python爬虫实现(百度贴吧)
  16. JavaScript基础(五)——ES2015(ES6)基础语法
  17. adb基础命令学习随笔
  18. S@Kura的PHP进阶之路(二)
  19. html5 canvas 椭圆,html5中怎么利用Canvas绘制椭圆
  20. 虚拟中3DMax2018打开报错

热门文章

  1. el-select 结合 el-checkBox 实现下拉全选+多选功能;el-select下拉框全选功能;
  2. 前端学习(3042):vue+element今日头条管理-用户退出
  3. 前端学习(2985):一文理解数据劫持3观察者模式
  4. [html] 如何禁止html页面缓存?
  5. [vue] 说下你的vue项目的目录结构,如果是大型项目你该怎么划分结构和划分组件呢?
  6. [css] 使用纯css来创建一个滑块
  7. 前端学习(82):按内容进行分类
  8. 前端学习(3):vs code编辑器
  9. java学习(35):巩固练习
  10. python .center用法_Python Pandas Series.str.center()用法及代码示例