当前位置: 首页 > news >正文

CF364

链接:http://codeforces.com/contest/364

A:Matrix

关于矩阵。。。

Let's notice that sum in the rectangle (x1, y1, x2, y2) is sum(x1, x2)·sum(y1, y2). Where sum(l, r) = sl + sl + 1 + ... + sr. Then, we have to calc sum(l, r) for every pair (l, r) and count how many segments give us sum x for any possible x (0 ≤ x ≤ 9·|s|). In the end we should enumerate sum on segemnt [x1, x2] and find . There is corner case a = 0.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 using namespace std;
 5 #define LL long long
 6 const int maxn=4010;
 7 LL n;
 8 char s[maxn];
 9 LL a[maxn][maxn],sum[maxn][maxn];
10 int main()
11 {
12     cin>>n>>s+1;
13     int len=strlen(s+1);
14     for(int i=1;i<=len;i++)
15         for(int j=1;j<=len;j++)
16         a[i][j]=(s[i]-'0')*(s[j]-'0');
17     for(int i=1;i<=len;i++)
18         for(int j=1;j<=len;j++)
19             sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
20             LL ans=0;
21     for(int i=1;i<=len;i++)
22         for(int j=1;j<=len;j++)
23             for(int k=1;k<=i;k++)
24                 for(int l=1;l<=j;l++)
25         if(sum[i][j]+sum[k-1][l-1]-sum[i][l-1]-sum[k-1][j]==n) ans++;
26            cout<<ans<<endl;
27 }
我的一看就超时的代码
 1 #include <cstdio>
 2 #include <numeric>
 3 #include <iostream>
 4 #include <vector>
 5 #include <set>
 6 #include <cstring>
 7 #include <string>
 8 #include <map>
 9 #include <cmath>
10 #include <ctime>
11 #include <algorithm>
12 #include <bitset>
13 #include <queue>
14 #include <sstream>
15 #include <deque>
16 
17 using namespace std;
18 
19 #define mp make_pair
20 #define pb push_back
21 #define rep(i,n) for(int i = 0; i < (n); i++)
22 #define re return
23 #define fi first
24 #define se second
25 #define sz(x) ((int) (x).size())
26 #define all(x) (x).begin(), (x).end()
27 #define sqr(x) ((x) * (x))
28 #define sqrt(x) sqrt(abs(x))
29 #define y0 y3487465
30 #define y1 y8687969
31 #define fill(x,y) memset(x,y,sizeof(x))
32                          
33 typedef vector<int> vi;
34 typedef long long ll;
35 typedef long double ld;
36 typedef double D;
37 typedef pair<int, int> ii;
38 typedef vector<ii> vii;
39 typedef vector<string> vs;
40 typedef vector<vi> vvi;
41 
42 template<class T> T abs(T x) { re x > 0 ? x : -x; }
43 
44 const int N = 40000;
45 
46 int n;
47 int m;
48 string s;
49 
50 int cnt[N];
51 
52 int main () {
53     cin >> m >> s;
54     n = sz (s);
55     for (int i = 0; i < n; i++) {
56         int cur = 0;
57         for (int j = i; j < n; j++) {
58             cur += s[j] - '0';
59             cnt[cur]++;
60         }
61     }
62     ll ans = 0;
63     if (m == 0) {
64         int all = n * (n + 1) / 2;
65         ans += (ll)all * all - (ll)(all - cnt[0]) * (all - cnt[0]);
66     } else {
67         for (int i = 1; i * i <= m && i < N; i++)
68             if (m % i == 0 && m / i < N) {
69                 int j = m / i;
70                 if (i != j) ans += (ll)2 * cnt[i] * cnt[j]; else ans += (ll)cnt[i] * cnt[i];
71             }
72     }
73     cout << ans << endl;
74     return 0;
75 }
一号
 1 #include <algorithm>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <list>
 5 #include <map>
 6 #include <queue>
 7 #include <set>
 8 #include <stack>
 9 #include <vector>
10 #include <cmath>
11 #include <cstring>
12 #include <string>
13 #include <iostream>
14 #include <complex>
15 #include <sstream>
16 using namespace std;
17  
18 typedef long long LL;
19 typedef unsigned long long ULL;
20 typedef long double LD;
21 typedef vector<int> VI;
22 typedef pair<int,int> PII;
23  
24 #define REP(i,n) for(int i=0;i<(n);++i)
25 #define SIZE(c) ((int)((c).size()))
26 #define FOR(i,a,b) for (int i=(a); i<(b); ++i)
27 #define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
28 #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)
29 #define ALL(v) (v).begin(), (v).end()
30  
31 #define pb push_back
32 #define mp make_pair
33 #define st first
34 #define nd second
35 
36 LL gcd(LL a, LL b) {
37     return b ? gcd(b,a%b) : a;
38 }
39 
40 char S[5000];
41 int su[5000];
42 int main() {
43     int A;
44     scanf("%d", &A);
45     scanf("%s", S);
46     int N = strlen(S);
47     REP(i,N) S[i] -= '0';
48     
49     map<int,int> C;
50     su[0] = 0;
51     FOR(i,1,N+1) su[i] = S[i-1] + su[i-1];
52     
53     map<int,int> M;
54     REP(i,N+1)REP(j,i) M[su[i] - su[j]]++;
55 
56     if (A == 0) {
57         LL Y = (N + 1) * N / 2;
58         LL X = M[0];
59         cout << (Y * Y - (Y - X) * (Y - X)) <<  endl;
60         return 0;
61     }
62 
63     LL result = 0;
64     for (int a = 1; a * a <= A; ++a) {
65         if (A % a) continue;
66         LL X = M[a];
67         LL Y = M[A / a];
68     
69         result += X * Y;
70         if (a * a != A) result += X * Y;
71     }
72     
73     cout << result << endl;
74 }    
二号

 

转载于:https://www.cnblogs.com/yijiull/p/6804853.html

相关文章:

  • jsp相关笔记(二)
  • CPU组成
  • 【Java并发编程】:加锁和volatile变量
  • expdp/impdp 参数说明,中英对照
  • 数据结构第11周笔记
  • for...in
  • 自学前端开发 新版css时钟效果图
  • UVA10129 Play on Words —— 欧拉回路
  • [Apio2012]dispatching 左偏树
  • 杭电1007-----C语言实现
  • 解决云服务器ECS,windows server 2012不能安装SQL Server 2012,不能安装.NET Fromework 3.5...
  • 自适应相关知识点1
  • JavaScript 原型链
  • Mysql数据库批量添加数据
  • Spring MVC解决中文乱码(post get)(转)
  • python3.6+scrapy+mysql 爬虫实战
  • [微信小程序] 使用ES6特性Class后出现编译异常
  • 【Amaple教程】5. 插件
  • 〔开发系列〕一次关于小程序开发的深度总结
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • flask接收请求并推入栈
  • iOS 颜色设置看我就够了
  • Java|序列化异常StreamCorruptedException的解决方法
  • Java比较器对数组,集合排序
  • Quartz初级教程
  • 构造函数(constructor)与原型链(prototype)关系
  • 官方新出的 Kotlin 扩展库 KTX,到底帮你干了什么?
  • 漂亮刷新控件-iOS
  • 手写一个CommonJS打包工具(一)
  • 限制Java线程池运行线程以及等待线程数量的策略
  • Oracle Portal 11g Diagnostics using Remote Diagnostic Agent (RDA) [ID 1059805.
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • hi-nginx-1.3.4编译安装
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (zhuan) 一些RL的文献(及笔记)
  • (zt)最盛行的警世狂言(爆笑)
  • (附源码)springboot 校园学生兼职系统 毕业设计 742122
  • (接口封装)
  • (九)c52学习之旅-定时器
  • (三分钟了解debug)SLAM研究方向-Debug总结
  • (生成器)yield与(迭代器)generator
  • .NET DevOps 接入指南 | 1. GitLab 安装
  • .NET 发展历程
  • .net 开发怎么实现前后端分离_前后端分离:分离式开发和一体式发布
  • .NET 中选择合适的文件打开模式(CreateNew, Create, Open, OpenOrCreate, Truncate, Append)
  • .Net(C#)自定义WinForm控件之小结篇
  • .net反编译的九款神器
  • .NET精简框架的“无法找到资源程序集”异常释疑
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比
  • .NET是什么
  • .net网站发布-允许更新此预编译站点
  • /etc/motd and /etc/issue
  • [20181219]script使用小技巧.txt