http://codeforces.com/problemset/problem/992/C

题意:

给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减1,增长k+1个月后结果是每种情况的总和除以种数。

题目要求的是增长k+1个月后的结果。

我们根据第三个样例可以推出他的增长过程

    3

  6    5

12  11  10  9

|      |     |   |

24    22   20  18

从这个推导我们容易得出最后得到的每种情况构成一个等差数列,公差为2

结果是:(2*n-1)*2k+1

注意特判0的情况,0的时候答案是0,直接输出

另外求2的次方的时候用快速幂,注意取余

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxm=1e6+;
const int maxn=1e5+;
using namespace std; LL POW(LL a,LL b )
{
LL ans = ;
a = a % mod;
while(b)
{
if( b % == )
ans = ( ans * a ) % mod;
a = ( a * a ) % mod;
b /= ;
}
return ans;
} int main()
{
LL n,k;
scanf("%lld %lld",&n,&k);
LL ans=;
if(n!=)
{
n=n%mod;
ans=(((*n-)*POW(,k)+mod)%mod++mod)%mod;
}
printf("%d\n",ans);
return ;
}

CodeForces 992C Nastya and a Wardrobe(规律、快速幂)的更多相关文章

  1. 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 ...

  2. Codeforces 992C Nastya and a Wardrobe (思维)

    <题目链接> 题目大意: 你开始有X个裙子 你有K+1次增长机会 前K次会100%的增长一倍 但是增长后有50%的机会会减少一个 给你X,K(0<=X,K<=1e18), 问你 ...

  3. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂

    https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...

  5. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

  6. CodeForces - 598A Tricky Sum (数学,快速幂的运用)

    传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...

  7. HDU 5793 A Boring Question (找规律 : 快速幂+逆元)

    A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...

  8. noip-2006普及组-数列- 【模拟-找规律-快速幂】

    链接:https://ac.nowcoder.com/acm/contest/153/1047 来源:牛客网 题目描述 给定一个正整数k( ≤ k ≤ ),把所有k的方幂及所有有限个互不相等的k的方幂 ...

  9. Codeforces 514E Darth Vader and Tree 矩阵快速幂

    Darth Vader and Tree 感觉是个很裸的矩阵快速幂, 搞个100 × 100 的矩阵, 直接转移就好啦. #include<bits/stdc++.h> #define L ...

随机推荐

  1. 洛谷 P2004 领地选择

    题目传送门 解题思路: 二维前缀和. AC代码: #include<iostream> #include<cstdio> using namespace std; ][],an ...

  2. python利用百度云接口实现车牌识别

    一个小需求---实现车牌识别. 目前有两个想法 调云在线的接口或者使用SDK做开发(配置环境和编译第三方库很麻烦,当然使用python可以避免这些问题) 自己实现车牌识别算法(复杂) ! 一开始准备使 ...

  3. 2,The AudioContext was not allowed to start.

    The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on t ...

  4. cf1200 E Compress Words(哈希)

    题意 有n个字符串,记为s1,s2……sn,s2与s1合并,合并的方式为:s1的后缀若与s2的前缀相同,就可以重叠起来,要最长的. 举个例子: “1333”  “33345” → “133345” s ...

  5. opencv3。4安装出错

    https://www.samontab.com/web/2017/06/installing-opencv-3-2-0-with-contrib-modules-in-ubuntu-16-04-lt ...

  6. VMWare WorkStation15--Win10下开机启动虚拟机

    参考 https://www.cnblogs.com/qmfsun/p/6284236.html http://www.cnblogs.com/eliteboy/p/7838091.html VMWa ...

  7. python类(3)感悟

    1.关于类属性attribute和实例(对象)特性property思考 为什么特性会出现,类属性不能完全替代它吗? 属性: python在为属性赋值时,只会搜索对象本身的__dict__,如果找不到对 ...

  8. Oracle 基础1

    oracle基础 表空间: Oracle数据库对数据的管理是基于表空间的概念来的, 各种数据的以及存储数据的优化, 实际上也是通过优化表空间来实现的 表空间分类: 永久表空间 用来存放表的数据, 视图 ...

  9. JavaScript-数据类型和变量

    数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要定 ...

  10. C++queue的使用

    C++队列是一种容器适配器,提供了一种先进先出的数据结构. 队列(queue)模板类定义在<queue>头文件中 基本操作: 定义一个queue变量:queue<Type> q ...