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 ...
随机推荐
- [REPRINT]Properties vs. Getters and Setters
http://www.python-course.eu/python3_properties.php Our new class means breaking the interface. The a ...
- echart-折线图,数据太多想变成鼠标拖动和滚动的效果?以及数据的默认圈圈如何自定义圆圈的样式
1.数据太多怎么办???想拖拽,想滑动 dataZoom: [ { type: 'slider', } ] dataZoom: [ { type: 'inside', }] 两种功能都需要,还想调样 ...
- 数组对象去重 reduce()
let log = console.log.bind(console); let person = [ {id: 0, name: "小明"}, {id: 1, name: &qu ...
- R 大小写转换
>x = "CAGTTTCTTGAGTCTGATTAATTCAGGTTTCGGGGT"#定义字符串变量x>tolower(x)[1] "cagtttcttga ...
- 手写Tomcat源码
http://search.bilibili.com/all?keyword=%E6%89%8B%E5%86%99Tomcat%E6%BA%90%E7%A0%81 tomcat源码分析一:https: ...
- [BZOJ2822]:[AHOI2012]树屋阶梯(卡特兰数)
题目传送门 题目描述 暑假期间,小龙报名了一个模拟野外生存作战训练班来锻炼体魄,训练的第一个晚上,教官就给他们出了个难题.由于地上露营湿气重,必须选择在高处的树屋露营.小龙分配的树屋建立在一颗高度为N ...
- React-Native 之 GD (十二)海淘半小时热门 及 获取最新数据个数功能 (角标)
1.海淘半小时热门 基本功能和首页相似 GDHt.js /** * 海淘折扣 */ import React, { Component } from 'react'; import { Style ...
- React-Native 之 GD (八)GET 网络请求封装
1.到这里,相信各位对 React-Native 有所熟悉了吧,从现在开始我们要慢慢往实际的方向走,这边就先从网络请求这部分开始,在正式开发中,网络请求一般都单独作为一部分,我们在需要使用的地方只需要 ...
- jenkins执行 pod install 报错 CocoaPods requires your terminal to be using UTF-8 encoding. Consider adding the following to ~/.profile:
错误提示是: CocoaPods 需要终端使用utf-8编码 解决办法
- python使用__new__创建一个单例模式(单例对象)
#单例模式:使一个类只产生一个对象.他们的id地址都指向同一个内存地址 第一步:理解谁创建了对象 # 单例模式# 首先明白,我们在创建一个类的对象的时候,其实是调用的这个类的父类,即继承object, ...