CodeForces 1419F Rain of Fire】的更多相关文章

题意 不想写. 题解 场上想了 1h+ 无果,一到场外就口胡出来了,我真是个 sb. 首先注意到如果 \(t\) 满足条件那么 \(t+1\) 也会满足,所以答案具有单调性,可以二分,于是现在只需要考虑对于某个特定的 \(t\) 能否满足. 注意到对于平面上的 \(u,v,w\) 三个点来说,如果 \(u\) 能到 \(v\),\(v\) 能到 \(w\) 那么 \(u\) 一定能到 \(w\). 既然这个可达性是可以传递的,那么可以用一个并查集来将相互到的点缩成一个连通块. 如果连通块个数为…
题目链接:http://codeforces.com/contest/988/problem/F 题目大意: 有三个整数a,n,m,a是终点坐标,给出n个范围(l,r)表示这块区域下雨,m把伞(p,w)在点p有重量为w的伞. 小明可以携带任意数量的伞,经过下雨处时必须要撑伞,小明每走一个单位长度消耗的体力与他所携带伞的重量相同, 求小明从0~a所需消耗的最少体力,若无解则输出-1. 解题思路: 第一种解法: 设dp[i]表示到达i点所需花费的最少体力,rain[i]表示第i段是否下雨(注意是段不…
题意:失火了,有n个物品,每个物品有价值pi,必须在时间di前(小于di)被救,否则就要被烧毁.救某个物 品需要时间ti,问最多救回多少价值的物品,并输出救物品的顺序. Examples Input 33 7 42 6 53 7 6 Output 1122 3 Input 25 6 13 3 5 Output 111 思路:有点像一个背包,dp数组记录的是当前时间所能获得的最大价值,转移方程dp[j]=max(dp[j],dp[j-t[i].ti]+t[i].w) path[i][j]表示到i号…
解题思路:动态规划 遍历点i,如果从前一个点i-1走到这个点i不需要伞,则疲劳值不变dp[i] = dp[i-1]. 如果前一个点i-1走到这一个点i需要伞,则从前面找一把伞. 即遍历前面的每个点j,如果点j处有伞,dp[i] = min(dp[i], dp[j]+(i-j)*fig[j]).fig[j]意为第j个点出伞所需要的疲劳值. 代码 #include <bits/stdc++.h> using namespace std; typedef long long ll; bool seg…
是个补题记录. 1419 除了 F 场上都过了. CF1419A Digit Game 这题好多人 FST 啊-- 考虑如果串长为奇数那么最后操作的肯定是第一个人,串长为偶数的最后操作的肯定是第二个,而且两个人的操作互相独立. 所以如果最后一个操作的是第一个人而且存在一个奇数位置上的数是奇数的话那么第一个人肯定赢,否则第二个人肯定赢. 最后一个操作的是第二个人的话同理. 代码 CF1419B Stairs 很明显只有当 \(n=2^k-1\) 的时候 \(n\) 级的阶梯才会是好的,然后从小到大…
一个造物游戏: acidrain=rain+smoke airlplain=metal+bird alcohol=fruit+time algae=plant+water allergy=dust+human alligator=swamp+lizard angel=human+bird antarctica=desert+snow aquarium=glass+water archipelago=isle+isle armor=metal+tool ash=energy+volcano ast…
Description Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take tiseconds to save i-th item. In addition, for each item, he estimated the value of di — the mom…
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E Description Polycarp lives on a coordinate line at the point x=0. He goes to his friend that lives at the point x=a. Polycarp can…
题目传送门:http://codeforces.com/contest/1119/problem/D D. Frets On Fire time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Miyako came to the flea kingdom with a ukulele. She became good friend…
http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择这件物品时需要一定的时间,在这段时间之内不能选择其他物品),选择这件物品只能在失效时间之前选择.问选择的最大价值是多少. 思路: 对于每一个物品,有选和不选两种操作,与01背包是相似的.但是此题选择的顺序会影响到结果,这是01背包不同的地方. 比如 a.st = 3,a.en = 5,a.v = 4…
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would…
题目链接:http://codeforces.com/problemset/problem/1121/A 真·阅读理解 题意就是 有n个人 pi表示他们的强度 si表示他们来自哪个学校 现在Arkady选了K个人 如果这其中有某些人不是他们学校里最强的,你就让这个人自己去一个学校 他就是这个新学校里面最强的 那么就一定会被选上 并且他原学校的最强的也会被选上 也就是 k个人里有哪个人不是最强的就必须多一个学校呗 读题半小时代码几分钟.. 代码如下 #include <cstdio> #incl…
题目链接:D. Frets On Fire 思路:明明可以离散化+二分写,思路硬是歪到了线段树上,自闭了,真实弟弟,怪不得其他人过得那么快 只和查询的区间长度有关系,排完序如果相邻的两个点的差值小于等于查询的区间长度,那么给结果带来的变化就会新增差值个数,如果大于区间长度那么就会新增区间长度个数 维护的话,线段树和二分都可以,二分需要离散化处理,再给差值排个序,每次找到第一个大于当前区间长度的差值位置就好了,(没实现,但是理论上应该没问题) 线段树直接动态开点可以不用离散化.. 实现代码: #i…
一.题目链接:http://codeforces.com/contest/988/problem/F 二.题面 三.思路 很明显而且比较能想到的$dp$. 四.代码实现 #include<bits/stdc++.h> using namespace std; #define fst first #define snd second #define MAXN 2018 typedef pair<int, int> PII; typedef long long LL; int dest…
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it…
A. Pouring Rain time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have de…
题目链接 Fire 题意 有n个物品,每个物品的挽救时间代价为ti, 消失时刻为di, 价值为pi. 如果要救某个物品,必须在他消失之前救出来. 同一时刻最多只能救一件物品. 当前耗时为当前已经救出的物品的ti累积. 你需要救出总价值尽可能大的物品,并输出方案. 考虑DP f[i][j]为考虑前i个物品,获得总价值为j的时候,所用时间的最小值. c[i][j]为在搜索到第i件物品,当前总价值为j的时候下一步的价值搜索状态. 则有f[i][j] = f[i - 1][j - p[i]] + t[i…
题目链接: A. Pouring Rain time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you h…
Rain and Umbrellas 题意:某同学从x=0的点走到x=a的点,路上有几段路程是下雨的, 如果他需要经过这几段下雨的路程, 需要手上有伞, 每一把伞有一个重量, 求走到重点重量×路程的最小花费. 题解:暴力,如果某段路程需要带伞,就直接去找前面有伞的地点,如果不需要伞就直接往后走就好了. 代码: #include<bits/stdc++.h> using namespace std; const int N = 1e5; const int INF = 0x3f3f3f3f; i…
题目链接:http://codeforces.com/contest/864/problem/E 题解:这题一看就很像背包但是这有3维限制也就是说背包取得先后也会对结果有影响.所以可以考虑sort来降低维度(这是常用的方法) 然后就是简单的有限背包至于这题还要求存下娶了哪些东西可以用vector来存. #include <iostream> #include <cstring> #include <cstdio> #include <vector> #inc…
E - Earth Wind and Fire 思路: 栈模拟 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi first #define se second #define pi acos(-1.0) #define LL long long //#…
题目链接: http://codeforces.com/contest/1148/problem/E 题意: 给出两个长度为$n$的序列,将第一个序列变成第二个序列,顺序不重要,只需要元素完全相同即可 只有一种修改操作 $a_i=a_i+d,a_j=a_j-d$满足 $a_j-a_i\geq 2 \cdot d$ 数据范围: $1\leq n\leq 3e^{5}$ 分析: 先说结论: 对$a,b$数组排序,结果一定是$a_i$变成$b_i$,也就是一一对应的关系 有些数需要增加,有些数需要减少…
原题连接:http://codeforces.com/problemset/problem/864/E 题意:一个人想从大火中带走一些东西.每次他只能带一个,耗时ti ,价值为pi, 当总时间超过di时不能被带走.问他如何按顺序带走物品使价值总和最大. 思路:背包问题.分为取和不取两种情况1.dp[i][j]=max(dp[i-1][j], dp[i-1][j-t]+p), j<d; 2.dp[i][j]=max(dp[i-1][j], dp[i][j]); AC代码: #include<io…
https://codeforces.com/problemset/problem/864/E 这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影响到之前的. #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> #include <stack> #include <vector> #inc…
背包DP,决策的时候记一下 jc[i][j]=1 表示第i个物品容量为j的时候要选,输出方案的时候倒推就好了 #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; struct poi{int t,ddl,p,id;}a[maxn]; int n,top,ansi,cnt;…
传送门 题意 给出n种物品,抢救第\(i\)种物品花费时间\(t_i\),价值\(p_i\),截止时间\(d_i\) 询问抢救的顺序及物品价值和最大值 分析 按\(d_i\)排序的目的是防止以下情况 4 8 100 1 2 100 不排序只能选择第一个物品 (请仔细思考) 那么排序后做一遍背包,排序后选择顺序必定是递增的,求路径时从n往前找,具体见代码 code #include<bits/stdc++.h> using namespace std; #define ll long long…
大意: $n$个石子, 第$i$个石子初始位置$s_i$, 每次操作选两个石子$i,j$, 要求$s_i<s_j$, 任取$d$, 满足$0\le 2d\le s_j-s_i$, 将$s_i,s_j$改为$s_i+d,s_j-d$. 给定数组$t$, 求是否能将所有石子位置摆成数组$t$. 没要求最小化操作数, 所以直接贪心选即可, 操作数一定是不超过$n$的. 这场当时没时间打, 感觉好亏. #include <iostream> #include <sstream> #i…
分析 必要条件: ① $\sum_{i=1}^{n} s_i = \sum_{i=1}^{n} t_i$ 预处理: 将 $s, t$ 从小到大排序. 尝试一 首尾匹配.例子 s = 2, 2, 4, 7, 9 t = 4, 5, 5, 5, 5 4, 2, 4, 7, 7 4, 4, 4, 7, 5 4, 5, 4, 6, 5 4, 5, 5, 5, 5 反例 s = 1, 4, 5, 8 t = 2, 3, 6, 7 key observation: 考虑排好序的 $s$ 和 $t$. ① 要…
题目链接: http://codeforces.com/problemset/problem/6/D D. Lizards and Basements 2 time limit per test2 secondsmemory limit per test64 megabytes 问题描述 This is simplified version of the problem used on the original contest. The original problem seems to hav…
传送门 D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to rest…