cf-789A (思维)】的更多相关文章

http://codeforces.com/contest/814/problem/C 给定一个字符串s,长度小于1500,进行q次询问q<=20w,每次询问输入一个m和一个字符c,求将最多m个c代替原来字符串的某些位置,能得到的连续个c的最长长度. 很容易想到一个n*n*q的暴力做法,但是会超时,由于只有26个字母,最长1500,考虑预处理所有结果. 枚举所有的字母,然后枚举所有的区间,预处理找出m个c对应的最佳区间长度. #include<bits/stdc++.h> using n…
题意: 给定一个靠着坐标轴长为n,宽为m的矩形和 矩形中的一个点A,求在这个矩形内部一个 长宽比为a/b的小矩形,使这个小矩形的长宽尽量大使点A在小矩形内部,并且点A尽量靠近小矩形的中心 CF的思维题确实牛,让点A尽量靠近小矩形的中心其实是比较障眼法的,让你觉得这个问题又需要考虑 小矩形最大又需要考虑点A的问题,然是考虑这样一个问题,小矩形的大小和点A在小矩形内部,两个问题是否矛盾. 这是解决问题的关键,所以这不仅是思维的难度,也是心理的考验,在思考这个问题之初就默认这两个问题是矛盾的, 为之后…
Day0 到杭州的时候是下午,休息了一下就吃完饭了. 晚上的时候闲着没事复习了一下几个不太熟的数论板子,\(\mathrm{exgcd}\),\(\mathrm{ExCRT}\),\(\mathrm{BSGS}\),还有高斯消元,线性基什么的,但愿不考. 感觉有点紧张. Day1 好早就到文渊中学了,感觉人特别多,进考场前膜拜了一下\(\mathrm{LHJKY}\)大佬,还从手机上看了一下\(\mathrm{windows}\)系统下的开栈方法,然后就进考场了. 地下室感觉有点闷热,还没有厕所…
题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He ha…
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题,要注意超边界... #include <iostream> #include <cstring> #include <algorithm> using namespace std; <<); int n,m,x,y,a,b; int ok(int x1,int…
题目 传送门:QWQ 分析 思维要求比较高. 首先我们要把原图的逆序对q算出来. 这个树状数组或归并排序都ok(树状数组不用离散化好评) 那么翻转$[l,r]$中的数怎么做呢? 暴力过不了,我试过了. 设$ t=r-l+1 $即为区间长度 那么区间数对数量(看好是所有数对,不是逆序对)的数量就是$ k =\frac{n\times(n-1)}{2} $ 方法是我们判断一下数量k的奇偶性,如果是奇数的,那么就把$ q $的奇偶性变一变. 然后判断q的奇偶性输出就行. 为什么这样是对的呢? 首先翻转…
http://codeforces.com/contest/987/problem/D 题目大概: 给出一个n个城镇m条边的图,给出每个城镇拥有的特产(可能多个城镇有相同特产).有k种不同特产. 要求每个城镇需要其他城镇运输特产到自己的城镇,每个城镇必须拥有s种特产,那么在城镇满足s种特产后,需要的最短路径是多长,最短路指的是特产运输过来走过的边的数量. 分析: 一开始以为是道水题,因为我只要对每个点都进行一次DFS,那问题就很简单了,但是...细想下,这其实是不行的,因为会TLE. 那现在我们…
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This me…
ACM思维题训练集合 A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and &…
ACM思维题训练集合 C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As the boat drifts down the river, a wood full of blossoms shows up on the riverfront. "I've been here on…
ACM思维题训练集合 You are given k sequences of integers. The length of the i-th sequence equals to ni. You have to choose exactly two sequences i and j (i≠j) such that you can remove exactly one element in each of them in such a way that the sum of the chan…
ACM思维题训练集合 It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are n displays placed along a road, and the i-th of them c…
ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture. A picture is a barcode if the following conditions are fulfilled: A…
ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting…
ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: First we build by the array a an array s of partial sums, consisting of n elements. Element number…
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers…
ACM思维题训练集合 The Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very difficult to distinguish. In fact, t…
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the…
题意:给你n行m列的数组,和k次的询问,问从l行到r行是否存在一个非递增的列 思路:看到这道题的数据量我们就知道直接暴力不可取,所以我们采用了预处理的方法,我们记录下来每一行的最长的非递减的列的开头的哪个行,比如num[i]=k;表示到第i行的最长的非递减的列是从第k行开始的,在每一次的询问中我们只需要比较num[r]的值与l的值就可以了: 代码: #include <cstdio> #include <cmath> #include <iostream> #inclu…
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she…
Description: 非 * 号的地方可以放A或B,不能AA或BB,一共有a个A,b个B,问你最多放几个 Solution: 1.模拟一下,找连续空位长度,如果长度为奇数,则我可以有一个位置放任意一个,否则摆放消耗一定,最后放完了判断一下是不是还有剩下的,有剩下的就都放到任意位置 Code #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int m…
E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Grigory has nn magic stones, conveniently numbered from 11 to nn . The charge of the ii -th stone is equal to cici . Sometime…
还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cstring> #include <stack> #include <set> using namespace std; ],v[],n,m,k,ans; ],vis[]; ]; stack<int> S; void dfs(int u){ if(sons[u].size…
Description Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for. Arkadi and Boris Strugatsky. Monday starts on Saturday Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta fo…
http://codeforces.com/contest/987/problem/C 题意:给你两个n的序列要你根据第一个序列(严格单调递增的方式)在第二个序列里找3个数加起来,输出最小的一个. 思路:先从前往后枚举两个最小的.在从后往前找一个加上使其最小,最后遍历剩下的三元组. AC代码: #include<bits/stdc++.h> #define ll long long using namespace std; ; *1e9; struct node{ int num,id; };…
题意: 是输入一个只有'w','b'的字符串,可以对他的任意位置切割成两个子串,切割后的右边的子串翻转后再和左边的子串拼起来会得到一个新的字符串,操作次数不限,问能得到的字符串中wb交替出现的最大的长度是多少 分析:其实只要将原有的字符串进行复制拼接然后扫描一遍得出结果就可以了,为什么呢 ? 其实呀只要这样操作无论怎样操作反转 ,都可以在s+s这个串里找到相同的子串,也就可以大胆的得出这个玄学的结论 . 不加一证明,表示不会,如果不相信可以手动操作一番 #include<bits/stdc++.…
题意:n 个人參加线上会议.某经理记录了中间一段时间的 m 条上下线记录(1 ≤ n, m ≤ 105).+ 表示上线,- 表示下线. leader是指仅仅要有人在线,他都在线的人.求全部可能的leader. 题目链接:http://codeforces.com/problemset/problem/420/B -->>这种一种人,他们在记录中的第一条记录是下线的,定义为xx.. 三个断言: 1)假设xx存在.那么出现的人中,leader仅仅可能是最后出现的那个xx.. 2)假设xx不存在,那…
题意: 某土豪公司建立了n个数据中心,把m份资料每份在其中的两个数据中心备份. 每个数据中心在一天h个小时当中有一个小时需要维护,此时不提供资料下载服务. 现在土豪公司想要将其中若干个数据中心的维护时间向后推迟一小时,并要求一天中任意时刻每份资料都可以被下载,问最少选取多少个数据中心维护. 题解: 首先,对于两个备份的地方,我们发现只有 (C[a]+1)(C[a]+1)(C[a]+1) % h==C[b]h==C[b]h==C[b] 时,a,ba,ba,b 两个处理器需要同时后延一小时.于是,建…
Graph And Its Complement time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given three numbers n,a,bn,a,b. You need to find an adjacency matrix of such an undirected graph that the number of…
Divisibility by 25 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an integer nn from 11 to 10181018 without leading zeroes. In one move you can swap any two adjacent digits i…