Codeforces Round #213 (diy.2) C. Matrix
来源:互联网 发布:淘宝店铺主营在哪里改 编辑:程序博客网 时间:2024/06/05 16:45
题目链接:点击打开链接
这题昨天做的时候题意读错了。。。关于数矩形和=a的部分,矩形a的值的计算这里
理解错误。
题意:(解题报告来源:cherish_)
用题目中的方法构造一个矩阵。
比如第一个样例
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
然后求出矩阵中长方形的和等于a的长方形的数量
思路:
1、计算构成它的长的那些数字的和
2、构成它的宽的那些数字的和
3、长方形的和=两个和的积
枚举出来S可以凑出的数字
然后行和列能凑出来的东西是一样的
那么枚举出现过的东西 然后去凑出a
当a==0的时候特判一下就Ok啦
记得longlong
//31ms
//cnt数组要用long long类型~~~~~~
#include<cstdio>#include<iostream>#include<cstring>using namespace std;char str[4010];int b[4010];long long cnt[40010];long long ans;int main(){ int a; while(scanf("%d%s",&a,&str)!=EOF) { memset(cnt,0,sizeof(cnt)); memset(b,0,sizeof(b)); ans=0; int len=strlen(str); for(int i=0;i<len;i++) b[i]=str[i]-'0'; for(int i=0;i<len;i++) { int s=0; for(int j=i;j<len;j++) { s+=b[j]; cnt[s]++; //cout<<s<<' '<<cnt[s]<<endl; } } if(a==0) { for(int i=0;i<40000;i++) ans+=cnt[i]*cnt[0]; } //else //{ for(int i=1;i<40000;i++) { if(a%i==0 && a/i>=0 && a/i<=len*9) ans+=cnt[i]*cnt[a/i]; } //} printf("%I64d\n",ans); memset(str,0,sizeof(str)); } return 0;}
另外一种~46ms
#include<cstdio>#include<iostream>#include<cctype>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<queue>#include<cstdlib>using namespace std;char str[4050];int a[4050];int b[40010];int main(){ int m,n; while(scanf("%d%s",&m,str)!=EOF) { n = strlen(str); for(int i=0;i<n;i++) a[i]=str[i]-'0'; memset(b,0,sizeof(b)); for(int i=0;i<n;i++) { int s=0; for(int j=i;j<n;j++) { s+=a[j]; b[s]++; //cout<<"test:"<<b[s]<<' '<<s<<endl; } } long long ans=0; for(int i=0;i<n;i++) { int s=0; for(int j=i;j<n;j++) { s+=a[j]; if(s>0 && m%s==0 && m/s<=n*9) { //cout<<s<<' '<<b[m/s]<<' '<<m/s<<endl; ans+=b[m/s]; } else if(s==0 && m==0) ans+=(n*(n+1)/2); } } printf("%I64d\n",ans); //return 0; } return 0;}
- Codeforces Round #213 (diy.2) C.Matrix
- Codeforces Round #213 (diy.2) C. Matrix
- 解说Codeforces Round #213 (diy.2) C.Matrix
- Codeforces Round #213 (Div. 2) C Matrix
- Codeforces Round #217 (diy.2) C. Mittens
- Codeforces Round #215 (diy.2) C. Sereja and Algorithm
- Codeforces Round #216 (diy.2) C. Valera and Elections
- Codeforces Round #348 (div 2) C. Little Artem and Matrix
- Codeforces 400 C. Inna and Huge Candy Matrix【 Codeforces Round #234 (Div. 2)】
- Codeforces Round #213C
- Codeforces Round #215 (diy.2) B.Sereja and Suffixes
- Codeforces Round #217 (diy.2) A. Rook, Bishop and King
- Codeforces Round #217 (diy.2) B. Berland Bingo
- Educational Codeforces Round 30 C. Strange Game On Matrix
- Codeforces Div.2 213 C Matrix (预处理+哈希)
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #236 (Div. 2) E. Strictly Positive Matrix
- Codeforces Round #214 (diy.2) B. Dima and To-do List
- Linux上像windows的FinalData的修復工具
- dlopen dlclose dlXXX
- ++*ip
- 理解 linux inode
- VMware Player 免費首選虛擬機器,執行速度快!
- Codeforces Round #213 (diy.2) C. Matrix
- unix network programming volume2 sorce code build and get(UNIX網絡編程卷2第二版)
- Struts2JQueryJson
- man page分類與說明
- Django 学习笔记(五)
- OpenGrok試用in WinXP
- C/C++控制台输出不同颜色的字体
- json
- javascript右下角弹层及自动隐藏