题意:给出a数组和b数组,他们的长度最大1e5,元素范围是1到1e9,问你让a数组最小的数比b数组最大的数要大需要的最少改变次数是多少.每次改变可以让一个数加一或减一 分析:枚举a数组和b数组的所有的元素x,作为他们的界限,也就是说a数组所有的数要大于等于x,b数组所有的数要小于等于x,再利用前缀和+二分,分别求出ab数组需要改变的次数,在所有的方案中取一个最小值 代码: #include <bits/stdc++.h> #define ll long long using namespace…
这是本人第一次写代码,难免有点瑕疵还请见谅 A. Devu, the Singer and Churu, the Joker time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu is a renowned classical singer. He is invited to many big functions/festi…
题意: q个询问,每一个询问给出2个数sum,n 1 <= q <= 10^5, 1 <= n <= sum <= 10^5 对于每一个询问,求满足下列条件的数组的方案数 1.数组有n个元素,ai >= 1 2.sigma(ai) = sum 3.gcd(ai) = 1 solution: 这道题的做法类似bzoj2005能量采集 f(d) 表示gcd(ai) = d 的方案数 h(d) 表示d|gcd(ai)的方案数 令ai = bi * d 则有sigma(bi)…
D. Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are giv…
Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given…
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不能超过R才算彻底通关,问直到彻底通关位置的游戏时间的期望值为多少 分析 二分从头开始通关的用时期望mid 设\(dp[i][j]\)表示通前i关,当前时间为j的期望,倒推期望. 若超时重新开始,则\(dp[i][j]…
--你以为你以为的.就是你以为的? --有时候还真是 题目链接:http://codeforces.com/contest/439/problem/D 题意大概就是要求第一个数组的最小值要不小于第二个数组的最大值,你所能做的就是对数组中的某一个数进行+1/-1的操作.最后问操作次数最少须要多少次. 起初这题我看着例子就開始瞎YY了,YY思路如图= =||| 看似有那么一丁点道理,可是事实上是无法这么找到的,非常快就自己找到了反例.. 只是之所以说是有那么一点道理是由于例子中的边缘数正好是它的平衡…
题目链接:点击打开链接 = - =曾经的三分姿势不对竟然没有被卡掉,,,太逗.. #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #inclu…
http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去,问对于每一个询问减掉num个人后是谁赢了拍卖,最小的价格是多少. 思路:昨晚不会做.想法好神奇(我太弱).对于每个人用 set-S 装起来其每次喊价的下标,然后用一个数组order按价格从大到小的顺序将每个人装起来,对于每一个询问,把这num个人丢到一个 set-s 里面,然后在order里面找没…
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…