UVa 1328 Period】的更多相关文章

数据范围较大,故用KMP求循环节 之后由小到大枚举长度范围,若该长度下有循环节就输出答案 还要注意输出格式.之前测试时候连着一串presentation error也是悲伤 #include<bits/stdc++.h> using namespace std; ]; ]; int n; void kmp(char s[]){ ne[]=;//题目要求最小循环长度为2 ne[]=; int i,j; ;i<n;i++){ j=ne[i]; while(j && c[i]!…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36131 题意:给出一个长度为n的字符串,要求找到一些i,满足说从1~i为多个个的重复子串构成,并输出子串的个数. 题解:对kmp中预处理的数组的理解 //作者:1085422276 #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #i…
https://vjudge.net/problem/UVA-1328 题意 求每个前缀的最小循环节,要求至少循环两次且为完整的. 分析 求next数组,i-next[i]即为前缀i的最小循环节,再判断一下限制条件即可. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorit…
当初学KMP的时候也做过这道题,现在看来还是刘汝佳的代码要精简一些,毕竟代码越短越好记,越不容易出错. 而且KMP的递推失配函数的代码风格和后面的Aho-Corasick自动机求失配函数的代码风格也是一致的. #include <cstdio> + ; char s[maxn]; int f[maxn]; //失配函数 int main() { //freopen("in.txt", "r", stdin); ; && n) { getc…
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=4117&mosmsg=Submission+received+with+ID+13583667">1371 - Period 题意:给定两个字符串.能够把第二个字符串分成若干份,然后由第一个字符串去操作得到每一个分出来的字符串,代价为当中的最大值,要求代价的最小值 思路:第一个字符串长度为50,所以答案肯…
思路:设字符串x的长度为n,y的长度为m,那么答案一定在[0, m]之间,那么可以二分求答案. d(i, j)表示第一个串前i个字符至少需要经过多少次才能的到第二个串的前j个字符,转移方程d(i, j) = min{d(i-1, j-1) + is_same(a[i], b[j]), d(i-1, j) + 1, d(i, j-1) + 1}; 如何判断某个答案mid是否合理?当a串中连续k个字符能够在mid次操作类转换成第二个串,就把d(k, 0)变成0即可. AC代码 #include <c…
Code: #include<cstdio> #include<cstring> using namespace std; const int maxn=1000000+5; char S[maxn]; int f[maxn]; void getfail(char p[],int n) { f[0]=0,f[1]=0; for(int i=1;i<n;++i) { int j=f[i]; while(j&&p[i]!=p[j])j=f[j]; f[i+1]=p…
UVa 10387- Billiard Table of Contents 1 题目 2 思路 3 代码 4 参考 1 题目 ============= Problem A: Billiard In a billiard table with horizontal side  a  inches and vertical side  b  inches, a ball is launched from the middle of the table. After  s  > 0 seconds…
 Always on the run Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 590 Appoint description:  System Crawler  (2015-08-26) Description   Screeching tires. Searching lights. Wailing sirens. Police cars…
UVa 10618 Tango Tango Insurrection 题目: Problem A: Tango Tango Insurrection You are attempting to learn to play a simple arcade dancing game. The game has 4 arrows set into a pad: Up, Left, Down, Right. While a song plays, you watch arrows rise on a s…
UVa 1412 Fund Management 题目: UVA - 1412 Fund Management Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description   Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fu…
UVA - 1153 Keep the Customer Satisfied Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description   Simon and Garfunkel Corporation (SG Corp.) is a large steel-making company with thousand of customers. Keeping the customer…
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life. A new idea Bill has recently developed assigns a non-negat…
Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16786   Accepted: 4627 Case Time Limit: 1000MS   Special Judge Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated…
Cancer or Scorpio Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3098 Description Alice and Michael is a young couple who are planning on having their…
option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank" style="">题目链接:uva 1203 - Argus 题目大意:一个成为Argus的系统.支持一个Register命令 Register Q_num Period 该命令为一个祖冊出发器,每Period产生一次Q_num的时间.要求模拟k个事件,假设多个事件同一…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2629 题意: 输入两个非负整数a.b和正整数n(0≤a,b<2^64,1≤n≤1000),你的任务是计算f(a^b)除以n的余数.其中f(0)=0,f(1)=1,且对于所有非负整数i,f(i+2)=f(i+1)+f(i). 分析: 所有计算都是对n取模的,设F(i)=f(i)…
UVa OJ 455 Periodic Strings A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string "abcabcabcabc" has period 3, since it is formed by 4 repe…
我们一数据库服务器上有个作业最近几天偶尔会遇到下面错误(敏感信息已做处理),主要是报"TCP Provider: The semaphore timeout period has expired. [SQLSTATE 07008] (Error 121)  OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Communication link failur…
今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred within the report server database.  This may be due to a connection failure, timeout or low disk condition within the database.;".检查C:\Program Files\Micro…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5…
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径. f[i][j][k]从下往上到第i层第j个和为k的方案数 上下转移不一样,分开处理 没必要判断走出沙漏 打印方案倒着找下去行了,尽量往左走   沙茶的忘注释掉文件WA好多次   #include <iostream> #include <cstdio> #include <a…
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求LCS,转移同时维护f[i][j].s为当前状态字典序最小最优解 f[n][n].s的前半部分一定是回文串的前半部分(想想就行了) 当s的长度为奇时要多输出一个(因为这样长度+1,并且字典序保证最小(如axyzb  bzyxa,就是axb|||不全是回文串的原因是后半部分的字典序回文串可能不是最小,多…
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问题 |00|+|01|=|0| 注意序列是环形 // // main.cpp // poj3869 // // Created by Candy on 25/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <i…
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 // // Created by Candy on 24/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <cst…
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll…
UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这次转移会给其他的元素带来的代价,也就是转移前已经出现但还没结束的元素都会代价+1   预处理每种颜色在两个序列中出现的位置bg[i][0/1]和ed[i][0/1], 计算f[i][j]时同时计算w[i][j]为(i,j)这个状态已经出现还没结束的个数 注意bg要先初始化为INF,计算w: if(b…
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4053   Accepted: 1318 Description The binomial coefficient C(m,n) is defined as m! C(m,n) = -------- n!(m-n)! Given four natural numbers p, q…
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is the same written forwards and backwards. For example, ‘racecar’ is a palindrome, but ‘fastcar’ is not. A partition of a sequence of characters is a lis…
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After several thrilling events we find her in the first station of Algorithms City Metro, examining the time table. The Algorit…