ACdream 1139(Sum-逆元)
J - Sum
Problem Description
You are given an N*N digit matrix and you can get several horizontal or vertical digit strings from any position.
For example:
123
456
789
In first row, you can get 6 digit strings totally, which are 1,2,3,12,23,123.
In first column, you can get 6 digit strings totally, which are 1,4,7,14,47,147.
We want to get all digit strings from each row and column, and write them on a paper. Now I wonder the sum of all number on the paper if we consider a digit string as a complete decimal number.
Input
The first line contains an integer N. (1 <= N <= 1000)
In the next N lines each line contains a string with N digit.
Output
Output the answer after module 1,000,000,007(1e9+7)。
Sample Input
3
123
456
789
Sample Output
2784
本题暴力会T
所以简化公式
对于同行/列 须要累加的值为 a1*111+a2*22+a3*3
发现规律sum=∑a(10^(n-i+1)-1)/9*i %F
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define MAXN (1000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n;
char a[MAXN][MAXN];
ll p10[MAXN]={0};
ll pow2(ll b)
{
if (b==1) return 10;
if (b==0) return 1;
if (p10[b]) return p10[b];
ll p=pow2(b/2)%F;
p=(p*p)%F;
if (b&1)
{
p=(p*10)%F;
}
p10[b]=p;
return p;
}
ll pow2(ll a,ll b)
{
if (b==1) return a;
if (b==0) return 1;
ll p=pow2(a,b/2)%F;
p=p*p%F;
if (b&1)
{
p=(p*a)%F;
}
return p;
}
ll tot[MAXN]={0};
ll mulinv(ll a)
{
return pow2(a,F-2);
}
int main()
{
// freopen("sum.in","r",stdin);
// freopen("sum.out","w",stdout);
scanf("%d",&n);
For(i,n)
{
scanf("%s",a[i]+1); }
/*
For(i,n)
{
For(j,n) cout<<a[i][j];
cout<<endl;
}
*/
For(i,n)
{
For(j,n) tot[i]+=a[i][j]-'0'+a[j][i]-'0';
} // For(i,n) cout<<tot[i]<<endl; // cout<<mul(pow2(10,1232),mulinv(pow2(10,1232)))<<endl;
// cout<<mulinv(9); ll c9=mulinv(9); For(i,n) p10[i]=pow2(i); ll ans=0;
For(i,n)
{
ll t=sub(p10[n-i+1],1),a=tot[i];
t=mul(t,c9);
t=mul(a,t);
ans=add(ans,mul(t,i));
}
cout<<ans<<endl; return 0;
}
ACdream 1139(Sum-逆元)的更多相关文章
- acdream Divide Sum
Divide Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitSta ...
- ACdream: Sum
Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticN ...
- acdream 1431 Sum vs Product
Sum vs Product Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...
- ACdream 1431——Sum vs Product——————【dfs+剪枝】
Sum vs Product Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...
- ACDream - Power Sum
先上题目: Power Sum Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...
- ACDream - Lowbit Sum
先上题目: C - Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others ...
- Codeforces 963 A. Alternating Sum(快速幂,逆元)
Codeforces 963 A. Alternating Sum 题目大意:给出一组长度为n+1且元素为1或者-1的数组S(0~n),数组每k个元素为一周期,保证n+1可以被k整除.给a和b,求对1 ...
- 2016 Asia Jakarta Regional Contest J - Super Sum UVALive - 7720 【快速幂+逆元】
J-Super Sum 题目大意就是给定N个三元组<a,b,c>求Σ(a1^k1*a2^k2*...*ai^ki*..an^kn)(bi<=ki<=ci) 唉.其实题目本身不难 ...
- Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad) D. Divide and Sum (思维,数学,逆元)
题意:有一个长度为\(2n\)数组,从中选分别选\(n\)个元素出来组成两个序列\(p\)和\(q\),(\(p\)和\(q\)中只要有任意一个元素在\(a\)的原位置不同,就算一个新的情况),选完后 ...
随机推荐
- document.documentElement与body下clientHeight,scrollHeight等区别
本次说明仅在chrom环境下,ie等其他浏览器可能不同 1获取显示屏高度(pc和移动端,屏幕分辨率px) window.screen.height => 这个好理解,不多说. 2获取浏览器可视窗 ...
- Spring 7大功能模块的作用
1. Spring 7大功能模块的作用 1) 核心容器(Spring core) 核心容器提供Spring框架的基本功能.Spring以bean的方式组织和管理Java应用中的各个组件及其关系 ...
- DICOM医学图像处理:fo-dicom网络传输之 C-Echo and C-Store
背景: 上一篇博文对DICOM中的网络传输进行了介绍.主要參照DCMTK Wiki中的英文原文.通过对照DCMTK与fo-dicom两个开源库对DICOM标准的详细实现,对理解DICOM标准有一个更直 ...
- hexo创建的tags和categories页面为空的解决办法
title: hexo创建的tags和categories页面为空的解决办法 toc: false date: 2018-04-16 02:26:10 主题:landscape 添加type以及men ...
- vue 组件来回切换时 记住上一个组件滚动位置(keep-alive)
记住组件滚动状态: 使用场景:从某列表组件进入详情页,在返回的时候需要保留列表组件状态,包括滚动的高度.这个时候需要keep-alive配合. 方法一:如下情况导航在做普遍用法.前提是使用keep-a ...
- jquery的clone()引发的问题,下拉框点击没有反应
此段代码是对某块元素的移位:上移.下移.对比修改前后的两段代码: 修改前: //点击移位 function move(obj,posi){ var al=$(obj).parent('li').par ...
- C#多播委托和事件的区别与关系
事件是对委托的封装. 如果一个类里,你把一个委托声明为 public 了,那么外部就可以随意改变委托变量的值,包括清空委托变量等,这样的话就违背了面向对象思想的封装特性:但如果声明为 private ...
- activity(工作流)初步学习记录
1.概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程自动进行,从而实现某个预期 ...
- 优动漫PAINT-超简单灌木教程
超简单灌木教程~零基础神马的都能神还原哦! 优动漫PAINT下载:http://wm.makeding.com/iclk/?zoneid=18597 想要Get到更多有关优动漫的信息包括软件下载,可关 ...
- json对象获取长度以及字符串和json对象的转换
var arr = Object.keys(typeARR); var str = ''; var len = arr.length; for(var i = 0;i<len;i++){ str ...