【链接】 我是链接,点我呀:)

【题意】

让你求出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的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【NOIP模拟】matrix(简化矩阵)

    题目背景 SOURCE:NOIP2016-RZZ-1 题目描述 给出两个 N×N 的矩阵 A.B,矩阵每行每列标号 0-N-1 .定义这两个矩阵的乘积 AB 为

  3. 【POJ 3233】Matrix Power Series

    [题目链接] 点击打开链接 [算法] 要求 A^1 + A^2 + A^3 + ... + A^k 考虑通过二分来计算这个式子 : 令f(k) = A^1 + A^2 + A ^ 3 + ... + ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. struct框架

    配置文件struct-config.xml<?xml version="1.0"encoding="UTF-8"?><!DOCTYPE str ...

  2. 如何快速删除Linux下的svn隐藏文件及其他临时文件 (转载)

    转自:http://blog.csdn.net/edsam49/article/details/5840489 在Linux下,你的代码工程如果是用svn进行管理的,要删除Linux kernel里的 ...

  3. Linux学习笔记之Linux系统启动过程

    Linux系统的启动过程可以分为五个阶段: 内核的引导 运行init 系统初始化 建立终端 用户登录系统 1.内核引导: 当计算机打开电源后,首先进行BIOS开机自检,按照BIOS中设置的启动设备(一 ...

  4. jQuery——表单应用(1)

    实现结果:聚焦表单的input部分时,input格式变更为CSS样式(获取和失去焦点改变样式) HTML: <!DOCTYPE html> <html> <head> ...

  5. [USACO09NOV]灯Lights

    题目描述 Bessie and the cows were playing games in the barn, but the power was reset and the lights were ...

  6. Poj 3694 Network (连通图缩点+LCA+并查集)

    题目链接: Poj 3694 Network 题目描述: 给出一个无向连通图,加入一系列边指定的后,问还剩下多少个桥? 解题思路: 先求出图的双连通分支,然后缩点重新建图,加入一个指定的边后,求出这条 ...

  7. 最大流增广路(KM算法) HDOJ 2255 奔小康赚大钱

    题目传送门 /* KM:裸题第一道,好像就是hungary的升级版,不好理解,写点注释 KM算法用来解决最大权匹配问题: 在一个二分图内,左顶点为X,右顶点为Y,现对于每组左右连接Xi,Yj有权w(i ...

  8. 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe

    题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...

  9. 数据库学习:for xml path

    一.开发环境 数据库:SQLServer2012 二.语法简介 for xml path它以xml形式展示查询的结果集 三.语法介绍 现在数据库中有一张表 1.基本语法 select * from B ...

  10. LN : leetcode 529 Minesweeper

    lc 529 Minesweeper 529 Minesweeper Let's play the minesweeper game! You are given a 2D char matrix r ...