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

【题意】

让你求出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|就不用管它

【代码】

  1. import java.io.*;
  2. import java.util.*;
  3. public class Main {
  4. static InputReader in;
  5. static PrintWriter out;
  6. public static void main(String[] args) throws IOException{
  7. //InputStream ins = new FileInputStream("E:\\rush.txt");
  8. InputStream ins = System.in;
  9. in = new InputReader(ins);
  10. out = new PrintWriter(System.out);
  11. //code start from here
  12. new Task().solve(in, out);
  13. out.close();
  14. }
  15. static int N = 4000;
  16. static class Task{
  17. int cnt[] = new int[N*10+100];
  18. int s[] = new int[N+10];
  19. String S;
  20. int a,n;
  21. public void solve(InputReader in,PrintWriter out) {
  22. a = in.nextInt();
  23. S = in.next();
  24. for (int i = 0;i < (int)S.length();i++) {
  25. s[i+1] = S.charAt(i)-'0';
  26. }
  27. n = S.length();
  28. for (int i = 1;i <= n;i++) {
  29. int temp = 0;
  30. for (int j = i;j <= n;j++) {
  31. temp = temp + s[j];
  32. cnt[temp]++;
  33. }
  34. }
  35. long ans = 0;
  36. if (a==0) {
  37. //a==0
  38. //sum(x,y)*sum(z,t)==0
  39. //sum(x,y)==0 sum(z,t)!=0
  40. //or sum(x,y)!=0 sum(z,t)==0
  41. for (int i = 1;i <=N*10;i++) {
  42. ans = ans + 1l*2*cnt[0]*cnt[i];
  43. }
  44. //sum(x,y)==0 sum(z,t)==0
  45. ans = ans + 1l*cnt[0]*cnt[0];
  46. }else {
  47. for (int i = 1;i <= N*10;i++) {
  48. if (a%i==0 && a/i<=(N*10)) {
  49. ans = ans + 1l*cnt[i]*cnt[a/i];
  50. }
  51. }
  52. }
  53. out.println(ans);
  54. }
  55. }
  56. static class InputReader{
  57. public BufferedReader br;
  58. public StringTokenizer tokenizer;
  59. public InputReader(InputStream ins) {
  60. br = new BufferedReader(new InputStreamReader(ins));
  61. tokenizer = null;
  62. }
  63. public String next(){
  64. while (tokenizer==null || !tokenizer.hasMoreTokens()) {
  65. try {
  66. tokenizer = new StringTokenizer(br.readLine());
  67. }catch(IOException e) {
  68. throw new RuntimeException(e);
  69. }
  70. }
  71. return tokenizer.nextToken();
  72. }
  73. public int nextInt() {
  74. return Integer.parseInt(next());
  75. }
  76. }
  77. }

【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. jQuery中contains和has的区别

    jQuery中contains和has的区别 根据不同的内容和属性可以准确定位到需要找的属性 如何根据内容筛选标签?:contains        匹配包含给定的文本元素$("div:co ...

  2. 通过CSS控制页面中的内容垂直居中的方法

    方法一:通过行高(line-height)定位 line-height通常是用于调节一段文字的行与行之间的距离,或者说两行文字之间的距离,如果行高是500px,那么每一行中的文字距离本行的顶部就是25 ...

  3. Android 在eclipse中没有出现AVD的解决方法(转载)

    转自:http://frabbit2013.blog.51cto.com/1067958/1243549 本文主要介绍在系统中成功配置好Android开发环境(即SDK is ok and ADT o ...

  4. E20171212-hm

    odd   adj. 古怪的; 奇数的; 剩余的; 临时的; odd number 奇数 even adj. 偶数的 even number 偶数

  5. bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【Floyd】

    弗洛伊德之后按序列加起来即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...

  6. json和Jsonp 使用总结(1)

    1.Json的使用 $.getJSON("subPreview", { jsonDatas: JSON.stringify(jsonData) }, function(data) ...

  7. 题解报告:poj 2386 Lake Counting(dfs求最大连通块的个数)

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  8. SQL server存储过程及触发器基础

    存储过程:就像函数一样的会保存在数据库中-->可编程性 --> 存储过程-----------------------------------------------------创建存储过 ...

  9. RabbitMQ指南之四:路由(Routing)和直连交换机(Direct Exchange)

    在上一章中,我们构建了一个简单的日志系统,我们可以把消息广播给很多的消费者.在本章中我们将增加一个特性:我们可以订阅这些信息中的一些信息.例如,我们希望只将error级别的错误存储到硬盘中,同时可以将 ...

  10. 盒子模型,top和margin-top

    1. 标准盒子模型: width只是内容的宽度. 元素的总宽度=width + padding*2 +border*2 +margin*2. IE盒子模型: width=内容的宽度 + padding ...