随笔分类 -  杂题

摘要:考虑对立情况,不漂亮的串的形式必然为GGGGR……R……RGGGG相邻R之间的距离为奇数且相等。#include #include #include #define LL long long intusing namespace std;const int MAXN = 888;const LL MOD = 1000000007;char str[MAXN];int main(){ int T; scanf( "%d", &T ); while ( T-- ) { scanf( "%s", str ); int len = strlen(st.. 阅读全文
posted @ 2013-10-04 22:59 冰鸮 阅读(319) 评论(0) 推荐(0)
摘要:M=1:aaaaaaaa……M=2:DFS+manacher, 暴出N=1~25的最优解,找规律。N8时,头两个字母一定是aa,剩下的以aababb循环,最后剩余#include using namespace std;const char str[] = "aababb";int main(){ int T; int cas = 0; scanf( "%d", &T ); while ( T-- ) { int M, N; scanf( "%d%d", &M, &N ); printf("Case 阅读全文
posted @ 2013-09-14 21:54 冰鸮 阅读(256) 评论(0) 推荐(0)
摘要:统计正面看高度为i的竖条个数为cnt1[i],统计侧面看高度为i的竖条个数为cnt2[i];ans = sum( i * max( cnt1[i], cnt2[i] ) ); ( 1 #include #include #include using namespace std;int cnt1[30];int cnt2[30];int main(){ int W, D; while ( scanf( "%d%d", &W, &D ), W || D ) { memset( cnt1, 0, sizeof(cnt1) ); memset( cnt2,... 阅读全文
posted @ 2013-09-11 20:54 冰鸮 阅读(258) 评论(0) 推荐(0)
摘要:训练指南p.59#include #include #include #include using namespace std;const int MAXN = 30;int N;int A[MAXN];char str[1010];map table;int bitcount( int x ){ int res = 0; while ( x ) { if ( x & 1 ) ++res; x >>= 1; } return res;}int main(){ while ( scanf( "%d", &N ) == 1 ) ... 阅读全文
posted @ 2013-09-09 16:33 冰鸮 阅读(275) 评论(0) 推荐(0)
摘要:假设最少删除的边的个数为cost,显然,最终答案即为cost+cost+1 (因为删除一条边,就会增加一个链,所以删除cost条边后,就会有cost+1条链,将这cost+1条链连接起来的代价为cost+1, 删除cost条边的代价为cost,所以总代价为cost+cost+1)求最少删除的边数:首先我们定义一棵子树中的链不能以该子树的根为端点,以下提到的所有链均必须满足这个条件。设一棵以节点i为根的子树中,叶子节点的个数为duan,并设i的父亲为fa。那么,这棵子树至少会分割成duan-1条链(以其中两个叶子为端形成一条链,剩下的一个叶子对应一条链)。DFS,对于某棵以节点i为根的子树,如果 阅读全文
posted @ 2013-09-08 21:55 冰鸮 阅读(456) 评论(0) 推荐(0)
摘要:设串C的第一个字母在串A中出现的位置是stA, 串C的最后一个字母在串A中出现的位置是edA。设串C的第一个字母在串B中出现的位置是stB, 串C的最后一个字母在串B中出现的位置是edB。求出每一对合法的(stA, edA),(stB, edB)对每一组( stA[i], edA[i] ) 和 ( stB[j], ed[j] ), 求串A[0,stA[i]-1]和串B[0, stB[j]-1]的最长公共子序列长度L1,求串A[edA[i]+1, lenA-1]和串B[stB[j]+1, lenB-1]的最长公共子序列长度L2, 答案为max( lenC+L1+L2 )……现在看看自己赛场上写的 阅读全文
posted @ 2013-08-15 23:04 冰鸮 阅读(322) 评论(0) 推荐(0)
摘要:负载是否平衡只与前两列有关,剩下的只要与前两列不重复就随便放。第一列我们按1-n这样循环放,第二列每次找个数最少的那个服务器放。#include #include #include using namespace std;const int MAXN = 110;int N, M;int mat[MAXN][MAXN];int cnt[MAXN];int ori[MAXN];bool vis[MAXN];void show(){ for ( int i = 1; i N ) j = 1; } solved(); show(); } ... 阅读全文
posted @ 2013-08-15 21:32 冰鸮 阅读(173) 评论(0) 推荐(0)