C. Voltage Keepsake time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is…
题目链接 这是一道很棒的二分题. 思路: 首先先思考什么情况下是可以无限的使用,即输出-1. 我们思考可知,如果每一秒内所有设备的用电量总和小于等于充电器每秒可以充的电,那么这一群设备就可以无限使用. 接下来分析不是无限使用的情况: 题目要求的是满足某个情况的最大值. 很像二分的类型,二分题目往往就是求某一个满足情况的最值,这样我们只需要寻找上限和下限,并对每一次mid值进行检验是否满足,这样的模型时间度一般为O(  N*Log( L )) L代表的是总区间的长度,而N代表的是完成一次判定需要的…
题意: 有n台机器,第i台机器每个单位时间消耗ai的功率,初始有bi的功率储备,有一个充电器每个单位时间充p单位的功率 问经过多长时间才能有一个功率位0的机器,如果能够无限使用输出-1: 解析: 时间是实数范围内,所以可以在任何时刻 给任何一个机器充电 所以如果p >= sum(a1 + a2 + a3 + ``` + an) 则能无限使用 如果不能无限使用 那么给所有的机器在不充电的情况下以初始能用多长时间从小到大排序 那么我们首先肯定要给使用时间最小的机器充电,使它用的时间能够大于等于时间第…
题目链接:http://codeforces.com/contest/801/problem/C 题意:给出一个充电器每秒钟充p个点,还有n个电器要同时使用a[i]表示第i个电器每秒钟用多少点,b[i]表示第i个 原来存了都少电.充电器可以无缝切换这充电,但是只能给一个充(同一时间).最后问你最长可用多久,如果可以 无限时间的用的话,就输出-1. 题解:首先确定一下什么时候输出-1也就是可以无限充电的情况,就是p大于所有a的总和就行. 然后就是时间有限的情况.这里明确一个式子. need*t=a…
C. Voltage Keepsake 题目链接:http://codeforces.com/problemset/problem/801/C time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have n devices that you want to use simultaneously. The i-th dev…
地址:http://codeforces.com/contest/801/problem/C 题目: C. Voltage Keepsake time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have n devices that you want to use simultaneously. The i-th devi…
C. Voltage Keepsake time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is…
题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计切换充电器的时间,问你最多能够同时使用这些充电器多久,如果可以一直用下去就返回-1.要求时间误差不能超过10^-4. 思路:开始没就见过这种类型的题目傻傻地一点一点把时间加上去....后来知道这是用了二分枚举,首先定义一个右边界(r=1e11根据提目应该大于1e10多一点)和左边界(l=0),然后不…
[题目链接]:http://codeforces.com/contest/801/problem/C [题意] 有n个设备 你想同时使用 第i个设备每分钟消耗ai点电量,一开始有bi点电量 你有一个充电器,每分钟可以冲p点电量 问你第一次有用电器的电量耗光是在何时 [题解] 二分时间t 充电量为temp=t*p 每一个设备 now = bi-ai*t 如果 now<0 if (temp<now) return false; else temp-=now; return true; 这种小数的二…
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store…
二分答案,验证. 二分到一个答案,比他小的时间都需要补充到这个时间,计算所需的量,然后和能提供的量进行比较. #include <cstdio> #include <cmath> #include <set> #include <cstring> #include <algorithm> #include <iostream> #include <string> #include <vector> using…
Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster e…
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间的最少边数,求加边之后任意两点长度之和 思路 一看到求任意两点,知道需要用每条边的贡献计算(每条边使用了多少次) 每条边的贡献等于边左边的点数*边右边的点数 然后就一直不知道怎么解决加边后的问题,不知道要标记哪些东西,怎么减去 单独看一条路径,加边之后, 假如边数是偶数的话,边数/2 假如边数是奇数…
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为位置$i$处的$F$复位所花费时间, 有 $dp[i] = max(dp[i-1]+1,cnt_i)$, $cnt_i$为前$i$位$M$的个数 $dp$最大值即为答案 #include <iostream> #include <algorithm> #include <cstd…
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w 的时候,我们最多通过1e5次枚举确定答案 而当 y >= w 的时候,平局所得分为:y * d = (y-w)*d + w*d ,可以看作平局的局数为 y - w ,多出的w*d贡献给 (w*d)/w = d 局胜局,所以胜局为 x + d ,说明此时用x+y局胜局和平局得到的分数可以由 x + d…
Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know th…
Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.…
题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶 在开始判断一次 a与b-c的关系 即两种方式喝酒的成本 如果a<=b-c 那么直接全部买塑料瓶就行了 没必要买玻璃瓶 因为麻烦 而且会出现钱不够b却够b-c这种情况 很麻烦 如果a>b-c  也就是说买玻璃瓶更省一些 就应当先买玻璃瓶的 不行了再尝试塑料瓶 第一种情况只做一次除法就够了 第二种情况 如果用while循环(n>b)来做 会超时在test48...…
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the numbe…
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are…
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move. There are nn doors, the ii-th door ini…
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c'…
大意: 给定森林, 要求构造一个表, 满足对于每个$x$, 表中第一次出现的$x$的祖先(包括$x$)是$a_x$. 刚开始还想着直接暴力分块优化一下连边, 最后按拓扑序输出... 实际上可以发现$a_x$要么等于$x$, 要么等于$fa_x$, 直接dfs一边就好了... #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set…
Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80%80% of applicants are girls and majority of them are going to live in the university dormitory for the next 44 (hopefully) years. The dormitor…
题意: 就是几个人去旅游,组队的条件是对于某个队员 队里至少有两个是他的朋友,每天早晨都会有一对新人成为朋友 解析: 用set标记互为朋友 a[i] b[i] 表示在第i天早晨 u和v成为朋友 先求最后一天的  前几天的数量肯定小于最后一天的数量   然后从后向前每天互相消去互为朋友的a[i] 和 b[i] 然后再判断a[i] 和 b[i] 是否符合还符合情况 把每个不符合的用vis标记 防止重复减 #include <bits/stdc++.h> #define rap(i, a, n) f…
大意: 给定无向图, 求是否能删除一条边后使图无环 直接枚举边判环复杂度过大, 实际上删除一条边可以看做将该边从一个顶点上拿开, 直接枚举顶点即可 复杂度$O(n(n+m))$ #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <cstdio> #include <queue> #define REP(i,a,…
大意: 第i天可以花$a_i$元买入或卖出一股或者什么也不干, 初始没钱, 求i天后最大收益 考虑贪心, 对于第$x$股, 如果$x$之前有比它便宜的, 就在之前的那一天买, 直接将$x$卖掉. 并不需要计算出最优的卖出时间, 因为若$x$后有更优价格, 可以再买回$x$, 不影响贪心结果 #include <iostream> #include <algorithm> #include <math.h> #include <cstdio> #include…
题意: 让你构造一个图,使得A,B,C,D的个数为给定的个数,上下左右连通的算一个. 哎呀 看看代码就懂了..emm..很好懂的 #include <bits/stdc++.h> using namespace std; , INF = 0x7fffffff; ][]; int main() { ; i<; i++) ; j<; j++) ) str[i][j] = 'A'; else str[i][j] = 'B'; int a, b, c, d; cin>> a &…
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or…
大意: 给定有向图, 每条边有一个权值, 假设你有$x$个控制器, 那么可以将所有权值不超过$x$的边翻转, 求最少的控制器数, 使得翻转后图无环 先二分转为判定问题. 每次check删除能动的边, 若剩余图有环显然不成立, 否则将剩余的图拓排一下, 再把能动的边按拓排的方向即可保证无环. #include <iostream> #include <algorithm> #include <math.h> #include <cstdio> #include…