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. 留学Essay写作做到精准表达很关键

    很多留学生在essay写作中可以迅速想到合理的中文论点.可是,写出来的英文论点却漏洞百出,不忍直视.在essay写作中我们要如何精准地用英文写出自己内心的独白呢?除了咨询老师,靠自己一样能做到! 1引 ...

  2. 吴裕雄--天生自然 JAVASCRIPT开发学习: Break 和 Continue 语句

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. StringBuffer类、StringBuilder类详解

    StringBuffer是一个字符串缓冲区,是一个容器,而且长度可变,可以直接操作多个数据类型, 最终会通过toString()方法变成字符串. 容器的功能有: 1.存储 public StringB ...

  4. springboot 潜入式web容器

    普通servlet 容器 1.tomcat <dependency> <groupId>org.springframework.boot</groupId> < ...

  5. C++程序--helloworld

    #include<iostream>using namespace std; int main(){ cout << "hello world!" < ...

  6. javascript语法规范和良好的变成习惯

    1.1空白和多行书写 1.空白:空格键输入的空白.tab键输入的空白以及回车键输入的空白 2.多行书写,不能将引号内的字符串放到两行,不然容易报错. 1.2点语法 . 点语法表达式由对象开始,接着是一 ...

  7. Mybatis基本配置(一)

    1. Mybatis介绍 MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis 使用 ...

  8. POJ 2039:To and Fro

    To and Fro Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8632   Accepted: 5797 Descri ...

  9. POJ 1325 && 1274:Machine Schedule 匈牙利算法模板题

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12976   Accepted: 5529 ...

  10. 进度2_家庭记账本App

    今天在昨天的基础上,相继完成了三个页面的布局和显示情况: 新增加的xml文件如下: activity_add.xml: <?xml version="1.0" encodin ...