The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If xx is the number of passengers in a bus just before the current bus stop and yy is…
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If xx is the number of passengers in a bus just before the current bus stop and yy is…
题目链接:http://codeforces.com/problemset/problem/978/E 题意 一辆公交车,在每站会上一些人或下一些人,车的最大容量为w,问初始车上可能有的乘客的情况数. 思路 找到公交车在路上的最大乘客数和最小乘客数,然后计算最大容量减去最大乘客数,加上最小乘客数的值.如果该值小于0,输出0 AC代码 #include <stdio.h> #include <string.h> #include <iostream> #include &…
[链接]: CF [分析]: 设上车前人数 x ,中途最大人数为 x+max ,最小人数为 x+min (max≥0,min≤0) 可得不等式组 x+max≤w, x+min≥0 整数解个数为 max(0,w-max+min+1) 求出 max,min 即可,有求和~记得long long [代码]: #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; #define ll long long #de…
在pygame写游戏出现pygame.error: video system not initialized 源代码 import sysimport pygamedef run_game(): pygame.init() screen = pygame.display.set_mode((1200,800)) pygame.display.set_caption("Alien Invasion")#主循环while True: #监视键盘和鼠标事件 for event in pyga…
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…
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…
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S…
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…
今天在github上找到一个用pygame做的Python游戏,但是clone到本地运行的时候却冒出了“mixer system not initialized”这样的问题.其实这句话说的就是音频混音器(具体指的就是双击右下角小喇叭图标后弹出的音量控制台)没有初始化,由于我的电脑重装过以后没有装声卡驱动,所以才导致了这个问题,安装声卡驱动以后,问题迎刃而解.…
(点击此处查看原题) 题意分析 已知 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…
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…
题目链接:https://vjudge.net/problem/CodeForces-1070F 具体思路:首先把所有的00放进去,然后对于10 和01 的取两个数目最小值t,排完序后将前t个加起来,然后再将剩余的看作一类,求一个最大加的数目就可以了. 关于为什么看作一类,第一个原因,剩下的的构成只能是只有00 ,或者(00,10)或者(01,00)或者(10)或者(01),这样就好分清楚剩下的最多加多少了,因为如果放入剩下的话,只能增加一种或者增加两种,所以取最大满足情况的前k项加起来就可以了…
题意:两个数组a,b,每次操作可将其中一个数组的一个数字加1或减1,求最小操作次数使得a数组的最小值大于等于b数组的最大值. 思路: 解法一:考虑最终状态,假设a为数组a中最小的数,b为数组b中最大的数,存在中间值c,对于a要做c-a次操作,对于b要做b-c次操作使得a=b消灭一对不符合的数,每次总操作数为b-a而与转换后的中间值c无关系.所以将a数组从小到大排序,b数组从大到校排序,sum+=(b-a). #include<iostream> #include<cstdio> #…
题意:求出长度为n仅由1到n数字组成的非降序列与非升序列的个数. 思路:转化为求非降序列(非升序列)的个数.n个元素想象为n个离散的点x1,x2,x3,...,xn,在最开头补上一个点x0为1,在最末尾补上一个点xn+1为n,两个相邻点之间的高度差为hi=xi+1-xi,hi>=0.可列出h1+h2+h3+...+hn+1=n-1,将hi加上1,则h1+h2+h3+...+hn+1+n+1=2n,在2n-1个位置放n块隔板,则答案为 C(2n-1,n).…
B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only…