ls特别喜欢素数,他总是喜欢把素数集合的所有子集写下来,并按照一定的顺序和格式.对于每一个子集,集合内 的元素在写下来时是按照升序排序的,对于若干个集合,则以集合元素之和作为第一关键字,集合的字典序作为第 二关键字(先比较集合第一个元素,再比较第二个元素,以此类推),这个序列的开始如下:[2], [3], [2, 3],  [5], [2, 5], [7], [3, 5], [2, 7], [2, 3, 5], [3, 7], [11], [2, 3, 7], [5, 7], [2, 11],…
Gennady and Georgiy are playing interesting game on a directed graph. The graph has n vertices and m arcs, loops are allowed. Gennady and Georgiy have a token placed in one of the graph vertices. Players take turns moving the token along one of the a…
ls是一个特别堕落的小朋友,对于n个连续的小时,他将要么睡觉要么打隔膜,一个小时内他不能既睡觉也打隔膜 ,因此一个小时内他只能选择睡觉或者打隔膜,当然他也必须选择睡觉或打隔膜,对于每一个小时,他选择睡觉或 打隔膜的愉悦值是不同的,对于第i个小时,睡觉的愉悦值为si,打隔膜的愉悦值为ei,同时又有一个奥妙重重的 规定:对于任意一段连续的k小时,ls必须至少有t1时间在睡觉,t2时间在打隔膜.那么ls想让他获得的愉悦值尽 量大,他该如何选择呢? 题意:就是N天,每天可以选择S或者E,每一天S或者E有…
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K,如果第L位已经有值了就会先调用\(Insert(L+1,A_L)\)(其中\(A_L\)表示第L位上的值),再将\(A_L\)赋为K.问经过查询后序列的模样. 思路:首先将题意抽象成每次找到从第L位开始第一个0,并将其"拖"回第L位,然后将其更改为K.这个操作很明显可以用FHQ Treap…
 2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Husam and the Broken Present 2 time limit per test:1.0 s memory limit per test:256 MB input:standard input output:standard output After you helped Husam…
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数组求min #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #defi…
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈算法. 介绍一下floyd判圈算法:该算法适用于在线性时间复杂度内判断有限自动机.迭代函数.链表中是否有环,求环的起点(即链长)和环长. 可以先这么做:首先从起点S出发,给定两个指针,一个快指针一个慢指针,然后每次快指针走1步,慢指针走2步,直到相遇为止.如果已经到达终点/达到规定步数时仍然没有相遇…
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\right\rfloor$个巢穴连通.第$i$个巢穴在最终时允许$c_i$只醒来的鼹鼠最终停留在这.已知第$i$只鼹鼠在第$p_i$个巢穴睡觉.要求求出对于每个满足$1 \leqslant k \leqslant n$的$k$,如果前$k$只鼹鼠醒来,最小的移动距离的总和. 考虑费用流的建图和暴力做法,把原图的…
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分. 我们将这个序列排序,对于权值相同的一段数可以任意交换它们,每两个相邻数在原序列的位置中如果是$i, i + 1$,那么划分的段数就可以减少1. 每次转移我们考虑添加值相同的一段. 每次转移能不能将减少的段数加一取决于当前考虑的数在前一段内有没有出现以及有没有作为最左端点. 因此我们记录一个决策与…
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共子矩阵.输出这个最大公共子矩阵的行数.列数和左上角分别在\(a,b\)中的坐标.若无解,输出\(\texttt{0 0}\).若有多解,输出任意一组. \(n1,m1,n2,m2\in[1,40]\). 如果你还不知道Gym是什么,please点击这个 (以下假设\(n1,m1,n2,m2\)同阶,…
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得得到的子图联通并且总代价最小,输出最小总代价和一种方案. 虽然题目里描述的很冗长,但其实这个图有一些性质:它最初是一条链/一个环,然后再有一些结点直接连到这些在链上/环上的结点.. 下图就是一个(就是样例): 做法 首先我们可以简单的查看点的度数来找到链/环上的点,和连接它们的边. 然后我们可以通过…
L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description Andrey works in the Ministry of Truth. His work is changing articles in newspapers and magazines so that they praise the Party an…
题目链接: http://codeforces.com/gym/100851 题目大意: 一个宽度为N的网格图,i上有h[i]高的方块.现在你有W个方块,问怎么放使得最终的最高点最高. 只要一个格子的下方,左下方和右下方都有方块那么久可以把方块放到这个格子上.最左端和最右端不能放方块. (N<=100000,W<=1018,h[i]<=109) 题目思路: [二分] 这题很容易就想到二分.但是怎么判断当前高度可行不太好想. 首先二分答案H,而对于当前高度,需要枚举这个H是在哪一个宽度I上…
题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛的水的体积就等于这个容器的“凸包”的体积减去墙的体积.所以要做的就是动态的维护凸包. 由于只有墙上升的操作,所以只需要用一个区间覆盖区间求和的线段树维护每个位置的凸包上界就可以了. 维护凸包的关键在于最大值的位置,具体见代码. #include<bits/stdc++.h> using names…
L. Useful Roads time limit per test:4 seconds memory limit per test:512 megabytes input:standard input output:standard output Berland capital contains n junctions and m roads connecting pairs of junctions. All roads are one-way. As you probably know…
A题  直接把问号全部变为陆地如果所有陆地连通    那么再逐个把刚才变成陆地的问号变为水如果依旧连通有多种解 为什么我的代码跑不过去,和网上的题解思路一模一样!!?? #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define MAX_N 55 using namespace std; char map[MAX_N][MAX_N]; int n,m; i…
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11665&courseid=0 题目大意: 一个微波炉,有N个按钮,每个按钮可以让时间加或减一个数,问达到M至少需要按几次按钮.(N<=16,0<=M<=3600) 如果无法达到M输出比M大的最小的值需要按的次数和这个值与M的差值.注意微波炉的时间满足0<=当前…
Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Let’s check another challenge of the IBM ICPC Chill Zone, a poetry challenge. One says a poetry string that starts with a…
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. • A string "()" is balanced. • Concatenation of two balance…
Space Golf 题目连接: http://codeforces.com/gym/100803/attachments Description You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of c…
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop…
Joy of Flight 题目连接: http://codeforces.com/gym/100531/attachments Description Jacob likes to play with his radio-controlled aircraft. The weather today is pretty windy and Jacob has to plan flight carefully. He has a weather forecast - the speed and d…
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Halloween computer game. The game is played on a rectangular graveyard with a rectangular chapel in it. During the game, the player places new rectangul…
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph are playing a two-player game on a triangular board that looks like the following: 1 2 3 4 5 7 8 6 9 10 11 13 14 16 17 12 15 18 At each turn, a playe…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, which is greater than 0. Let N1 be the number of ones in the binary representation of N0. So, if N0 = 27, N1 = 4. For all i > 0, let Ni be the number…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要找一个最小的点集,使得满足这n个区间的条件 Input n 然后li,ri,ci Output 输出最小点集大小 Sample Input 5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1 Sample Output 6 Hint 题意 题解: 线段树+二分+贪心 首先我们贪心一…
E. Palindrome QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100570/problem/E Description De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to its reverse. De Prezer also love…
A. Cursed QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100571/problem/A Description De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a big fan of Supernatural series.So, he di…
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description It was a beautiful night at Yekaterinburg, the sky was crystal clear with no clouds, and the view of the moon and the stars was…
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/F Description I Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a dragon with n heads numbered from 1 to nf…