题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二点 gcd(a[i],a[i-1])>1 也就是说两个数不能互质 找出最长的子序列长度 思路:首先想互质问题,如果两个数互质说明两个数之间没有素因子相同,我们想以每个素因子结尾的最大长度是多少 然后比如样例 2 3 4 6 9 第一个数 2      2结尾 1 第二个数 3      3结尾 1 第三…
题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #include <cmath> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef unsigned long long ull; int…
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记忆化搜索记忆,vis数组标记那些已经访问过的状态. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define REP(i, a, b) for (i…
A. Colorful Stones (Simplified Edition) 模拟. B. Roadside Trees (Simplified Edition) 每次转移时,只需要爬到\(min(h_i,h_{i+1})\)位置,然后跳到下一个位置即可. C. Escape from Stones 当\(s_i=l\)时,先输出左边的数,否则先输出\(i\),在处理右边的数. D. Good Sequences \(a_i<a_{i+1}\),那么对于每个\(a_i\)找到所有质因子中最长的…
B. Making Sequences is Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For exampl…
A. Colorful Stones (Simplified Edition) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You a…
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_2, ..., a_n (1 ≤ a_i)\). $ 1.$ $gcd(a_1, a_2, ..., a_n) = x $ $ 2.$ \(\sum_{i=1}^{n}a_i = y\) 题解: 可以发现,当\(y\%x!=0\)时,满足条件的序列不存在.让\(f(t)\)表示满足序列和为的 \(t…
题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 0 36 4 题意 给一串数,用这n个数排几种序列,使得 i=1~(n-1) 输出有几种序列满足情况 题解 附  : & -- 位运算之一,有0则0 不用怀疑,一堆数&完后,得到的数<=这堆数的任意一个数 因为每一位只要有一个数==0,这一位就=0,否则为1 记最后&完所有数的…
题目链接 题目大意 给你一个长为n的数组a,要你构造一个非严格单调上升的数组b和一个非严格单调下降的数组c,使得\(b_i+c_i=a_i\) 要你使这两个数组b,c中最大的元素最小,还有q次修改(q<=1e5),每次修改使[l,r]上的所有元素加x.在线查询 题目思路 看到这个区间操作,在线查询,就能想到线段树qwq,结果居然是差分 假设现在已经确定了\(b[1]\)\(c[1]\). 假设\(a[2]\)大于\(a[1]\)而\(b[2]+c[2]=a[2]\) 显然是想要b数组的每一个元素…
题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The gi…
C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for hi…
B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't m…
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. 简单dp,dp[i]表示取i时zui最大和为多少,方程为dp[i] = max(dp[i - 1] , dp[i - 2] + cont[i]*i). #include <bits/stdc++.h> using namespace std; typedef __int64 LL; ; LL a…
B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/B Description Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such…
D. Dreamoon and Binary time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Dreamoon saw a large integer x written on the ground and wants to print its binary form out. Dreamoon has accomplishe…
A. Help Farmer 题目连接: http://www.codeforces.com/contest/142/problem/A Description Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocki…
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and m…
题目链接: http://codeforces.com/contest/429/problem/B B. Working out time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym w…
G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter widt…
C. Remembering Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/543/problem/C Description You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings ar…
C. Fragile Bridges 题目连接: http://codeforces.com/contest/201/problem/C Description You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you'v…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. 题解: 就首先预处理一下每个点在哪些时刻会被车子占领,然后从右向左dp一下就好 代码: #include<iostream> #include<cstring> #include<string> #include<vector> #include<alg…
题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下标 \(i\),\(p_i\)大于所有 \(p_j\),\(j\epsilon[1,i-1]\)同时大于所有\(p_i\),\(j\epsilon[i+1,i+k]\).问你满足这样条件的排列有多少种? 题解: 设\(dp[i]\)表示以 \(i\) 结尾的,满足题目要求的\(1\) ~ \(i\)…
E https://codeforces.com/contest/1154/problem/E 题意 一个大小为n(1e6)的数组\(a[i]\)(n),两个人轮流选数,先找到当前数组中最大的数然后选择以这个数为半径k的所有数,问两个人的选数情况 题解 set维护剩下数的最大 链表维护左右第一个存在的数的位置 代码 #include<bits/stdc++.h> #define MAXN 200005 using namespace std; int n,k,a[MAXN],p[MAXN],L…
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价值为s 题解:min(s/n,a)*n+b>=s?YES:NO #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm>…
题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后能够得到该排列. 题解 将原排列拆分为一个个连续子序列,每次从大于上一子序列首部的元素处分出下一连续子序列,只要将这些子序列按照拆分先后排列,归并排序后一定可以得到原排列. 之后即判断能否将这些子序列排列为两个长为 $n$ 的序列即可,可以用状压 $dp$,也可以用 $01$ 背包. 状态 $dp$…
题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结点 $u$ 有 $1$ 个子结点,添加 $2$ 个子结点 如果结点 $u$ 有 $3$ 个子结点,跳过该结点 如: \begin{equation} level = 1, 2, 3,4 \end{equation} 爪形结构如下: 问可以在 $level_n$ 选出几个互不相交的爪形结构. 题解 衍…
题意: 给两个串S,T,问能找出多少的S的(a1,b1)(a2,b2)..(ak,bk),使Sa1---Sb1,...Sak---Sbk都包含子串T,其中k>=1,且(a1,b1)...(ak,bk)互不相交. 比如S = "abacaba",T="aba", 当k=1时,(0,6)满足,还有其他只包含一个aba串的也满足,k-2时,(0,2)(3,6)满足,(0,2)(4,6)也满足,(0,3)(4,6)也满足,所以总共有12种. 解法:dp.先用kmp找出…
C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers w…