# Codeforces Round #213 (Div. 1)

13-11-26        来源：[db:作者]

A. Matrix

// Author : JayYe  Created Time: 2013-11-19 23:47:55
#include <stdio.h>
#include <string.h>
#include <map>
#include <algorithm>
using namespace std;
typedef __int64 ll;

const int maxn = 4000 + 5;

char s[maxn];
ll a[maxn][maxn];
ll b[maxn*maxn];
map<ll,int>    mp;

int main() {
ll n;
scanf("%I64d%s", &n, s + 1);
int len = strlen(s + 1), tot = 0;
for(int i = 1;i <= len; i++) {
a[i][i] = s[i] - '0';
b[tot++] = a[i][i];
mp[a[i][i]]++;
for(int j = i+1;j <= len; j++) {
a[i][j] = a[i][j-1] + s[j] - '0';
b[tot++] = a[i][j];
mp[a[i][j]]++;
}
}
ll ans = 0;
for(int i = 0;i < tot; i++) {
if(n == 0) {
if(b[i] == 0)
ans += tot;
else
ans += mp[0];
}
else if(b[i] != 0 && n % b[i] == 0) {
//            printf("%d %d\n", b[i], mp[n/b[i]]);
ans += mp[n / b[i]];
}
}
printf("%I64d\n", ans);
return 0;
}
来自CODE的代码片
A.cpp

B. Free Market

// Author : JayYe  Created Time: 2013-11-20 18:56:53
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 1000000 + 10;

bool vis[maxn];
int b[maxn], a[55];

int main() {
int n, d;
scanf("%d%d", &n, &d);
for(int i = 1;i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n + 1);
vis[0] = true;
int pre = 0;
for(int i = 1;i <= n; i++) {
bool flag = false;
for(int j = pre;j >= 0; j--) if(vis[j] && a[i] - j <= d) {
flag = true;
break;
}
if(!flag)    break;
for(int j = pre;j >= 0; j--) if(vis[j])
vis[j + a[i]] = true;
pre += a[i];
}
int tot = 0, ans = 0;
for(int i = 0;i <= pre;i ++) if(vis[i])
b[tot++] = i;
if(tot == 1)    return puts("0 0"), 0;
pre = 0;
for(int i = 0;i < tot; i++) {
if(pre + d < b[i]) {
ans++; pre = b[i-1];
}
}
ans++;
printf("%d %d\n", b[tot-1], ans);
return 0;
}
来自CODE的代码片
B.cpp