Codeforces 1009E
题意略。
思路:
比如现在n = 11。那么我们观察a[1.....n]的出现次数:
a[1]:2 ^ 10 + 10 * 2 ^ 9
a[2]:2 ^ 9 + 9 * 2 ^ 8
a[3]:2 ^ 8 + 8 * 2 ^ 7
.........
a[x]:2 ^ (n - x) + (n - x) * 2 ^ (n - x - 1)
凭借这个规律,我们可以通过快速幂求得答案。
详见代码:
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const LL mod = ;
- const LL maxn = 1e6 + ;
- LL an[maxn];
- LL qmod(LL a,LL n){
- LL ret = ;
- while(n){
- if(n & ) ret = ret * a % mod;
- n = n>>;
- a = a * a % mod;
- }
- return ret;
- }
- int main(){
- int n;
- scanf("%d",&n);
- for(int i = ;i <= n;++i) scanf("%lld",&an[i]);
- LL ans = ;
- for(int i = ;i < n;++i){
- LL temp1 = qmod(,n - i);
- LL temp2 = LL(n - i) * qmod(,n - i - ) % mod;
- ans += (temp1 + temp2) % mod * an[i] % mod;
- }
- ans += an[n];
- ans %= mod;
- printf("%lld\n",ans);
- return ;
- }
现在反过来想想,为什么可以这么去计算呢?
就是因为它要求的是所有情况的总和,这样我们才可以一个个把它们单独拿出来考虑。
Codeforces 1009E的更多相关文章
- Codeforces 1009E Intercity Travelling | 概率与期望
题目链接 题目大意: 一个人要从$A$地前往$B$地,两地相距$N$千米,$A$地在第$0$千米处,$B$地在第$N$千米处. 从$A$地开始,每隔$1$千米都有$\dfrac{1}{2}$的概率拥有 ...
- CodeForces - 1009E Intercity Travelling
题面在这里! 可以发现全是求和,直接拆开算贡献就好了 #include<bits/stdc++.h> #define ll long long using namespace std; c ...
- Intercity Travelling CodeForces - 1009E (组合计数)
大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- python基础-python解释器多版本共存-变量-常量
一.编程语言的发展史 机器语言-->汇编语言-->高级语言,学习难度及执行效率由高到低,开发效率由低到高 机器语言:二进制编程,0101 汇编语言:用英文字符来代替0101编程 高级语言: ...
- java练习---10
package cn.zrjh; public class L { public int id; public String name; public int age; public String c ...
- SQLyog连接数据库报错plugin caching_sha2_password could not be loaded
摘录自: https://blog.csdn.net/lihua5419/article/details/80394716
- Mysql处理中文乱码的问题
一开始在创建完毕数据库和数据表之后,插入中文发现在mysql命令行和在sqlyog终端上看都是乱码,查看了一些文章,写的内容都一样,无非是如下几个步骤: 1:修改数据库字符集为utf8 2:修改数据表 ...
- javaweb入门----servlet简介
servlet 上文已经了解了web服务器和http协议是怎么回事儿,并且也了解了浏览器与服务器之间的联系,现在要介绍一下服务器是如何处理来自客户端的请求的,这就是servlet. servlet:J ...
- 关于报错:The Microsoft.ACE. Oledb.12.0 provider was not registered on the local computer
错误描述:The Microsoft.ACE. Oledb.12.0 provider was not registered on the local computer 最近在Web项目中做一个自动生 ...
- Java匹马行天下之J2EE框架开发——Spring—>用IDEA开发Spring程序(01)
一.心动不如行动 一.创建项目 *注:在IDEA中我创建的Maven项目,不了解Maven的朋友可以看我之前的博客“我们一起走进Maven——知己知彼”,了解Maven后可以看我之前的博客“Maven ...
- python基础之循环与迭代器
循环 python 循环语句有for循环和while循环. while循环while循环语法 while 判断条件: 语句 #while循环示例 i = 0 while i < 10: i += ...
- 【Java例题】3.6 计算arcsin(x)的值
6.使用泰勒展开式计算arcsin(x)的值. arcsin(x)=x+x^3/(2*3)+1*3*x^5/(2*4*5)+...+ (2n)!*x^(2n+1)/(2^2n)*(n!)^2*(2n+ ...
- Lua语言学习
1,语法 语句不用分号结尾 function ... end if .. else .. end 2, io库, string库, table库, OS库, 算术库, debug库 3, dofile ...