[Codeforces Round495A] Sonya and Hotels】的更多相关文章

[题目链接] https://codeforces.com/contest/1004/problem/A [算法] 直接按题意模拟即可 时间复杂度 :O(NlogN) [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 110 const int inf = 1e9; int n,d; int a[MAXN]; set< int > ans; template <typename T> inlin…
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standard input output: standard output Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty mul…
题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类型的操作: + ai : 把 ai 加入到集合 multiset 中, 可能出现重复元素. -  aj : 把 aj 从集合 multiset 中删除, 保证集合中一定存在这个元素. ? s  : 统计集合中现有的元素和模式串 s 匹配的个数.s 是一个 “01” 串, 其中 "0" 代表…
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上或者减去某个数,调整的代价是加上或者减去的数的绝对值之和,请你输出最小代价. [题解] 先考虑这样一个问题,如果是非严格单调递增该如何做,我们会发现每次调整,都是调整某个数字为原先数列中存在的数字,最后才是最优的,所以,我们设DP[i][j]表示前i个数字,最后一个数为原先数列排序后第j大的数字的最…
题目链接:http://codeforces.com/problemset/problem/1151/F 题目大意: 给定长度为 n 的 01 序列,可以对该序列操作 k 次,每次操作可以交换序列中任意两个元素的位置,求进行 k 次操作后 01 序列升序排列的概率. 分析: 每一次操作就是在 n 个数中选2个,因此有 $\binom{n}{2}$ 种,一共有 k 次操作,所以一共有 $\binom{n}{2}^{k}$ 种可能结果,即分母 Q. 对于分子 P,设序列中 0 的个数为 cnt_0,…
C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sonya was unable to think of a story for this problem, so here comes the formal description. You are g…
Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the ma…
题目链接   Sonya and Problem Wihtout a Legend 题意  给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成严格递增子序列的所需最小花费. 考虑$DP$. 首先比较常见的套路就是把每个$a[i]$减去$i$,然后把这个新的序列升序排序,记为$b[i]$. 这里有个结论:最后操作完成之后的每个数都是$b[i]$中的某个数. 然后就可以$DP$了,令$f[i][j]$为前$i$个数操作之后每个数都小于等于$b…
[题目链接] https://codeforces.com/contest/1004/problem/B [算法] 不难发现 , 最优解一定是01010101.... 时间复杂度 : O(N) [代码] #include<bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { T f = ; x = ; char c = getchar(); for (; !isd…
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan di…
题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i+1]-(i+1),处理一下. 首先是最基础的dp[i][j]前i位最大值为j的最小值为多少. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include…
题意:给一个序列,可以进行若干次操作,每次操作选择一个数让它+1或-1,问最少要几次操作使得序列变为严格单调递增序列. 题解:首先考虑非严格递增序列,则每个数字最终变成的数字一定是该数组中的某个数.那么O(n^2)复杂度dp一下即可. dp[i][j]表示第i个数变成第j小的数,dp[i][j] = min (dp[i-1][1 ... j])+abs(a[i]-b[j]). 那么对于严格递增序列,将a[i]变成a[i]-i后,再照非严格递增序列跑一遍dp即可. #include<bits/st…
大意: 给定01序列, 求随机交换k次后, 序列升序的概率. 假设一共$tot$个$0$, 设交换$i$次后前$tot$个数中有$j$个$0$的方案数为$dp[i][j]$, 答案即为$\frac{dp[k][tot]}{\sum\limits_{i=0}^{tot}{dp[k][i]}}$ 矩阵快速幂求出$dp[k][0]...dp[k][tot]$后即可得出答案.…
题面在这里! 挺智障的一个二分...我还写了好久QWQ,退役算啦 题解见注释... /* 先对每个点记录 向子树外的最长路 和 向子树内最长路,然后二分. 二分的时候枚举链的LCA直接做就好啦. */ #include<bits/stdc++.h> #define ll long long using namespace std; #define pb push_back const int N=100005,B=2333333; inline int read(){ int x=0; cha…
题意:给你n个数字,每个数字可以加减任何数字,付出变化差值的代价,求最后整个序列是严格单调递增的最小的代价. 首先我们要将这个题目进行转化,因为严格单调下是无法用下面这个dp的方法的,因此我们转化成非严格的,对严格下而言,a[j]-a[i]>=j-i,那么得到a[i]-i<=a[j]-j.这样,我们令a'[i] = a[i] - i,就可以得到a'[i]<=a'[j].这样我们就把问题转化成求这样一个非严格单调的序列了. 将整个序列排序后构成一个新的数组b[i],用dp[i][j]来表示…
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has n…
题目链接: http://codeforces.com/contest/1004/my A. Sonya and Hotels 分类讨论 看第一个样例解释的时候没看到后面第二行还有一个19,想了半天为啥19不算 题意大致是选定一个位置,使得其到达原本那些位置的距离最小的为d 此处应注意,最小为d意味着不能距离小于d 所以可能的住所有三种情况, 1. 两个城市距离小于2d, 那么无法在其间选定 2. 两个城市距离等于2d, 可选定一个点 3. 两个城市距离大于2d, 可选定2个点 #include…
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. A…
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries,…
题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Sonya learned about long integers and invited all her friends to…
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sonya was unable to think of a story for this problem, so here comes the formal description. You are g…
C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multi…
题目链接: C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sonya was unable to think of a story for this problem, so here comes the formal description. You…
题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty…
Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing \(n\) positive integers. At one turn you can pick any element and increase or decrease it by \(1\). The goal i…
http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. 现在给出t个点的值,问是否可以确定一个由t个点组成的方格,方格中的值由这t个点组成,如果有,则任一输出一个方格的规模n.m和中心点的坐标x.y. 思路: 参考了https://blog.csdn.net/FSAHFGSADHSAKNDAS/article/details/80951796的题解. #…
http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器人从起点开始分别向右和向左移动,当它们移动到和他们自己数字相同的格子时就会停止,否则就会一直移动下去知道出界.现在要计算出有多少组不重复的(p,q)可以使得这两个机器人不相遇. 思路: 只要去考虑每个数第一次出现的位置和最后出现的位置即可.这题我用了前缀和的思想,首先从左到右扫描一遍,算出1~i这个…
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn nn numbers in a row, aiai is located in the ii-th position. She also has put a robot at each end of the row (to the left…
http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角上, 可将它调整到位置(n,m) 设中心点(x, y) 则可以得到 n-x+m-y=mx 再注意到假若图无限大, 则对每个距离d的取值一定有4*d个 即第一个取值数<4*d的d可以调整为中心点的x坐标 然后就可以暴力枚举因子判断了 #include <iostream>#include &l…
https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每一列都是一个回文串,问最多有多少个这样的子矩阵 思路 首先可以思考如何暴力,枚举四个边界(子矩阵),然后判定一下子矩阵的每一行每一列,这样的复杂度是nmnmn*m 很明显需要找一下规律来优化一下复杂度, 对于每一行来说,最多只能存在一种字母的数量是奇数,这样一定可以保证这一行是回文串 对于每一列来说,因为…