A dreamstart的催促 (快速幂) B TRDD got lost again
链接:https://ac.nowcoder.com/acm/contest/322/A
来源:牛客网
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
有一天集训队的学弟们正在计算一堆数,但是dreamstart感觉他们算的太慢了,就让他们坐在一起想出一个快速计算的方法,但是由于他们一时想不出来,想让你帮助他们。他们说现在有一个数列,要算出第 i 个数的 i 次幂并且把每个数计算出来的值加到一起,最后答案模10000019。
聪明的你可以帮助他们吗?
输入描述:
第一行有一个整数n,n <= 1e5 接下来一行有n个数,每个数的大小不超过1e16
输出描述:
输出取模之后的和
输出
21502 快速幂求解就行
/**
/*快速幂板子
/*
*/
ll mod_pow(ll x , ll n ,ll mod){
if(n==) return ;
ll res = mod_pow(x * x % mod, n / , mod);
if(n % ) res = res * x % mod;
return res;
}
//快速幂
typedef long long ll;
ll mod_pow(ll x ,ll n , ll mod){
ll res;
while(n > ){
if(n & ) res = res * x % mod;
x = x * x % mod;
n >>=;
}
return res;
}
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
long long a[+];
const long long mod=;
int poww(int a, int b) {
ll ans = , base = a;
while (b != ) {
if (b & != )
ans = ans*base%mod;
// base = base*base%mod;
b >>= ;
}
return ans;
} int main() {
//long long x;
int n; scanf("%d",&n);
long long sum = ;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
//a[i] %= mod;
sum=(sum +poww(a[i],i))%mod;
}
//int num = sum;
printf("%lld\n",sum); return ;
}
来源:牛客网
备注:
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=;x=;int f=;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*+ch-'',ch=getchar();x*=f;Finish_read=;}
template<class T>inline void print(T x){if(x/!=)print(x/);putchar(x%+'');}
template<class T>inline void writeln(T x){if(x<)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
const int step[][]={{,},{,},{-,},{,-}};
char mp[][];
string now;
int n,m,sx,sy,ex,ey,dis[][];
typedef pair<int,int>pii;
#define fi first
#define se second
int main() {
ios::sync_with_stdio(false);
cin.tie(),cout.tie();
cin>>n>>m;
getline(cin,now);
for(int i=;i<=*n+;++i) {
getline(cin,now);
for(int j=;j<=*m+;++j) {
mp[i][j]=now[j-],dis[i][j]=1e9;
if(mp[i][j]=='S')
sx=i,sy=j;
if(mp[i][j]=='T')
ex=i,ey=j;
}
}
queue<pii>q;
q.push(pii(sx,sy)),dis[sx][sy]=;
for(pii u;!q.empty();q.pop()) {
u=q.front();
int x=u.fi,y=u.se;
if(x==ex&&y==ey)
return *printf("%d\n",dis[x][y]/+);
for(int k=;k<;++k) {
int nx=x+step[k][],ny=y+step[k][];
if((mp[nx][ny]==' '||mp[nx][ny]=='T')&&dis[nx][ny]>dis[x][y]+)
dis[nx][ny]=dis[x][y]+,q.push(pii(nx,ny));
}
}
puts("TRDD Got lost...TAT");
}
A dreamstart的催促 (快速幂) B TRDD got lost again的更多相关文章
- A.dreamstart的催促
题目描述 有一天集训队的学弟们正在计算一堆数,但是dreamstart感觉他们算的太慢了,就让他们坐在一起想出一个快速计算的方法,但是由于他们一时想不出来,想让你帮助他们.他们说现在有一个数列,要算出 ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- GDUFE-OJ 1203x的y次方的最后三位数 快速幂
嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- HDU5950(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...
随机推荐
- 安装mod_rpaf让apache获取访客真实IP
安装mod_rpaf让apache获取访客真实IP 安装mod_rpaf让apache获取访客真实IP 作者:朱 茂海 /分类:Apache 字号:L M S mod_rpaf是apache ...
- linux运维、架构之路-Kubernetes离线、二进制部署集群
一.Kubernetes对应Docker的版本支持列表 Kubernetes 1.9 <--Docker 1.11.2 to 1.13.1 and 17.03.x Kubernetes 1.8 ...
- Django模板自定义标签和过滤器,模板继承(extend),Django的模型层
上回精彩回顾 视图函数: request对象 request.path 请求路径 request.GET GET请求数据 QueryDict {} request.POST POST请求数据 Quer ...
- WEB超大文件上传与下载
1.介绍enctype enctype 属性规定发送到服务器之前应该如何对表单数据进行编码. enctype作用是告知服务器请求正文的MIME类型(请求消息头content-type的作用一样) 1. ...
- [ZJU 1002] Fire Net
ZOJ Problem Set - 1002 Fire Net Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose that we ha ...
- 学习wavenet_vocoder之预处理、训练
一.预处理 1.在进行预处理时,如果不明白需要的参数,可以使用命令获取帮助,从这里我们可以看到可以具体的用法和对应的参数. python preprocess.py --help python pre ...
- IDEA中代码不小心删除,或者改了半天想回退到某个特定时间怎么办?
第一步: 第二步: 第三步: 第四步:
- centos双网卡配置
centos双网卡问题,一个网卡配置局域网,一个网卡配置公网,如果内网访问自动走eth1,如果外网访问自动走eth2. 需要配置路由吗? 1. 首先查看机器是否是双网卡,命令如下: lspci | g ...
- 从数据库、页面加载速度角度思考 id设计 sku asin
(已对数据进行字符串替换,去身份识别.隐私跟踪) 12-13-14-15-16-18岁20女孩夏装初中高中学生韩版上衣服短袖T恤衫-tmall.com天猫 https://detail.tmall.c ...
- 豆瓣镜像安装python库