Atcoder 2373 Cookie Exchanges
Problem Statement
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
- Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
Constraints
- 1≤A,B,C≤109
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print -1 instead.
Sample Input 1
4 12 20
Sample Output 1
3
Initially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,
- After the first action, they have 16, 12 and 8.
- After the second action, they have 10, 12 and 14.
- After the third action, they have 13, 12 and 11.
Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.
Sample Input 2
14 14 14
Sample Output 2
-1
Sample Input 3
454 414 444
Sample Output 3
1
a==b==c的时候会死循环,其他情况暴力算就行了,因为每一次操作之后最大值-最小值会减半,所以不久就能到达终止条件。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int A,B,C,tot,a,b,c;
int main(){
scanf("%d%d%d",&A,&B,&C);
while(!((A&1)||(B&1)||(C&1))){
if(A==B&&B==C){
puts("-1");
return 0;
} tot++,a=(B+C)>>1,b=(A+C)>>1,c=(B+A)>>1;
A=a,B=b,C=c;
} printf("%d\n",tot);
return 0;
}
Atcoder 2373 Cookie Exchanges的更多相关文章
- Atcoder Grand-014 Writeup
A - Cookie Exchanges 题面 Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respec ...
- AtCoder Grand Contest 014
AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中 ...
- 【AtCoder】AGC014
AGC014 链接 A - Cookie Exchanges 发现两个数之间的差会逐渐缩小,所以只要不是三个数都相同,那么log次左右一定会得到答案 #include <bits/stdc++. ...
- AtCoder Grand Contest 014 题解
A - Cookie Exchanges 模拟 Problem Statement Takahashi, Aoki and Snuke love cookies. They have A, B and ...
- A@GC*014
A@GC*014 A Cookie Exchanges 卡时跑了1s就输出-1 每次操作会使三个数的极差缩小一半,所以最多\(\log\)次之后就会出现\(A=B=C\)的情况,可以直接判掉 B Un ...
- Python Web学习笔记之Cookie,Session,Token区别
一.Cookie,Session,Token简介 # 这三者都解决了HTTP协议无状态的问题 session ID or session token is a piece of data that i ...
- 超大 Cookie 拒绝服务攻击
有没有想过,如果网站的 Cookie 特别多特别大,会发生什么情况? 不多说,马上来试验一下: for (i = 0; i < 20; i++) document.cookie = i + '= ...
- IE10、IE11 User-Agent 导致的 ASP.Net 网站无法写入Cookie 问题
你是否遇到过当使用一个涉及到Cookie操作的网站或者管理系统时,IE 6.7.8.9下都跑的好好的,唯独到了IE10.11这些高版本浏览器就不行了?好吧,这个问题码农连续2天内遇到了2次.那么,我们 ...
- 解决cookie跨域访问
一.前言 随着项目模块越来越多,很多模块现在都是独立部署.模块之间的交流有时可能会通过cookie来完成.比如说门户和应用,分别部署在不同的机器或者web容器中,假如用户登陆之后会在浏览器客户端写入c ...
随机推荐
- touch-action css属性 滚动和缩放手势
CSS 属性 touch-action 用于指定某个给定的区域是否允许用户操作,以及如何响应用户操作(比如浏览器自带的划动,缩放等) 默认情况下,平移(滚动) 和 缩放手势由浏览器专门处理.该属性用于 ...
- javascript(函数式编程思考) ---> Map-Filter-quicksort-Collatz序列-Flodl-Flodr
let add = x=>x+1; //Map :: ( a -> b) -> [a] -> [b] let Map = function(f,arr){ //闭包存储累积对象 ...
- 洛谷 P2032 扫描
https://www.luogu.org/problemnew/show/P2032 为啥不用STL,多方便. 定义一个大根堆,里边放一对数,这个数的大小和位置. 我们对于每次查询,判断首元素的位置 ...
- 分享一个C++与Python开发的中小型通用游戏服务端框架(跨平台,开源,适合MMORPG游戏)
在开发一款游戏项目时,在立项时我们往往会考虑或者纠结很多,比如: 1,对于开发来说:服务端和客户端应该选择什么语言?用什么协议通信才更效率?协议后期如何维护?Socket是用长连接还是短连接?TCP还 ...
- OJ 大整数减法
描述 求两个大的正整数相减的差. 输入 共2行,第1行是被减数a,第2行是减数b(a > b).每个大整数不超过200位,不会有多余的前导零. 输出 一行,即所求的差. 样例输入 9999999 ...
- Codeforces Round #477滚粗记&&祭第一次div2场
4.29 - 23:58:现在似乎在ST的样子……先等一波 Day4.29 prescript : 难得遇上一场9:00开始的div2,看了看大家都打,索性也当一回神仙吧. 晚上出去吃饭,匆匆赶回家, ...
- (15)zabbix ODBC数据库监控
概述 ODBC监控对应于Zabbix Web管理端中的Database monitor监控项类型. ODBC是用于访问数据库管理系统(DBMS)的C语言中间件API.ODBC由Microsoft开发, ...
- (4)zabbix监控第一台服务器
2. zabbix监控服务器 创建主机,选择模板以及录入基本信息,过一分钟左右,就可以看到cpu.内存.硬盘等等使用情况.本节以图文为主.by the way, zabbix中文翻译很烂,config ...
- Python赋值运算及流程控制
1. 内置函数 1> len:统计元素长度 str1 = 'wonderful' print(len(str1)) result: li = [,,] print(len(li)) result ...
- python中os模块讲解
本文主要介绍一些os模块常用的方法: 先看下我的文件目录结构 D:\LearnTool\pycode\part1 在此目录下的文件如下: abcd.py demo1.1.py demo1.2.py z ...