2016.10.20 [ TEST 30 ] 总结
来源:互联网 发布:苏州团扇李晶淘宝店 编辑:程序博客网 时间:2024/05/16 05:43
一.第二饭堂
定义一个长度为
根据定义,不是回文串的字符串(包括空串)价值为
现在给定一个回文串,要求求出其所有前缀的价值和。
例:
根据其定义我们可以的出这样一个结论:设
本题数据不强,
p.s. 某神犇写了马拉车……_ (:3_|<) _厉害了word哥
#include <stdio.h>#include <string.h>#define hash 107long long l, r, pow = 1, ans, f[ 5000005 ], len;char ch[ 5000005 ];int main(){ freopen("hw.in", "r", stdin); freopen("hw.out", "w", stdout); scanf("%s", ch+1); len = strlen( ch+1 ); for(int i = 1; i <= len; i++) { l = l * hash + ch[ i ]; r = r + ch[ i ] * pow; pow *= hash; if(l == r) f[ i ] = f[ i/2 ] + 1; ans += f[ i ]; } printf("%lld\n", ans); return 0;}
以为用
二.数字
定义一个数字是好数字,当且仅当满足:
1.有
2.构成它的每个数字都在给定的集合
3.它的前
已知
由条件3合法数字要求前
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define mod 999983const int inf = ~0u>>1;int n, len_s, c[ 15 ], vis[ 15 ], cnt, maxn = -inf;long long ans, t1, t2, f[ 1001 ][ 10001 ];char s[ 15 ];int main(){ freopen("digit.in","r",stdin); freopen("digit.out","w",stdout); scanf("%d", &n); scanf("%s", s + 1); len_s = strlen( s+1 ); for(int i = 1; i <= len_s; i++) if(!vis[ s[ i ] - '0' ]) { c[ ++cnt ] = s[ i ] - '0'; vis[ s[ i ] - '0' ] = 1; maxn = max(maxn, c[ cnt ]); } f[ 0 ][ 0 ] = 1; for(int i = 0; i < n; i++) for(int j = 0; j <= maxn*i; j++) for(int k = 1; k <= cnt; k++) ( f[ i + 1 ][ j + c[ k ] ] += f[ i ][ j ] ) %= mod; for(int i = 0; i <= maxn * n; i++) (ans += f[ n ][ i ] * f[ n ][ i ]) %= mod; (ans <<= 1) %= mod; int a = (n+1) >> 1; int b = n >> 1; for(int i = 0; i <= a * maxn; i++) (t1 += f[ a ][ i ] * f[ a ][ i ]) %= mod; for(int j = 0; j <= b * maxn; j++) (t2 += f[ b ][ j ] * f[ b ][ j ]) %= mod; ans -= t1 * t2; printf("%lld\n", (ans % mod + mod) % mod); return 0;}
三.树上三角形
给定一棵
如果我们考虑选择哪三个点构成三角形,显然这种方法是复杂而不可行的,正难则反,考虑什么样的数列可以使不合法的数尽量多。
假设有三点权值
#include <stdio.h>#include <algorithm>using namespace std;int n, q, w[ 100001 ], t, a, b, s, e;struct tree{ int to,next;}edge[ 200001 ];int head[ 100001 ],tot;void insert(int x, int y){ edge[ ++tot ].to = y; edge[ tot ].next = head[ x ]; head[ x ] = tot; edge[ ++tot ].to = x; edge[ tot ].next = head[ y ]; head[ y ] = tot;}int fa[ 100001 ],dep[ 100001 ],cnt;long long que[ 100001 ];void dfs(int x, int y){ dep[ x ] = dep[ y ] + 1;fa[ x ] = y; for(int i = head[ x ]; i; i = edge[ i ].next) if(edge[ i ].to != y) dfs(edge[ i ].to,x);}void query(int x, int y){ cnt = 0; if(dep[ x ] < dep[ y ]) swap(x, y); while(cnt<=50 && dep[ x ] != dep[ y ]) { que[ ++cnt ] = w[ x ]; x = fa[ x ]; } while(cnt <= 50 && x != y) { que[ ++cnt ] = w[ x ]; que[ ++cnt ] = w[ y ]; x = fa[ x ];y = fa[ y ]; } que[ ++cnt ] = w[ x ]; if(cnt >= 50) { printf("Y\n"); return; } sort(que + 1, que + cnt + 1); for(int i = 1; i + 2 <= cnt; i++) if(que[ i ] + que[ i+1 ] > que[ i+2 ]) { printf("Y\n"); return; } printf("N\n"); return;}int main(){ freopen("tree.in","r",stdin); freopen("tree.out","w",stdout); scanf("%d%d",&n,&q); for(int i = 1; i <= n; i++) scanf("%d", &w[ i ]); for(int i = 1; i < n; i++) { scanf("%d%d", &s, &e); insert(s, e); } dfs(1, 0); for(int i = 1; i <= q; i++) { scanf("%d%d%d", &t, &a, &b); if(t) w[ a ] = b; else query(a, b); } return 0;}
p.s.注意点权可以卡到
- 2016.10.20 [ TEST 30 ] 总结
- Team Test单元测试总结
- Unit test学习总结
- ruby test::unit assert总结
- Unit test 学习总结 (一)
- Unit test 学习总结(二)
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- C++ Google Test 学习心得总结-1
- Boost Test学习总结(C++)
- Spring Test 整合 JUnit 4 使用总结
- Spring Test 整合 JUnit 4 使用总结
- Scroller的学习
- oracle ORA-00936: missing expression 报错的几种情况和解决方法
- Docker四种网络模式
- sqlserver中,insert into XXX values(N'xxx'),这里N的意思!
- httpclient详解(一)
- 2016.10.20 [ TEST 30 ] 总结
- 简单实现回复功能
- 谈KVC、KVO(重点观察者模式)机制编程
- 泉水
- Git命令行
- Spring modules介绍
- Linux dirname、basename 指令
- 计算机网络练习题
- ArcEngine开发常见报错原因分析及解决方法