Saruman’s Level Up~(多校赛算组合数)
Description
Saruman’s army of orcs and other dark minions continuously mine and harvest lumber out of the land surrounding his mighty tower for N continuous days. On day number i, Saruman either chooses to spend resources on mining coal and harvesting more lumber, or on raising the level (i.e., height) of his tower. He levels up his tower by one unit only on days where the binary representation of i contains a total number of 1’s that is an exact multiple of 3. Assume that the initial level of his tower on day 0 is zero. For example, Saruman will level up his tower on day 7 (binary 111), next on day 11 (binary 1011) and then day 13, day 14, day 19, and so on. Saruman would like to forecast the level of his tower after N days. Can you write a program to help?
Input
The input file will contain multiple input test cases, each on a single line. Each test case consists of a positive integer N < 1016, as described above. The input ends on end of file.
Output
For each test case, output one line: “Day N: Level = L”, where N is the input N, and L is the number of levels after N days.
Sample Input
2
19
64
Sample Output
Day 2: Level = 0
Day 19: Level = 5
Day 64: Level = 21 这题其实就是一个模拟,其实把n转化为二进制,
然后求出小于等于n有多少个数的二进制中含有1的个数是3的倍数
就是计算组合数,思维题,
例如1000100 当计算到第一个1的时候 就是加上c(6,3)+c(6,6)
此时bits的个数加一,然后到第二个1的时候就是看看
(i+bits)%==0 0<=i<=2 时候存在 i 再加上组合数就是了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
typedef long long LL;
LL gcd(LL a, LL b ) {
if (b == ) return a;
return gcd(b, a % b);
}
LL combine(LL n, LL r) {
LL ret = ;
if (r > n - r) r = n - r;
for (LL i = ; i <= r ; i++) {
LL k = n - i + ;
LL g = gcd(i, k);
ret = ret / (i / g) * (k / g);
}
return ret;
}
LL ans(LL n) {
LL ret = , bits = , k = ((LL) << ), r = ;
while(k) {
if (k & n) {
for (int i = ; i <= r ; i++) {
if ((i + bits) > && ((i + bits) % == )) ret += combine(r, i);
}
bits++;
}
k = k >> ;
r--;
}
if (bits > && bits % == ) ret++;
return ret;
}
int main() {
LL n;
while(scanf("%lld", &n) != EOF) {
printf("Day %lld: Level = %lld\n", n, ans(n));
}
return ;
}
Saruman’s Level Up~(多校赛算组合数)的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
		
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
 - 2014上半年acm总结(1)(入门+校赛)
		
大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干= = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...
 - PKU2018校赛 H题 Safe Upper Bound
		
http://poj.openjudge.cn/practice/C18H 题目 算平均数用到公式\[\bar{x}=\frac{x_1+x_2+x_3+\cdots+x_n}{n}\] 但如果用in ...
 - ZJU 17th 校赛
		
第一次参加校赛,和小伙伴们拿了7个气球,还是挺开心的. 简单记个流水账吧. A:判断出INF的情况后 暴力模拟即可. INF的情况有x=1 || y=1 || (x==2 && y= ...
 - 2017校赛 问题 F: 懒人得多动脑
		
题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每日所需的生活水源在一条平行该双曲线准线的直线上,设它的值为v.大家都知道,每天都是要喝水的,但是小D有点懒,他希望自己能在去上学或者 ...
 - SCNU省选校赛第二场B题题解
		
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
 - 2017CUIT校赛-线上赛
		
2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...
 - HZNU第十二届校赛赛后补题
		
愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...
 - 校赛F
		
问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...
 
随机推荐
- PHP中的mysql_unbuffered_query与mysql_query的区别
			
对于mysql_query大家都很熟悉,下面先简单介绍下mysql_unbuffered_query mysql_unbuffered_query (PHP 4 >= 4.0.6, PHP 5) ...
 - linux下磁盘分区、格式化、挂载
			
(1)fdisk /dev/sdb进行分区 (2)选择n表示添加一个分区,选择d表示删除一个分区.可通过m获取帮助信息 (3)选择p表示主分区,然后输入分区大小 (4)分区完成后,可通过fdisk - ...
 - ChemDraw Std 14性价比最高版本,即将下架
			
虽然ChemDraw Std 14是ChemOffice®14的基础组件,但是基础功能涵盖全面,是教育专供产品.根据官方最新消息ChemDraw系列软件产品线将进行全面的升级,ChemOffice®1 ...
 - struts2官方 中文教程 系列六:表单验证
			
先贴个本帖的地址,以免被爬:struts2教程 官方系列六:表单验证 即 http://www.cnblogs.com/linghaoxinpian/p/6906720.html 下载本章节代码 介 ...
 - Android log 里面快速搜索错误堆栈    ( 关键字)
			
有时候,别人给你的log 文件,是一个文件夹,里面放了很多文件.但是可能你需要的log 只有几行.这时候不可能手工搜索的. 那怎么办呢?使用FileLocationPro.下载地址: https:// ...
 - VS2013生产过程问题及解决
			
TRK0002错误 现象:编译器.链接器交替报错,不能正常生成 环境:Win8.1 + VS2013 + 百度杀毒 解决:退出百度杀毒,重启VS,再进行生成 修订:发现问题依旧,经过多次试验,发现与杀 ...
 - jsp 中获取自定义变量
			
首先确定El表达式的查找范围: 依次从Page.Request.Session.Application 中的 attribute属性中查找. <% String basePath = reque ...
 - Python-学习-小例子练习
			
网上了点小例子,练习一下下,都是特别简单的.而且这些代码也都是找的网上的代码,目的是在于练习一下Python和熟悉下Python的编码风格等等 学习一门语言,最快的方法就是把它用在世界的开发中,这样才 ...
 - 基于Python的接口自动化-01
			
为什么要做接口测试 当前互联网产品迭代速度越来越快,由之前的2-3个月到个把月,再到班车制,甚至更短,每次发版之前都需要对所有功能进行回归测试,在人力资源有限的情况下,做自动化测试很有必要.由于UI更 ...
 - 2015年开源前端框架盘点TOP20
			
2015年,榜单根据github上star数作为排名依据.(榜单中大部分为组件式框架, react.Angular等基础框架不在此篇讨论) 1.Bootstrap 类别/语言:HTML.CSS.Jav ...