SPOJ - COLONY B - Linearian Colony 二分
来源:互联网 发布:磁铁车牌号码贴 淘宝 编辑:程序博客网 时间:2024/06/05 09:58
Description
Linearians are pecurliar creatures. They are odd in several ways:
- Every Linearian is either red or blue.
- A Linearian colony is a straight line, aligned N-S with the magentic field.
- A colony starts with single red Linearian.
- Every year, each Linearian produces an offspring of the opposite color. After birth, the parent moves just south of the offspring. (Since everyone is born at once, this does make for a lot of jostling, but everyone stays in order.)
So a colony grows as follows:
N ----------- SYear 0: RYear 1: BRYear 2: RBBRYear 3: BRRBRBBRYear 4: RBBRBRRBBRRBRBBR
Given a year and a position along the N-S axis, determine what the color of the Linearian there will be.
Input
The first line is the year Y (0 <= Y <= 51). The second line is the position P from north to south, 0-indexed (0 <= P < 2^Y).
Ouput
The color of the Linearian, either red or blue.
36
51123456789012345
blue
red
#include <iostream> #include <cstdio>#include <cstdlib>#include <cmath>#include <fstream>#include <algorithm>#include <climits>#include <cstring>#include <string>#include <set>#include <map>#include <queue>#include <stack>#include <vector>#include <list>const int maxn=5e2+10;using namespace std;typedef long long ll;typedef unsigned long long ull; ll y,p; int main(){ll sum =1;cin >> y>>p;p++;for(int i=1;i<=y;i++)sum*=2;int flag = 0; ll l=1,r=sum;while(l<r){ll mid = (l+r)/2;if(p<=mid){flag ++;r = mid;}else{l = mid+1;}} //cout <<l<<r<< flag <<endl;if(flag%2)cout <<"blue"<<endl;elsecout <<"red"<<endl; return 0;}
0 0
- SPOJ - COLONY B - Linearian Colony 二分
- Linearian Colony SPOJ - COLONY
- SPOJ-COLONY - Linearian Colony!简单二分思想
- Linearian Colony
- SPOJ - Linearian Colony【分解为子问题】
- [BZOJ3872][Poi2014]Ant colony(dfs+二分)
- [BZOJ 3872][POI 2014]Ant colony(BFS+二分)
- CodeForces 474F Ant colony 【线段树】【gcd】【二分】
- bzoj 3872: [Poi2014]Ant colony (dfs+二分)
- About Ant Colony Optimization
- Sicily 2377. Ants Colony
- 【CODEFORCES】 F. Ant colony
- zoj 3005 Bacteria Colony
- Ant Colony Algorithm
- Ant Colony Optimization
- BZOJ3872: [Poi2014]Ant colony
- POI2014 Ant colony
- Binary Ant Colony Optimization
- codeforces Good Bye 2016
- 优雅编程之阿里巴巴开发规范分享及扩展学习(三十八)
- Github 简明教程
- MVC的配置
- Windows安装mysql-5.7.17-winx64.zip方式
- SPOJ - COLONY B - Linearian Colony 二分
- spring aop原理(动态代理)
- Spring Data Jpa 查询
- kmeans(最简单的机器学习算法)
- (草稿)WEB服务器、应用程序服务器、HTTP服务器
- Java过滤器与SpringMVC拦截器之间的关系与区别
- HDU How many prime numbers
- 2017喽
- springmvc使用hibernate-validator校验框架实现后端校验