第一题:
题目大意就是需要给了t个函数f(x),每个函数f(x)是多个F函数的相加,
判断s(x)是不是收敛的。
思路:
如果s(x)是收敛的,那么每一个f(j)都必须的极限都必须等于0。但是F函数的所有可选项的极限再C不为0时都不为0。所以直接判断所有C是否等于0即可。C++快速处理字符串可以看我这篇博客:
https://editor.csdn.net/md/?articleId=115360326.
第11题:
Sample Input
1
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
..........................##...........##..........#####......########..........##......########....
.......#.......#..........###..........##.........#######.....########.........###......########....
.......#.......#..........###..........##........##....##..........###.........###......##..........
.......#.......#.........####..........##...............##........###.........####......##..........
....###############......####..........##..............##........###..........####......##..........
.......#.......#.........##.#..........##..............##.......###...........####......##..........
.......#.......#.........##.##.........##..............##.......#####........#####......#######.....
.......#.......#.........##.##.........##.............##........######.......##.##......########....
.......#.......#........###.##.........##............###............##......###.##............###...
.......#########........##..##.........##...........###.............##......##..##.............##...
.......#.......#........##...#.........##...........##..............##......##..##.............##...
.......#.......#........##...##........##..........###..............##.....##...##.............##...
.......#.......#........#######........##.........###.........##....##.....#########...........##...
.......#.......#.......########........##.........##..........##....##.....#########....##.....##...
.......#########.......##....##........##........###..........###...##..........##.......##...###...
.......#.......#.......##....##........##........########......######...........##.......#######....
.......................##.....##.......##........########.......####............##........#####.....
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
Sample Output
Case #1:
5 19
24 32
40 41
50 58
63 70
76 84
89 97
思路:
因为需要考虑到汉字(比如川)的情况,从后往前找到所有数字并记录汉字的右端点,然后再从左往右找汉字的左端点。
第二题:
题目大意:
就是求一棵树的任意一点到其他点的路径上的元素数量,然后把他用f函数处理一下输出。O(n^2)的复杂度可以过,针对树的特性优化一下DFS就行。
AC代码:
#include<iostream>
#include<vector>
#include<cstdio>
#define debug(x) cout<<x<<" "
#define MAX 2005
using namespace std;
typedef long long ll;
const int N = 2000;
const int b = 19560929;
const int M1 = 1e9 + 7;
const int M2 = 1e9 + 9;
vector<int > g[MAX];
int weight[MAX], a[MAX], _1[MAX], _2[MAX], cnt[MAX],sum;
void init() {
//生成权重数组
_1[1] = _2[1] = 1;
for (int i = 2; i <= N; i++) {
_1[i] = 1ll * _1[i - 1] * b % M1;
_2[i] = 1ll * _2[i - 1] * b % M2;
}
return;
}
void dfs(int v, int front) {
//v表示当前节点,front表示上一个节点
if (cnt[weight[v]] == 0) {
sum++;
}
a[v] = sum;
cnt[weight[v]]++;
for (int x : g[v]) {
if (x != front) {
//不是上一个节点
dfs(x, v);
}
}
cnt[weight[v]]--;
if (cnt[weight[v]] == 0) {
sum--;
}
return;
}
int main() {
int T;
cin >> T;
init();
while (T--) {
int v;
cin >> v;
for (int i = 2; i <= v; i++) {
int x;
scanf("%d", &x);
g[i].push_back(x);
g[x].push_back(i);
}
for (int i = 1; i <= v; i++) {
scanf("%d", &weight[i]);
}
for (int i = 1; i <= v; i++) {
ll h1=0, h2=0;
sum = 0;
dfs(i, -1);
for (int i = 1; i <= v; i++) {
h1 = (h1 + (1ll*_1[i] * a[i]) % M1) % M1;
h2 = (h2 + (1ll*_2[i] * a[i]) % M2) % M2;
}
printf("%lld %lld\n", h1, h2);
}
for (int i = 1; i <= v; i++) {
g[i].clear();
}
}
return 0;
}