Codeforces 365C Matrix 暴力
来源:互联网 发布:矩阵论清华大学出版社 编辑:程序博客网 时间:2024/05/17 23:44
点击打开链接
题意:给出A<=1e9,string s长度<=4000.矩阵b[i][j]=s[i]*s[j],问b有多少个子矩阵和为A
利用b[i][j]=s[i][j] 若子矩阵左上角(a,b),右下角(c,d)和为A 则(s[a]+..s[c])*(s[b]+..s[d])=A
n<=4e3,暴力预处理出和为x的区间个数,枚举a,c. ans+=cnt( A/(s(a)+..s[c]) )
特判A=0 非0区间个数乘以0区间的个数+零区间个数^2
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=5e3+20;ll A,p[N];char s[N];map<ll,ll> mp;//mp[x] 和为x的区间个数 int main(){while(cin>>A){p[0]=0,mp.clear();scanf("%s",s+1);int n=strlen(s+1);for(int i=1;i<=n;i++)p[i]=p[i-1]+(s[i]-'0');ll res=0,zero=0;for(int i=0;i<=n;i++){for(int j=i+1;j<=n;j++){mp[p[j]-p[i]]++;if(p[j]-p[i])res++;elsezero++;}}ll ans=0;if(A==0){ans+=(zero*res)*2ll+zero*zero;cout<<ans<<endl;continue;}for(int i=0;i<=n;i++){for(int j=i+1;j<=n;j++){ll x=p[j]-p[i];if(x==0)continue;if(x&&(A%x)==0)ans+=mp[A/x];}}cout<<ans<<endl;}return 0;}
阅读全文
0 0
- Codeforces 365C Matrix 暴力
- CodeForces 669C Little Artem and Matrix(暴力)
- Codeforces 669C Little Artem and Matrix【思维+暴力】
- Codeforces 493C 暴力
- codeforces 837C(暴力)
- codeforces 900C(暴力)
- Codeforces 486B OR in Matrix(暴力)
- Codeforces 412C Pattern(暴力)
- codeforces 461C 暴力+BIT
- Codeforces 570C Replacement 暴力
- Codeforces-Strange Game On Matrix(暴力直接写)
- Codeforces 401C Team(贪心+暴力)
- Codeforces 474c Captain Marmot | 暴力几何
- Codeforces 490C Hacking Cypher(暴力)
- Codeforces 493C Vasya and Basketball(暴力)
- Codeforces 387C George and Number 暴力
- Codeforces 558C Amr and Chemistry 暴力 - -
- Codeforces 496C Removing Columns(暴力)
- 制作简易聊天界面
- 关于Xutils框架出现无法访问HttpRequestBase 找不到org.apache.http.client.methods.HttpRequestBase解决方案
- 【mysql 事件】mysql事件的开启和调用
- [搜索] hdu1043 Eight(8思路)
- Android观察者模式项目中基本用法
- Codeforces 365C Matrix 暴力
- Android 中aidl调用执行线程和同步异步问题
- Lintcode——整数排序 II
- js 前端验证表单输入
- SQL Server数据库的基本操作
- Device Module之Kobject,Ktype,Kset(基于kernel 4.11)
- 架构的理解
- android的Environment类
- Java多线程之this与Thread.currentThread()的区别——java多线程编程核心技术