1.题目大意 输入长度为n$(2\le n\le 100)$的环状DNA串,找出该DNA串字典序最小的最小表示. 2.思路 这题特别简单,一一对比不同位置开始的字符串的字典序,更新result. 3.代码 #include"stdio.h" #include"string.h" #define maxn 100 int judge(char* s,int p,int q) //比较p的字典序是否比q小 { int m=strlen(s); for(int i=0;…
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,…
题意  给你一个环形串   输出它以某一位为起点顺时针得到串的最小字典序 直接模拟   每次后移一位比較字典序就可以  注意不能用strcpy(s+1,s)这样后移  strcpy复制地址不能有重叠部分 #include<cstdio> #include<cstring> using namespace std; const int N = 150; char s[N], ans[N], c; int t, l; int main() { scanf ("%d"…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4459 题目意思:给出一个字符串,求出该字符串的最小字典序 暴力求解即可,用 ans 保存最小字典序的第一个字符的下标.(好像这方法有点慢,测试的时候,第二个 test 出来的答案好像要等那么一段时间 = =, 3s 应该挺够的) #include <iostream>…
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> #include<cstdlib> #include<cstring> #include <vector> #include <queue> #include <map> using namespace std; #define maxn 10010…
1.题目大意 如果a加上a的各个数字之和得到b,则说a是b的生成元.给出n其中$1\le n\le 100000$,求其最小生成元,若没有解则输出0. 2.思路 使用打表的方法打出各个数字a对应的b,存入s[b]中. 3.应注意的问题 (1) 没有解时输出0,也就意味着在开始打表前要把数组s[maxn]清零.利用memset实现,要加入string.h的头文件,而memset对数组操作时只能初始化为0或-1. (2) 要求求出的是最小生成元,也就意味着在存入s[b]之前要有所比较. 4.代码 #…
1.题目大意 比较给定序列和用户猜想的序列,统计有多少数字位置正确(x),有多少数字在两个序列中都出现过(y)但位置不对. 2.思路 这题自己思考的思路跟书上给的思路差不多.第一个小问题——位置正确的数字数量可以很容易求出,第二个小问题——在两个序列中都出现过但位置不对的数字数量则要由“y-x=在两个序列中都出现过的数字数量-位置正确的数字数量”得出. 3.应当注意的问题 (1)虽然思路大同小异,但是具体实现的过程中能否很好地实现则很考验人.最开始写这题的时候,我甚至定义了4个数组,这点在后来证…
sort3解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] 给你N,而后给出N个数,每个数都是1~3中的一个.请问,要把这个数列升序排好,最少需要进行几次两两交换?[数据范围] 1<=N<…
1.题目大意 把前n$(n\le 10000)$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更好的办法了,写完看了一下其它人的思路好像也差不多是打表的思路. 3.应注意的问题 (1)首先是格式问题,我第一次提交的时候PE了,因为没有意识到空格也会有影响.最开始我的最后一段代码是: for(i=0;i<10;i++) printf("%d ",s[n][i]); printf(…
1.题目大意 给出一个由O和X组成的字符串(长度为80以内),每个O的得分为目前连续出现的O的数量,X得分为0,统计得分. 2.思路 实在说不出了,这题没过脑AC的.直接贴代码吧.=_= 3.代码 #include"stdio.h" #include"string.h" #define maxn 80 int main() { int T,i,m,sum,c; char s[maxn]; scanf("%d",&T); while(T--…
1.题目大意 输入字符串,判断其是否为回文串或镜像串.其中,输入的字符串中不含0,且全为合法字符.以下为所有的合法字符及其镜像: 2.思路 (1)考虑使用常量数组而不是if或switch来实现对镜像的判断,由此避免过于繁琐的过程. (2)" -- is not a palindrome."," -- is a mirrored string."," -- is a regular palindrome."," -- is a mirro…
1.题目大意: 输入一个错位的字符串(字母全为大写),输出原本想打出的句子. 2.思路: 如果将每个输入字符所对应的应输出字符一一使用if或者switch,则过于繁琐.因此考虑使用常量数组实现. 3.应该注意的问题: (1) 在对常量数组赋值时,应考虑字符转义符的影响,反斜杠"\"的转义符应为"\\". (2) 小心控制访问数组的范围. 4.代码: #include"stdio.h" char s[] = "`1234567890-=Q…
1.题目大意: 输入两个整数L.H其中($1≤L≤H≤10^9,H−L≤10000$),统计[L,H]区间上正约数最多的那个数P(如有多个,取最小值)以及P的正约数的个数D. 2.原理: 对于任意的一个正整数N,若有$N=p_1^{e1}p^{e2}_2...p^{er}_r$ 且$p_1.p_2...p_r$都为素数,则有N的因数个数为$(e1+1)(e2+1)...(er+1)$. 3.范围确定 关于对maxn的确定,由$1≤L≤H≤10^9$可知:对 $10^9$ 开根号,大概估算一下,将…
1.题目描述: 1175. Strange Sequence Time limit: 1.0 secondMemory limit: 2 MB You have been asked to discover some important properties of one strange sequences set. Each sequence of the parameterized set is given by a recurrent formula: Xn+1 = F(Xn-1, Xn)…
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 - a2|,| a2 - a3…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/design-circular-deque/description/ 题目描述: Design your implementation of the circular double-ended queue (deque). Your implementation should support following op…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 用直的代替弯的 数组循环利用 日期 题目地址:https://leetcode.com/problems/design-circular-queue/description/ 题目描述 Design your implementation of the circular queue. The circular queue is a linear da…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/split-array-into-fibonacci-sequence/description/ 题目描述 Given a string S of digits, such as S = "123456579", we can split it into a Fib…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/permutation-sequence/description/ 题目描述 The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of th…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; ; int l, chance;…
Permutation Sequence https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123&…
题目 题目描述 给N个整数,每个整数只能是1,2,或3.现在需要对这个整数序列进行从小到大排序,问最少需要进行几次交换.N(1 <= N <= 1000) 样例输入 9 2 2 1 3 3 3 2 3 1 样例输出 4 解题思路 这个题目我没有做出来,想到一个思路,提交之后返回一个wa.后来看了一下题解,才知道自己错在什么地方.现在来回顾一下. 错误思路 我首先统计了1,2,3的个数,记为cnt1,cnt2,cnt3.然后统计在前cnt1个位置有多少个数字不是等于1的,统计在中间cnt2个位置…
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4.…
BZOJ 1367 [Baltic2004]sequence Description 给定一个序列\(t_1,t_2,\dots,t_N\),求一个递增序列\(z_1<z_2<\dots<z_N\),使得\(R=|t_1-z_1|+|t_2-z_2|+\dots+|t_N-z_N|\)的值最小,本题中,我们只需求出这个最小的\(R\)值 Input 第\(1\)行为\(N(1\le N\le10^6)\) 第\(2\)行到第\(N+1\)行,每行一个整数.第\(K+1\)行为\(t_k(…
Time Limit:1000MS     Memory Limit:32768KB Description ​A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n). Input The input consists of mult…
P4597 序列sequence 题目背景 原题\(\tt{cf13c}\)数据加强版 题目描述 给定一个序列,每次操作可以把某个数\(+1\)或\(-1\).要求把序列变成非降数列.而且要求修改后的数列只能出现修改前的数. 输入输出格式 输入格式: 第一行输入一个\(n\),表示有\(n(n \leq 5\times10^5)\)个数字. 第二行输入\(n\)个整数,整数的绝对值不超过\(10^9\) 输出格式: 输出一个数,表示最少的操作次数 发现之前洛谷做过一个类似的..P2893 che…
题目链接1 题目链接2 题目大意 给出一个括号序列,添加最少的括号使序列正确 解题思路 先将问题简单化,从求序列退化为求最小添加括号数的问题 用区间dp n³解决 f[l][r]表示使第l个到r个区间正确的最小添加数 1 :当l = r时, f[l][r] = f[l+1][r-1] 2 :  在l到j中,枚举中间点k,则f[l][r] = min (f[l][r], f[l][k] + f[k+1][r]) 求出了最小添加括号数后,再来思考完整的问题 用递归解决输出方案 假设有一个 从 l 到…
题目链接:(这个是内网的网址)  http://172.22.27.1/problem?pid=1013 Good Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStatistic Next Problem Problem Description A sequence contains n integers. A sequence p1, p2,…
题目链接: http://172.16.0.132/senior/#main/show/5437 题目: 题解: 发现满足上述性质并且仅当A序列的子序列的差分序列与B序列的差分序列相同 于是我们把A变成差分序列,把B变成差分序列,做一次KMP就好了 #include<algorithm> #include<cstring> #include<cstdio> #include<iostream> using namespace std; ; int n,m;…
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…