http://codeforces.com/contest/365/problem/C

构造出的矩阵中的长方形的和等于构成它的长的那些数字的和加上构成它的宽的那些数字的和。 也就是求这个字符串中的两个子字符串的和的乘积等于a的数目。 记录每一个子字符串的和的等于m的数目。然后枚举就可以求出数目。0要单独处理。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 50000
#define LL __int64
using namespace std; LL a;
char s[maxn];
LL c[maxn];
LL sum[maxn];
LL g[maxn];
LL ans; int main()
{
while(scanf("%I64d",&a)!=EOF)
{
scanf("%s",s);
int k=strlen(s);
for(int i=; i<k; i++)
{
c[i+]=(LL)(s[i]-'');
sum[i+]=sum[i]+c[i+];
}
int cnt=;
for(int i=; i<=k; i++)
{
for(int j=; j<i; j++)
{
LL m=sum[i]-sum[j];
g[m]++;
cnt++;
}
}
if(a==)
{
ans=*(cnt-g[])*g[]+g[]*g[];
}
else
{
ans=;
for(int i=; i<; i++)
{
if(a/i<&&a%i==)
{
ans+=g[i]*g[a/i];
}
}
}
printf("%I64d\n",ans);
}
return ;
}

cf C. Matrix的更多相关文章

  1. CF 1042 E. Vasya and Magic Matrix

    E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...

  2. 【CF edu 30 C. Strange Game On Matrix】

    time limit per test 1 second memory limit per test  256 megabytes input standard input output standa ...

  3. [CF #236 (Div. 2) E] Strictly Positive Matrix(强联通分量)

    题目:http://codeforces.com/contest/402/problem/E 题意:给你一个矩阵a,判断是否存在k,使得a^k这个矩阵全部元素都大于0 分析:把矩阵当作01矩阵,超过1 ...

  4. CF 274D Lovely Matrix 拓扑排序,缩点 难度:2

    http://codeforces.com/problemset/problem/274/D 这道题解题思路: 对每一行统计,以小值列作为弧尾,大值列作为弧头,(-1除外,不连弧),对得到的图做拓扑排 ...

  5. [CF] 402 E. Strictly Positive Matrix

    一个矩阵,自乘无限次后能否全为正数? 如果n比较小,可以二分一下,但是这里n很大,乘一次都无法接受 可以考虑实际含义:矩阵看成邻接矩阵,那么0就是没有边,其余就是有边. 我们知道邻接矩阵自乘k次就相当 ...

  6. cf div2 234 D

    D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

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

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

  8. 推荐系统算法学习(一)——协同过滤(CF) MF FM FFM

    https://blog.csdn.net/qq_23269761/article/details/81355383 1.协同过滤(CF)[基于内存的协同过滤] 优点:简单,可解释 缺点:在稀疏情况下 ...

  9. [cf div 2 706E] Working routine

    [cf div 2 706E] Working routine Vasiliy finally got to work, where there is a huge amount of tasks w ...

随机推荐

  1. 【HDOJ】1011 Starship Troopers

    第一道树形DP.很容易理解. #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...

  2. unix网络编程之简介

    通常客户一次只与一个服务器通信, 上图为:一个服务器同时处理多个客户的请求. 上图为:客户与服务器使用TCP协议在同一个以太网中通信. 路由器是广域网的架构设备.今天,最大的广域网是因特网. 上图为: ...

  3. BZOJ3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 45  Solved: 27[Sub ...

  4. 【转】Java 多线程(四) 多线程访问成员变量与局部变量

    原文网址:http://www.cnblogs.com/mengdd/archive/2013/02/16/2913659.html 先看一个程序例子: public class HelloThrea ...

  5. HDOJ 1076 An Easy Task(闰年计算)

    Problem Description Ignatius was born in a leap year, so he want to know when he could hold his birt ...

  6. ACtivity实现欢迎界面并添加动画切换效果

    先看效果: 中间切换动画没来得及截图,凑合着看吧. 主要是java代码的实现: Welcom.java package kehr.activity.welcome; import android.ap ...

  7. [AngularJS] Angular 1.5 $transclude with named slot

    In Angular 1.5, there is no link and compile. So use if you transclude, you cannot access the fifth ...

  8. 【从零学习openCV】IOS7下的人脸检測

    前言: 人脸检測与识别一直是计算机视觉领域一大热门研究方向,并且也从安全监控等工业级的应用扩展到了手机移动端的app,总之随着人脸识别技术获得突破,其应用前景和市场价值都是不可估量的,眼下在学习ope ...

  9. 来自GitHub的Android UI开源项目

    最近在搞Android开发,做了一个项目后感觉,Android开发入门很是简单,但要能做出用户体验比较完美的APP实在是一件很不容易的事情!要达到一定的水准,估计还需要慢慢的积累,这里先保存一个Git ...

  10. VS 的winform中生成release模式

    我试过,直接在项目的"Properties"中,修改"Build"标签的"Configuration"还不行.因为之前将不常用的工具栏隐藏了 ...