数论:
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
2
2 3
output
Alice
input
2
5 3
output
Alice
input
3
5 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[],c[];
int main()
{
cin>>n;
int cnt=,flag=;
for(int i=;i<n;i++) cin>>a[i];
for(int i=;i<n;i++){
if(a[i]==i) cnt++;
else if(a[a[i]]==i) flag=;
}
if(cnt==n) cout<<cnt<<endl;
else if(flag) cout<<cnt+<<endl;
else cout<<cnt+<<endl;
return ;
}
贪心 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
3
3 4 5
30 17
output
6
input
3
5 6 7
1000 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[],a,b;
int main()
{
cin>>n;
for(int i=;i<n;i++) cin>>num[i];
cin>>a>>b;
sort(num,num+n);
int len=unique(num,num+n)-num;
int ans=,tmp;
while(a>b){
tmp=a-;
for(int i=;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 ;
}

Codeforces Round #201 (Div. 2)C,E的更多相关文章

  1. Codeforces Round #201 (Div. 2) - C. Alice and Bob

    题目链接:http://codeforces.com/contest/347/problem/C 题意是给你一个数n,然后n个数,这些数互不相同.每次可以取两个数x和y,然后可以得到|x - y|这个 ...

  2. codeforce Codeforces Round #201 (Div. 2)

    cf 上的一道好题:  首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是  所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...

  3. Codeforces Round #201 (Div. 2). E--Number Transformation II(贪心)

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description You ar ...

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

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

  5. Codeforces Round #633 (Div. 2)

    Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. django 连接mysql报错

    原因: 问题1. 即从mysql5.7版本之后,默认采用了caching_sha2_password验证方式. 问题2.  然后在执行 python manage.py makemigrations依 ...

  2. 吴恩达j机器学习之过拟合

    五.编程作业: 见:https://www.cnblogs.com/tommyngx/p/9933803.html

  3. 微软的XML可视化编辑器:XML Notepad 2007

    最近项目需要定义xml协议格式,编写xml文件比较多,之前使用xml spy工具,但是不够轻量级. 微软提供的xml nodepad 2007很实用,希望能给大家提供帮助. 运行后的界面 下载地址:h ...

  4. Python中的print

    Python 3.X的print 在Python 3.X中,print是一个内置函数,完整的声明形式如下: print([object, ...][, sep=' '][, end='\n'][, f ...

  5. Bad Cowtractors(最大生成树)

      Description Bessie has been hired to build a cheap internet network among Farmer John's N (2 <= ...

  6. 事后分析报告(M2阶段)

    我们的项目是自选项目,一款名为备忘录锁屏MemoryDebris的软件. 在第二轮的迭代中,由于各科的大作业都集中在这一段时间,所以这段时间各个组员间的负担都比较大,但是在大家共同努力,最终我们还是交 ...

  7. Calculation PartⅡ

    GitHub/object-oriented 误删内容--周末修复

  8. DAY2敏捷冲刺

    站立式会议 工作安排 (1)服务器配置 (2)数据库连接 (3)页面创意 燃尽图 代码提交记录 感想 林一心:centos配置服务器真的算是一个不小的坑,目前数据库配置清楚,脚本部署好明天测试交互,还 ...

  9. 在用js拼接html时,给元素加不上事件的问题

    问题描述:有时,发起ajax请求成功后,需要用js去拼接一小段html字符串,然后给某些元素添加事件时,事件总是加不上. 解决办法:在success 回调函数内,给元素添加事件绑定. 代码如下: $. ...

  10. iOS- UIPickerView餐厅点餐系统

    在餐厅里的点餐系统的核心控件就是UIPickerView 今天晚上在整理以前的项目笔记时,特意把UIPickerView单独拿出来,做了一个简陋的点餐道具. 因为没有素材图片,所有大家将就看看吧 0. ...