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 ...
随机推荐
- ubuntu16.04 配置tomcat开机启动
使用脚本方式设置开机启动 1.将tomcat目录下/bin中的catalina.sh拷贝到/etc/init.d下: cp /usr/local/java/apache-tomcat-/bin/cat ...
- springboot自定义异常数据
一.源码分析 自定义异常数据之前我们先看看一下源码 上述代码意思是如果你没有提供就使用springboot提供的类 这是springboot提供的异常属性类,我们想要自 ...
- iOS---实现在屏幕上实时绘图的简单效果---CAShaperLayer和UIBezierPath的简单运用
首先,声明几个属性 @property(nonatomic,strong)UIBezierPath * beizer; @property(nonatomic,assign)CGPoint start ...
- 【bzoj3926】[Zjoi2015]诸神眷顾的幻想乡
*题目描述: 幽香是全幻想乡里最受人欢迎的萌妹子,这天,是幽香的2600岁生日,无数幽香的粉丝到了幽香家门前的太阳花田上来为幽香庆祝生日. 粉丝们非常热情,自发组织表演了一系列节目给幽香看.幽香当然也 ...
- nginx之Geoip读取地域信息模块
1 geoip_module模块 基于IP地址匹配MaxMind GeolP二进制文件,读取IP所在地域信息. yum install nginx-module-geoip geoip2已经有了,安装 ...
- 续上文,Unity3D面试ABC
http://www.unitymanual.com/blog-3573-685.html 最先执行的方法是: 1.(激活时的初始化代码)Awake,2.Start.3.Update[FixUpdat ...
- ES6 Object.setPrototypeOf ()方法和defineProperty()方法的使用
将一个指定的对象的原型设置为另一个对象或者null(既对象的[[Prototype]]内部属性). 示例: <script type="text/javascript"> ...
- array object
w object(stdClass)#3 (8) { ["MERCHANT_ID"]=> string(11) "MERCHANT_ID" [" ...
- 服务器上安装搭建node环境
一.版本 : node v4.4.3 npm v2.15.1 pm2 v1.1.3 express v4.13.4 二.node安装与环境配置 新建node安装目录,与node项目目录 ...
- accomplish、complete、finish、achieve和fulfill
accomplish to succeed in doing something, especially after trying very hard vt. 完成:实现:达到 complete us ...