题目链接: 题目 A. Reberland Linguistics time limit per test:1 second memory limit per test:256 megabytes 问题描述 First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university…
C. Reberland Linguistics     First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge…
A. Reberland Linguistics 题目连接: http://www.codeforces.com/contest/666/problem/A Description First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The educati…
C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talent…
题目链接: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…
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一个满足条件的四个点. 题解: 首先预处理出任意两点的最短距离,用队列优化的spfa跑:O(n*n*logn) 现依次访问四个点:v1,v2,v3,v4 我们可以枚举v2,v3,然后求出v2的最远点v1,v3的最远点v4,为了保证这四个点的不同,直接用最远点会错,v1,v4相同时还要考虑次最远点来替换…
题目链接:http://codeforces.com/contest/667/problem/D 给你一个有向图,dis[i][j]表示i到j的最短路,让你求dis[u][i] + dis[i][j] + dis[j][v]的最大值,其中u i j v互不相同. 先用优先队列的dijkstra预处理出i到j的最短距离(n^2 logn).(spfa也可以做) 然后枚举4个点的中间两个点i j,然后枚举与i相连节点的最短路dis[u][i](只要枚举最长的3个就行了),接着枚举与j相连节点的最短路…
B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Cicasso goes to a world tour! Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he…
题意:给一个初始串s,和m个模式串,q次查询每次问你第l到第r个模式串中包含\(s_l-s_r\)子串的最大数量是多少 题解:把初始串和模式串用分隔符间隔然后建sam,我们需要找到在sam中表示\(s_l-s_r\)子串的状态节点(先找到\(s_r\)对应的节点,然后倍增parent树即可),我们需要找到包含\(s_l-s_r\)的模式串,这些节点肯定在parent树上位于我们找到的状态节点的子树上.那么我们按sam的topo序进行线段树合并,线段树区间表示l,r模式串中最大匹配值以及下标.每次…
第一题直接算就行了为了追求手速忘了输出yes导致wa了一发... 第二题技巧题,直接sort,然后把最大的和其他的相减就是构成一条直线,为了满足条件就+1 #include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<iomanip> #…
D. World Tour   A famous sculptor Cicasso goes to a world tour! Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will en…
题目链接: 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…
题目: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 第三…
题目链接: 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…
原题连接: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…
C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right…