【Codeforces 364A】Matrix
【链接】 我是链接,点我呀:)
【题意】
让你求出b[i][j]=s[i]*s[j]规则构成的矩阵
的所有子矩阵中子矩阵的和为a的子矩阵的个数
【题解】
(x,y,z,t)
会发现它的和就是sum(x,y)*sum(z,t)
sum(x,y)=a[x]+a[x+1]+...+a[y]
因为这个子矩阵的和就是
a[x][z]+a[x][z+1]+...+a[x][t] +
a[x+1][z] + a[x+1][z+1]....+a[x+1][t]
....
而a[i][j] = a[i]*a[j]
下次遇到这样的就动手算一算和是什么
看看能不能找出规律
注意a=0的时候的情况分类讨论一波
sum(x,y)最多就为9*|s|
因此如果a/i >9*|s|就不用管它
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = 4000;
static class Task{
int cnt[] = new int[N*10+100];
int s[] = new int[N+10];
String S;
int a,n;
public void solve(InputReader in,PrintWriter out) {
a = in.nextInt();
S = in.next();
for (int i = 0;i < (int)S.length();i++) {
s[i+1] = S.charAt(i)-'0';
}
n = S.length();
for (int i = 1;i <= n;i++) {
int temp = 0;
for (int j = i;j <= n;j++) {
temp = temp + s[j];
cnt[temp]++;
}
}
long ans = 0;
if (a==0) {
//a==0
//sum(x,y)*sum(z,t)==0
//sum(x,y)==0 sum(z,t)!=0
//or sum(x,y)!=0 sum(z,t)==0
for (int i = 1;i <=N*10;i++) {
ans = ans + 1l*2*cnt[0]*cnt[i];
}
//sum(x,y)==0 sum(z,t)==0
ans = ans + 1l*cnt[0]*cnt[0];
}else {
for (int i = 1;i <= N*10;i++) {
if (a%i==0 && a/i<=(N*10)) {
ans = ans + 1l*cnt[i]*cnt[a/i];
}
}
}
out.println(ans);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 364A】Matrix的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【NOIP模拟】matrix(简化矩阵)
题目背景 SOURCE:NOIP2016-RZZ-1 题目描述 给出两个 N×N 的矩阵 A.B,矩阵每行每列标号 0-N-1 .定义这两个矩阵的乘积 AB 为
- 【POJ 3233】Matrix Power Series
[题目链接] 点击打开链接 [算法] 要求 A^1 + A^2 + A^3 + ... + A^k 考虑通过二分来计算这个式子 : 令f(k) = A^1 + A^2 + A ^ 3 + ... + ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- Connection: close和Connection: keep-alive有什么区别?
看到有人问Connection: close和Connection: keep-alive有什么区别?想起以前学习到的一篇文章,今天转载来,大家看看,我也再温故知新下.如果有问题补充的在下面可以扩充下 ...
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
按左端点排序,贪心的选即可 #include<iostream> #include<cstdio> #include<algorithm> using namesp ...
- robotframework - 测试用例&套件- Settings标签
1.Test Case -- Settings标签截图 2.Test Case Settings 标签说明: Documentation:用于描述用例的一个小文本,它可以把 URL 地址转换为可点击的 ...
- 使用printf和String.format格式化输出
格式化输出 在哪些情况下使用格式化输出: 异常打印到日志中使用格式化输出有利于排查错误原因: printf格式化 示例: public class PrintfTest { public static ...
- 13、git
安装Git 网上有很多Git安装教程,如果需要图形界面,windows下建议使用TortoiseGit,linux建议使用Git GUI或者GITK.(windows下载exe安装包,linux可以使 ...
- 士兵杀敌 三 --- O( 1 ) 的时间复杂度 .
一看就是 十分简单的 题 , 然后上去开始无脑程序 超时~~~ 感觉时间复杂度 , 已经很低了 , 但是并没有什么卵用 . #include<stdio.h> #in ...
- Canvas入门笔记-实现极简画笔
今天学习了Html5 Canvas入门,已经有大神写得很详细了http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html#8 在学习过后 ...
- Spring.Net学习笔记(2)-依赖注入
一.开发环境 操作系统:Win10 编译器:VS2013 framework版本:.net 4.5 Spring版本:1.3.1 二.涉及程序集 Spring.Core.dll Common.Logg ...
- Python批量生成用户名
写在最前 平时在工作中尤其是在做压测的时候难免需要一些用户名和密码,写个简单的Python小脚本批量生成一些 代码示例 import random,string #生成大小字母和数字一起的大字符串 a ...
- Filesystem Hierarchy Standard (Unix, Linux etc)
http://www.pathname.com/fhs/ /boot -- Static files of the boot loader Purpose: contains everything r ...