Codeforces Round #201 (Div. 2)C,E

数论:
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[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
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[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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/417135.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

c语言非法字符有哪些,98行的四则计算器.(支持括号)加入了非法字符的检测

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼#include#include#includedouble s2n(char **tem)//字符串转为数字{double tem_satof(*tem);while(isdigit(*(*tem))||**tem.);return tem_s;}bool error_found(const char *now)//检测错误的输入{while(*now!\0&&isdigit(…

前端学习(2325):angular之数据修改

app.component.html <div style"text-align:center"><h1>welcome to {{title}}</h1><div style"color:#f00000">我是歌谣</div><div>{{name}}</div> </div>app.component.ts import { Component } from…

Java调用WCF

到网上下载axis包&#xff0c;执行以下命令&#xff0c;set Axis_Libaxis-1_4\libset Java_Cmdjava -Djava.ext.dirs%Axis_Lib%set Output_Path.set Packagewcf%Java_Cmd% org.apache.axis.wsdl.WSDL2Java http://localhost:8000/WebWcf/GetAccountService.svc?wsdl -o%Output…

静态方法和类方法

1. 类方法 是类对象所拥有的方法&#xff0c;需要用修饰器classmethod来标识其为类方法&#xff0c;对于类方法&#xff0c;第一个参数必须是类对象&#xff0c;一般以cls作为第一个参数&#xff08;当然可以用其他名称的变量作为其第一个参数&#xff0c;但是大部分人都习惯以…

c语言角谷定理递归,【C++】(递归+非递归)卖鸭子及角谷定理+递归模型+递归树...

ps&#xff1a;全文中如果有任何错误您看到并能指出来的话(尤其是递归树)感激不尽XDDDD每个问题包含&#xff1a;(1)题目描述(2)递归解决代码(3)非递归解决代码(4)递归模型(5)递归树(6)运行结果截图一、卖鸭子问题1.题目描述一个人赶着鸭子去每个村庄卖&#xff0c;每经过一个村…

前端学习(2325):angular之添加新组件

app.component.html <div style"text-align:center"><h1>welcome to {{title}}</h1><div style"color:#f00000">我是歌谣</div><div>{{name}}</div> </div>app.component.ts import { Component } from…

【批处理】shift用法举例

1 echo off 2 set sum03 call :sub sum 1 2 3 44 echo sum%sum%5 pause6 7 :sub8 set /a %1%1%29 shift /2 10 if not "%2""" goto sub 11 goto :eof View Code转载于:https://www.cnblogs.com/xiongjiawei/p/6564958.html

C语言给出任意4个数算24点,讨论24点算法。

讨论24点算法。24点是扑克牌游戏 玩法是&#xff1a;从一副扑克的A到10里随意抽出4张牌用‘加’’减‘‘乘’‘除’四个符号算出4个数是否等于24&#xff0c;是的话成功&#xff0c;否的话失败&#xff1b;我用的是穷举法&#xff01;(源码有点长)就是穷举出所有可能的算术式&a…

前端学习(2326):angular之用户输入数据

test1.component.html <p class"p1">test1 works!</p> <div (click)"clickDemo()" >我是div1的内容</div> <input (keyup)"onkey($event)" type"text">test1.component.spec.ts import { ComponentF…

项目被os x占用

xattr -d com.apple.FinderInfo 空格后拖入项目回车就行了转载于:https://www.cnblogs.com/EnzoDin/p/6565549.html

c语言编写pdf,编写并运行C语言程序.pdf

VC6.0 使用教程 &#xff1a;从 VC6.0安装到运行和调试 【详解版】VisualC6.0 简称 VC或者 VC6.0 &#xff0c;是微软推出的一款 C和 C编译器 &#xff0c;具有强大的可视化开发功能和调试功能。VC6.0是使用最多的版本 &#xff0c;非常经典 &#xff0c;很多高校将 VC6.0作为C…

前端学习(2327):angular之双向绑定

test1.component.html <p class"p1">test1 works!</p> <div (click)"clickDemo()" >我是div1的内容</div> <input (keyup)"onkey($event)" type"text"><form action"" #heroFrom"n…

android开发入门

下载ADT-17.0.0.zip打开eclipse->help->install new software将ADT-17.0.0.zip拖动到框中&#xff0c;去掉下面第一个和第四个复选框&#xff08;需要连接网络获取新版本信息&#xff09;下一步……ADT中下载各个版本的android系统模拟包安装好后重启File->New->An…

mysql主键异常(冲突)

抛出异常&#xff1a;detached entity passed to persist: org.booking.entity.Admin 这个时候你做session.save()添加&#xff0c;entityManager.persist()添加也好&#xff0c;你都不能添加成功。 解决方法&#xff1a;因为mysql有自增长的属性&#xff0c;并且实体也设置自增…

c语言去除图像斑点,武汉理工-图像检测与处理技术-实验报告.doc

学生学号 0121304940834实验课成绩学 生 实 验 报 告 书实验课程名称图像检测与处理技术开 课 学 院机电工程学院指导教师姓名刘清元学 生 姓 名李勇学生专业班级测控13042015--2016学年第2学期实验教学管理基本规范实验是培养学生动手能力、分析解决问题能力的重要环节&#x…

前端学习(2328):angular之模板

test2.component.html <p>test2 works!</p> <a href"{{url}}">百度</a> <a [href]"url">百度2</a>test1.component.spec.ts import { ComponentFixture, TestBed } from angular/core/testing;import { Test2Compon…

Struts2学习总结(完整版)

Struts2学习总结&#xff08;完整版&#xff09; 一、搭建struts2环境 1、jar包的导入 主要是到 解压其中的一个工程&#xff0c;得到里面lib下包含的jar包 把这里的所有的jar包拷贝到项目的 WEB-INF目录下的lib文件夹下面。 2、配置struts.xml文件 注意&#xff1a;必须要放在…

打开word时出现“在加载ThisDocument时出现错误”

有可能软件兼容性不行或者就是安装时没有安装正版软件&#xff0c;有些模块没有加载进去就无法打开文件现在有office 2007 建议保存的时候保存成97-03兼容模式