原题链接 CF 127个测试点,好评 简要题意: 多组数据,问数组中是否有长度 \(\geq 3\) 的回文子序列. 我们需要找到本质. 题目不让我们求这个长度,只让我们判断,这是为什么呢? 如果答案是 YES,那么必然存在一个长度为 \(3\) 的回文子序列.否则为 NO. 你想,如果原数组的最长回文序列是奇数的话,只要每次在两边同时删去一个,就可以得到长度为 \(3\) 的回文子序列. 如果是偶数,只要每次在两边同时删去一个,再在最中间两个任意删去一个,也可以得到长度为 \(3\) 的回文子…
http://poj.org/problem?id=2826 题目大意:给两条线,让它接竖直下的雨,问其能装多少横截面积的雨. ———————————————————————————— 水题,看题目即可知道. 但是细节是真的多……不过好在两次AC应该没算被坑的很惨(全程没查题解). 推荐交之前看一下讨论版的数据,方便一次AC(我第一次就是作死直接交了结果我自己都想好的情况忘了写了……) 相信看到这篇题解的人都看过题了,那么先说细节: 1.C++提交(G++不知道为什么WA了……) 2.精度 3.…
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1…
看到Palindrome的题目.首先想到的应该是中心问题,然后从中心出发,思考怎样解决. DP问题通常是从更加小的问题转化到更加大的问题.然后是从地往上 bottom up地计算答案的. 能得出状态转移方程就好办了,本题的状态转移方程是: if (cowID[i] == cow{j]) tbl[id][i] = tbl[id][i+1];//相等的时候无需修改 else tbl[id][i] = min(tbl[!id][i+1] + cost[cowID[i]-'a'], tbl[!id][i…
前言 这道题比较简单,但我还是想了好一会 题意简述 Abu Tahun很喜欢回文. 一个数组若是回文的,那么它从前往后读和从后往前读都是一样的,比如数组\(\left\{1\right\},\left\{1,1,1\right\},\left\{1,2,1\right\},\left\{1,3,2,3,1\right\}\)都是回文数组,但是数组\(\left\{11,3,5,11\right\},\left\{1,12\right\}\)不是回文的. Abu Tahun有个包含\(n\)个整数…
You are given an array aa consisting of nn integers. Your task is to determine if aa has some subsequence of length at least 33 that is a palindrome. Recall that an array bb is called a subsequence of the array aa if bb can be obtained by removing so…
题目 For a given positive integer n, please find the saallest positive integer x that we can find an integer y such that \(y^2 = n +x^2\). 输入 The first line is an integer \(T\), which is the the nuaber of cases. Then T line followed each containing an…
题目链接:https://www.luogu.org/problemnew/show/UVA101 这题码量稍有点大... 分析: 这道题模拟即可.因为考虑到所有的操作vector可最快捷的实现,所以数组动态vector.每一种情况分别考虑. 其他的见代码注释 部分过长的注释防在这里,请对照序号到代码中查看. ①:wa意为a的位置,记录当前a所在位置的序号. wb意为b的位置,记录当前b所在位置的序号. ca意为a的层数,记录当前a所在这堆积木中第几个. cb意为b的层数,记录当前b所在这堆积木…
达哥送分给我我都不要,感觉自己挺牛批. $type=0:$ 跟visit那题类似,枚举横向移动的步数直接推公式: $ans=\sum C_n^i \times C_i^{\frac{i}{2}} \times C_{n-i}^{\frac{n-i}{2}},i\% 2=0$ $type=1:$ 因为不能触碰负半轴,所以可以把右移看成+1,左移看成-1,转化为前缀和大于等于0的问题 于是直接Catalan数就好了.注意是第$\frac {n}{2}$项的Catalan. $Catalan_n=C_…
题意 f(u,v):x小于等于u且y小于等于v的点才对f有贡献,每个这样的点贡献(u-x)+() 思路 =f(u_2,v_2)" class="mathcode" src="https://private.codecogs.com/gif.latex?u_1%20%5Cge%20u_2%20%5C%3B%20and%20%5C%3B%20v_1%20%5Cge%20v_2%20%5Cquad%20%5CRightarrow%20%5Cquad%20f%28u_1%2…
原题链接 简要题意: 再简要一波: 每次可以把一个数增加 \(2\),问最后能不能让所有数相等.(也就是抵消掉) 什么?题意变成这样子还做个啥? 你会发现,必须所有数的奇偶性都相同,才可以:反之就不可以. 这结论不用证明了,因为每次增加不会改变奇偶性的. #pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; inline int read(){char ch=getchar();int f=1;while(ch…
题意: 问一个数组中是否存在至少长为3的回文子数组(按下标排列,可不连续). 思路: 找三个相同数或两个不连续的相同数. #include <bits/stdc++.h> using namespace std; const int M=5500; void solve(){ int last[M]={0},cnt[M]={0}; int n;cin>>n; int a[n+1];for(int i=1;i<=n;i++) cin>>a[i]; for(int i…
Content 给定一个数 \(n\),求它最多能够拆分成多少个质数,并输出拆分成的每一个质数. 数据范围:\(2\leqslant n\leqslant 10^5\). Solution 我们考虑尽可能地用小的数拆分. 由样例 \(2\) 可知,拆分成的质数可以重复,那么就考虑用最小的两个-- \(2\) 和 \(3\),来拆分. 我们通过奇偶性来分类讨论: 当 \(n\) 为奇数,此时我们可以考虑 \(n-3\) 用 \(\dfrac{n-3}{2}\) 个 \(2\) 来拆分,最后用 \(…
Content 给定 \(n,m\),你需要输出一个长度为 \(n\) 的排列,满足该排列进行不超过 \(m\) 次交换操作可以得到的最小的字典序最大. 数据范围:\(T\) 组数据,\(1\leqslant T\leqslant 10^5\),\(1\leqslant n\leqslant 10^5\),\(\sum n\leqslant 10^5\),\(0\leqslant m\leqslant n\). Solution 算是一道比较小清新的构造题,接下来教你如何弄出正确的构造方案. 首…
Content 若一个素数可以用比它小的相邻的两个素数的和加 \(1\) 表示,那么称这个素数为"好素数". 给定两个正整数 \(n,k\),问从 \(2\) 到 \(n\) 的好素数个数是否 \(\geqslant k\). 数据范围:\(2\leqslant n\leqslant 1000,0\leqslant k\leqslant 1000\). Solution 直接通过埃氏筛得到 \(1000\) 以内的素数,再通过直接暴力枚举预处理出 \(1000\) 以内的"好…
题意 给定一个长度为 \(n\) 的序列 \(a\) 以及一个长度为 \(m\) 的字符串 \(s\),初始 \(s\) 均为 \(\text{B}\),第 \(i\) 次操作可以把 \(s_{a_i}\) 或 \(s_{m+1-a_i}\) 修改为 \(\text{A}\),求修改过后的字典序最小的 \(s\). 思路 因为要使字典序最小,所以要让 \(\text A\) 尽量靠前,所以会出现以下几种情况: 设当前更改位置为第 \(i\) 位,若 \(s_i\) 和 \(s_{m+1-i}\)…
题目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using…
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also…
D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make a…
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also…
Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以某个位置为结束的回文串有多少个(manacher + 差分),因为要求s串选取的要多一点.这道题是个痛啊...当时的金牌题,不会EXKMP可以用二分+字符串hash啊,比赛前的暑假还写过,比赛时就没想到,还以为KMP可以搞出这个东西, 然后就三个人一起自闭地调KMP,说到底还是菜呀. 代码: #pr…
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2017-10-13       Latest Modification: 2018-02-28 #include<bits/stdc++.h> using namespace std; int a,b; int main() { cin>>a>>b; cout<<…
目录 题目链接 题解 代码 题目链接 CF868F. Yet Another Minimization Problem 题解 \(f_{i,j}=\min\limits_{k=1}^{i}\{f_{k,j-1}+w_{k,i}\}\) \(w_{l,r}\)为区间\([l,r]\)的花费,1D1D的经典形式 发现这个这是个具有决策单调性的转移 单无法快速转移,我们考虑分治 对于当前分治区间\([l,r]\) ,它的最优决策区间在\([L,R]\)之间. 对于\([l,r]\)的中点\(mid\)…
Palindrome Partitioning 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/palindrome-partitioning/description/ Description Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitio…
[BZOJ3218]a + b Problem 题解:思路很简单,直接最小割.S->i,容量为Bi:i->T,容量为Wi:所有符合条件的j->new,容量inf:new->i,容量Pi. 但是符合条件的j有很多,并且限制有二维,所以用可持久化线段树优化建图即可. #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <…
A palindrome is a string that reads the same forward and backward, for example, radar, toot, and madam. In this lesson we discuss how to approach the palindrome problem using TypeScript / JavaScript. We also discuss a more complex algorithmic challen…
解题过程 开场开A,A题shl看错题意,被制止.然后开始手推A,此时byf看错E题题意,开始上机.推出A的规律后,shl看了E题,发现题意读错.写完A题,忘记判断N=0的情况,WA+1.过了A后,shl重新写E,lfw开始开J题,E题过不了样例,lfw多次起立让shl调试,然后shl拿到E的一血,lfw之后过了J.byf开始开I题,shl口胡出M做法,然后lfw和shl一起推G题.byf过了I题后,shl推出G题,byf去写.然后lfw开始计算几何,经过查错后过掉,然后shl开始开M题,过掉后还…
(A) Even Subset Sum Problem 题解:因为n非常非常小,直接暴力枚举所有区间即可. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef double db; int t,l,r,n,a[110],s[110]; int main(){ cin>>t; while(t--){ cin>>…
最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. Longest Palindrome 给出一个包含大小写字母的字符串.求出由这些字母构成的最长的回文串的长度是多少. 数据是大小写敏感的,也就是说,"Aa" 并不会被认为是一个回文串 输入 : s = "abccccdd" 输出 : 7 说明 : 一种可以构建出来的最长回…
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many peopl…