CF992C Nastya and a Wardrobe
题意很清晰,这种题,我们当然还是有两种方法来做啦
方法一:找规律
读完题我们来看样例,通过样例一已我们大概可以看出,答案或许是\(n*2^{k+1}\)
肯定不能这么简单对吧,那就来看样例二,难道答案是\(n*2^{k+1}-k\)或者是\(n*2^{k+1}-2^{k-1}\)也有可能是\(n*2^{k+1}-2^k+1\)
通过样例三可得,答案是\(n*2^{k+1}-2^k+1\)
方法二:数学证明
每个月都是乘2,所以第i个月取走一个对第j个月的影响就是\(2^{j-i}(i<j)\)
那么每个月都会对最后一个月产生影响,影响总和是$ \sum _ {i=0} ^ {k-1} 2^i $,也就是\(2^k-1\)
这是负的影响,正的影响很容易算,就是\(n*2^{k+1}\)
说白了,每个月要么直接乘二,要么-1再乘二,我们把这个-1提出来,就分成了上面所说的正贡献和负贡献
千万别忘了特判等于零,还有直接乘会爆long long
下面放代码
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#define ll long long
#define gc getchar
#define mo 1000000007
using namespace std;
inline ll read(){
ll a=0;int f=0;char p=gc();
while(!isdigit(p)){f|=p=='-';p=gc();}
while(isdigit(p)){a=(a<<3)+(a<<1)+(p^48);p=gc();}
return f?-a:a;
}
ll n,k,k1,e=2,sum=1;
inline ll cheng(ll a,ll b){
ll sum=0;
while(b){
if(b&1)sum=(sum+a)%mo;
a=(a<<1)%mo;b>>=1;
}
return sum;
}
int main(){
n=read();k1=k=read();++k;
if(n==0){
puts("0");
return 0;
}k%=mo-1;
while(k){
if(k&1)n=cheng(n,e)%mo;
e=cheng(e,e)%mo;k>>=1;
}e=2;k1%=mo-1;
while(k1){
if(k1&1)sum=cheng(sum,e)%mo;
e=cheng(e,e)%mo;k1>>=1;
}
--sum;if(sum<0)sum+=mo;
printf("%lld\n",((n-sum)%mo+mo)%mo);
return 0;
}
不要抄代码哦
CF992C Nastya and a Wardrobe的更多相关文章
- CF992C Nastya and a Wardrobe 数学 第四道
Nastya and a Wardrobe time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...
- Codeforces 992C Nastya and a Wardrobe (思维)
<题目链接> 题目大意: 你开始有X个裙子 你有K+1次增长机会 前K次会100%的增长一倍 但是增长后有50%的机会会减少一个 给你X,K(0<=X,K<=1e18), 问你 ...
- Nastya and a Wardrobe CodeForces - 992C(规律)
写一下二叉树 推一下公式就出来了, 注意取模时的输出形式 #include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a ...
- CodeForces 992C Nastya and a Wardrobe(规律、快速幂)
http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减 ...
- Codeforces Round #489 (Div. 2)
A. Nastya and an Array time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #489 (Div. 2) B、C
B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input ...
- [Codeforces]Codeforces Round #489 (Div. 2)
Nastya and an Array 输出有几种不同的数字 #pragma comment(linker, "/STACK:102400000,102400000") #ifnd ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
随机推荐
- pygrib学习
pygrib-2.0.3/docs/index.html 导入pygrib模块 >>> import pygrib 打开grib文件,获取grib消息迭代器 >>> ...
- electron快速开始
初学electron 接触了两周的electron,感觉还不错,以后pc端基本上可以用electron加壳写pc端应用了,可以用nodejs的模块,也可以用es6.7,还可以直接操作系统文件.基本上可 ...
- react-native初体验(1) — hello world
没有简介,直接开始干活吧. 默认阅读本文的你已经安装好 nodejs, windows用户需要升级yarn到最新版本. 并且设置安装源为国内的淘宝源: npm config set registry ...
- LeetCode 193. Valid Phone Numbers
分析 难度 易 来源 https://leetcode.com/problems/valid-phone-numbers/ 题目 Given a text file file.txt that con ...
- IDEA主题设置
主题下载: Color Themes(个人倾向该网站,而不是http://www.riaway.com/) 主题设置: 打开IDEA,按下Ctrl+Alt+S,选择Editor-->Color ...
- Kettle日常使用汇总整理
Kettle日常使用汇总整理 Kettle源码下载地址: https://github.com/pentaho/pentaho-kettle Kettle软件下载地址: https://sourcef ...
- GlusterFS分布式存储集群-2. 使用
参考文档: Quick Start Guide:http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/ Instal ...
- caffe 预训练 或者Fine-Tuning 操作
1.使用预训练模型,需要修改训练的prototxt,将layer name改为与要使用模型的layer name相同即可. Borrowing Weights from a Pretrained Ne ...
- python判断文件和文件夹是否存在、没有则创建文件夹
原文出处:https://www.cnblogs.com/hushaojun/p/4533241.html >>> import os >>> os.path.ex ...
- teamwork 2
1.访问上学期项目团队,学习他们的得失. 上学期学长们有一个项目是学霸系统,在看过了学长们的相关博客后,我们可以感受到学长们确实花费了不少心思,也看到了许多值得我们学习的地方. 首先,学长们在项目开始 ...