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, ...
随机推荐
- HDU1209:Clock
参考:https://blog.csdn.net/libin56842/article/details/8990530 https://blog.csdn.net/u011479875/article ...
- 数据库 MySQL part2
表记录的操作 增 1.插入一条记录 语法:insert [into] tab_name (field1,filed2,.......) values (value1,value2,.......); ...
- 【转】moodle中年级、班级、小组研讨
Moodle平台支持年级.班级.小组功能,提供了方便易用的分组工具.小组支持公开和封闭属性,配合教学功能模块,教师可以组织小组为单位的教学活动. 在Moodle中,年级.班级.小组主要是通过群组(co ...
- 在List中删除符合条件的内容
objDAList.RemoveAll(s => s.daCID == "20170725152407CD");
- 高德API+.NET解决租房问题(新增诚信房源)
作者:李国宝链接:https://zhuanlan.zhihu.com/p/22105008(欢迎点赞)来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 之前有小伙伴反应 ...
- 清除远程桌面连接记录和SQLSERVER 连接记录的办法
1.清除远程桌面连接记录: 清除远程桌面访问痕迹.使用windows系统自带的“远程桌面协助”mstsc进行远程,如果连接的用户多了,会留下访问的痕迹.虽然能带来方便,但是如果对于公用电脑来说,这些访 ...
- 30分钟玩转css3动画, transition,animation
其实css3动画是就是2种实现,一种是transition,另一种就是animation.transition实现的话就是只能定制开始帧,和结束2帧:而animation实现的话可以写很多关键帧.没有 ...
- Java日志(二):log4j与XML配置文件
[Java日志(一):log4j与.properties配置文件]一文列举的几个案例以.properties文件作为log4j的配置文件,本文简单看一下log4j与XML配置文件 (1)XML配置文件 ...
- 使用hibernate连接Oracle时的权限问题
在使用hibernate对象关系映射连接和创建表的时候,会涉及到很多权限问题,有些数据库管理会将权限设的很细,我们可以根据后台日志错误和异常信息作出判断. 比如下图所示这个错误(这是我在给银行投产系统 ...
- CF 55D
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...