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 ...
随机推荐
- poj 3352 : Road Construction 【ebcc】
题目链接 题意:给出一个连通图,求最少加入多少条边可使图变成一个 边-双连通分量 模板题,熟悉一下边连通分量的定义.最后ans=(leaf+1)/2.leaf为原图中size为1的边-双连通分量 #i ...
- 【leetcode】1169. Invalid Transactions
题目如下: A transaction is possibly invalid if: the amount exceeds $1000, or; if it occurs within (and i ...
- 借用的对vue-cli配置对解析
- 常用的JAVA第三方工具类
转自:https://www.jianshu.com/u/9c5cb1ee4c46 一. org.apache.commons.io.IOUtils 注解 说明 closeQuietly 关闭一个IO ...
- HDU-6705 Path
Description You have a directed weighted graph with n vertexes and m edges. The value of a path is t ...
- 170826-关于spring的知识点及练习
1.Spring作用: 1.生态体系庞大,全能型选手![springmvc是其一个子模块,jdbcTemplate能直接操作数据库!] 2.将其他组件粘合在一起 3.IOC容器和AOP[Aspect ...
- jquery attr()方法获取input的checked属性问题
问题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法获取其真实值,下面介绍这两种方法的区别: 1.通过prop方法获取checked属性 ...
- codeblocks-error: Illegal byte sequence
error: converting to execution character set: Illegal byte sequence 对于源码包含有中文编译过程中出现如上的错误 解决办法:在Comp ...
- 从数据库、页面加载速度角度思考 id设计 sku asin
(已对数据进行字符串替换,去身份识别.隐私跟踪) 12-13-14-15-16-18岁20女孩夏装初中高中学生韩版上衣服短袖T恤衫-tmall.com天猫 https://detail.tmall.c ...
- python生成requirements.txt 导出项目依赖
使用pip freeze $ pip freeze > requirements.txt 这种方式是把整个环境中的包都列出来了,如果是虚拟环境可以使用. 通常情况下我们只需要导出当前项目的req ...