[CF846E]Chemistry in Berland题解】的更多相关文章

这题乍一看是一道水树形DP(其实事实上它确实是树形DP),然后设f[i]表示第i个点所多余/需要的材料,然后我们愉快的列出了式子: if(f[v]<0) f[u] += f[v] * edges[c_e].dis; else f[u] += f[v]; 然后放到CF上,直接WA,十分自闭,于是我试图define int long long,还是没过,仔细一想(偷瞄了一眼CF的数据),发现f数组有可能会爆long long,怎么办?高精? 显然这不太现实,于是想着如果它要爆了就把它置回边缘,实测不…
题目 题意: 有n种化学物质,第i种物质现有bi千克,需要ai千克.有n-1种,编号为2-n的转换方式,每种都为(x,k),第i行是编号为i+1的转换方式,编号为i的转换方式(xi,ki)表示ki千克的xi物质可以转换成1千克的i物质,1千克的i物质可以转换成1千克的xi物质.问是否可能通过转换得到足够的需要的物质.(1 ≤ xj + 1 ≤ j) 重点:上面标红的条件.如果只保留ki千克的xi物质可以转换成1千克的i物质产生的一条有向边,表明xi物质连出的边一定是指向编号大于i的物质的(x[i…
咸鱼选手发现自己很久不做cf了,晚节不保. A.Curriculum Vitae 枚举一下间断点的位置. #include<bits/stdc++.h> using namespace std; ; int cnt,n,a[N],mx,cur; inline int read(){ ,x=;char ch; ;}'); +ch-'); return f*x; } int main(){ n=read(); ;i<=n;i++)a[i]=read(); ; ;i<=n;i++){ c…
Content 有一种叫做 Berland crossword 的拼图游戏.这个拼图由 \(n\) 行 \(n\) 列组成,你可以将里面的一些格子涂成黑色.现在给出 \(T\) 个这样的拼图,每个拼图都含有如下限制: 第一行最多有 \(u\) 个黑色格子. 第 \(n\) 列最多有 \(r\) 个黑色格子. 第 \(n\) 行最多有 \(d\) 个黑色格子. 第一列做多有 \(l\) 个黑色格子. 问是否有满足如上限制的拼图(不需要输出方案). 数据范围:\(2\leqslant n\leqsl…
Prelude 题目传送门:ヾ(•ω•`)o Solution 按照题意模拟即可. 维护一个优先队列,里面装的是正在运营中的出租车,关键字是乘客的下车时间. 维护一个线段树,第\(i\)个位置表示第\(i\)个房子前面有没有停放出租车,这样在有人需要打车的时候可以快速找到离她最近的车的位置. 对每个房子维护一个堆,里面装的是停在这个房子前面的出租车,关键字是出租车的编号和上一个乘客下车的时间,上一个乘客下车越早,等待时间越长. 然后模拟时间的流逝就可以了,代码非常好写. Code #includ…
题意 给出 \(n,m,k\) ,表示 \(k\) 名玩家打牌,共 \(n\) 张牌,\(m\) 张王,保证 \(k|n\) ,记得分为 拿到最多王的玩家手中王数 \(-\)拿到第二多王的玩家手中的王数,求得分最大值 思路 首先,每人有 \(n/k\) 张牌, 假设有玩家手气特好,抽一张一个王,那他最多有 \(maxn=\max\{m,n/k\}\) 张牌, 在此情形下,还剩 \(m-maxn\) 张王,则拿到第二多王数应该为 \(\left\lceil\dfrac{m-maxn}{k-1}\r…
链接:http://codeforces.com/contest/445/problem/B 描述:n种药品,m个反应关系,按照一定顺序放进试管中.如果当前放入的药品与试管中的药品要反应,危险系数变为之前的2倍:否则危险系数不改变.起始危险系数为1.求可能的最大的危险系数. 思路:遍历图 在图上画一画,就会发现,只要一块连通的图中的一个点放入后,之后每添加这块图中的一个点就会导致危险系数乘2.那么我们只需要找到一共有多少个连通图tmp,然后用总数减去得到ans.答案就是1LL<<ans.注意l…
B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/B Description Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of…
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hierog…
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/problem/C Description Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different type…
B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/B Description Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any o…
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals…
C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$opt==1$时,对$[L,R]$全部加x,$opt==2$时,对$[L,R]$求$\sum_{i=L}^{R}Fibonacc(a_{i})$. 题解: 线段树+矩阵快速幂. 在每个线段树存一个转移矩阵,然后YY即可. 代码: #include<cstdio> #include<cstrin…
写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya and Books 分别记录书本摆放顺序$a[]$,取书顺序$b[]$,每本书的位置$pos[]$,每本书在不在书堆上$in[]$,书堆最顶端的书的位置$top$(因为用的是数组,元素位置是固定的). 然后,按照题意枚举输入的取书顺序$b[]$,同时记录答案$ans$,更新$top$即可. C. Va…
D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes…
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if…
[CF883B]Berland Army 题意:给出n个点,m条有向边,有的点的点权已知,其余的未知,点权都在1-k中.先希望你确定出所有点的点权,满足: 对于所有边a->b,a的点权>b的点权对于i=1..k,至少有一个点的点权为i n,m,k<=100000 题解:像菜肴制作一样奇怪的拓扑排序题,直接上方法吧,不会证. 先正反跑两边拓扑排序,得出每个点点权的下界Li和上界Ri. 将所有点按上界从小到大排序,然后枚举权值i.将所有上界为i的点都扔到堆中,再从堆里取出下界最大的那个点,将…
C. Old Berland Language 题目连接: http://www.codeforces.com/contest/37/problem/C Description Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letter…
E. Berland Local Positioning System Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/E Description In Berland a bus travels along the main street of the capital. The street begins from the main square and looks l…
链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=61581#overview 描写叙述:非常老的CF题,题不错,拿来训练正好. 做的时候刚做完BC,还时不时去hdu看看有木有judge结束,题有木有挂掉,脑子有点糊涂,当时过了三题(按自己平时做CF的顺序作的).代码写得也非常繁琐(就记得B题T成狗,最后在群里的提醒下过了...).当然如今脑子也是糊涂.打完北京赛区然后就要连续考试三门我也是醉了. 要不是立即比赛就要关了赛后AK的时…
codeforces 808G Anthem of Berland 题面 给定\(s\)串和\(t\)串,字符集是小写字母.\(s\)串中有些位置的值不确定,要求你确定这些位置上的值,使得\(t\)在\(s\)中出现次数最多,输出最多出现次数. 参考博客 http://www.cnblogs.com/Oncle-Ha/p/7061929.html 题解 AC自动机预处理 \(ne[i][j]\):字符串 \(t[i]+j\) 的后缀最长匹配到 \(t[ne[i][j]]\). 状态\(f[i][…
B. Making Genome in Berland 题目连接: http://www.codeforces.com/contest/638/problem/B Description Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has notin…
C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.…
C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were s…
题目链接:http://codeforces.com/contest/440/problem/D D. Berland Federalization   Recently, Berland faces federalization requests more and more often. The proponents propose to divide the country into separate states. Moreover, they demand that there is a…
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫描线搞一搞区间(主席树也OK啊,只是空间玄学,主席树理论空间nlogn实际上开小那么10倍8倍没什么锅啊zzzz),对于权值建立权值线段树,然后记录每个权值出现的次数以及区间权值和,然后在线段树上二分求答案即. #include<cstdio> #include<cstring> #i…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrou…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. E…
A.Regular bracket sequence A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting…
E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Pr…