Problem Statement

Takahashi, Aoki and Snuke love cookies. They have AB 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 412 and 20 cookies. Then,

  • After the first action, they have 1612 and 8.
  • After the second action, they have 1012 and 14.
  • After the third action, they have 1312 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的更多相关文章

  1. Atcoder Grand-014 Writeup

    A - Cookie Exchanges 题面 Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respec ...

  2. AtCoder Grand Contest 014

    AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中 ...

  3. 【AtCoder】AGC014

    AGC014 链接 A - Cookie Exchanges 发现两个数之间的差会逐渐缩小,所以只要不是三个数都相同,那么log次左右一定会得到答案 #include <bits/stdc++. ...

  4. AtCoder Grand Contest 014 题解

    A - Cookie Exchanges 模拟 Problem Statement Takahashi, Aoki and Snuke love cookies. They have A, B and ...

  5. A@GC*014

    A@GC*014 A Cookie Exchanges 卡时跑了1s就输出-1 每次操作会使三个数的极差缩小一半,所以最多\(\log\)次之后就会出现\(A=B=C\)的情况,可以直接判掉 B Un ...

  6. Python Web学习笔记之Cookie,Session,Token区别

    一.Cookie,Session,Token简介 # 这三者都解决了HTTP协议无状态的问题 session ID or session token is a piece of data that i ...

  7. 超大 Cookie 拒绝服务攻击

    有没有想过,如果网站的 Cookie 特别多特别大,会发生什么情况? 不多说,马上来试验一下: for (i = 0; i < 20; i++) document.cookie = i + '= ...

  8. IE10、IE11 User-Agent 导致的 ASP.Net 网站无法写入Cookie 问题

    你是否遇到过当使用一个涉及到Cookie操作的网站或者管理系统时,IE 6.7.8.9下都跑的好好的,唯独到了IE10.11这些高版本浏览器就不行了?好吧,这个问题码农连续2天内遇到了2次.那么,我们 ...

  9. 解决cookie跨域访问

    一.前言 随着项目模块越来越多,很多模块现在都是独立部署.模块之间的交流有时可能会通过cookie来完成.比如说门户和应用,分别部署在不同的机器或者web容器中,假如用户登陆之后会在浏览器客户端写入c ...

随机推荐

  1. awk纯干货

    AWK的惊人表现: Awk设计的目的:简化一般文本处理的工作. 属于POSIX的一部分. AWK命令行: Awk的调用可以定义变量.提供程序并且指定输入文件: Awk [ -F fs ]  [ -v ...

  2. webAssmebly实现js数组排序 使用custom elements和Shadow DOM自定义组件

    直接上码了……………… .wat源码 (module (type $t0 (func (param i32 i32))) (type $t1 (func (result i32))) (type $t ...

  3. Windows10系统可以禁止的服务(按名称排序)

    1.Application LayerGateway Service(Windows必须禁止的10项服务) 2.Bluetooth Handsfree Service(没有蓝牙的用户可以关闭) 3.B ...

  4. (19)zabbix Applications使用介绍

    介绍 Applications(我们翻译为应用程序)是item的一个组. 例如我们要监控MySQL,我们可以将所有和MySQL相关的item放到这个应用程序中. 例如MySQL的availabilit ...

  5. VS做简历的第三天(将文件中的样式保存并且导入)

    VS做简历的第三天(将文件中的样式保存并且导入) 1.先在文件栏新建一个CSS文件 如 2.将第二天如下代码,删除<stype></stype>保留中间部分,复制在CSS文件并 ...

  6. GYM 101350 G

    G. Snake Rana time limit per test 4.0 s memory limit per test 256 MB input standard input output sta ...

  7. ACM Changchun 2015 A. Too Rich

    You are a rich person, and you think your wallet is too heavy and full now. So you want to give me s ...

  8. H.264 Profile-level-id

    基于SIP协议的VOIP通信,该字段通常位于视频协商sdp报文中,如: video RTP/AVP rtpmap: H264/ fmtp: profile-level-id=42801E; packe ...

  9. PAT Basic 1063

    1063 计算谱半径 在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界.换言之,对于给定的 n 个复数空间的特征值 { a​1​​+b​1​​i,⋯,a​n​​+b​n​​i },它们的模为实部 ...

  10. C#中何时使用dynamic

    背景:比如说,有一个方法,有很多参数,且有时候只需要其中的某几个参数,有时候需要使用全部,甚至有时候一个都不需要,这时候写一个长长的参数列表一点都不酷,且容易 出错,这时候就需要考虑C#的dynami ...