CodeForces 702D Road to Post Office】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公里就要花费 t秒修一次才可以继续开,车每公里花费 a秒,步行每公里花费 b秒.依次给出d, k, a, b, t.问最少需要花费多少时间到达邮局.车刚开始时是好的. 思路: 首先可以模拟一下,可以想到,如果车速比步速块,那么前 k公里路肯定选择坐车,因为开始时车是好的,不用花费多余的时间来修理车,否…
答案的来源不外乎于3种情况: 纯粹走路,用时记为${t_1}$:纯粹乘车,用时记为${t_2}$:乘车一定距离,然后走路,用时记为${t_3}$. 但是${t_1}$显然不可能成为最优解. 前两个时间都挺好算的,${t_3}$算的时候要讨论一下. 如果是$a*k+t>=b*k$,那么也就是说第一个$k$的距离开车,然后开始走路. 如果是$a*k+t<b*k$,那么可以尝试着最后不到$k$的距离走路,前面的都开车. 直接得出数学公式有点难度,因为最优解不会逃出${t_1}$,${t_2}$,${…
http://codeforces.com/contest/702 题意:人到邮局去,距离d,汽车在出故障前能跑k,汽车1公里耗时a,人每公里耗时b,修理汽车时间t,问到达终点最短时间 思路:计算车和人的平均速度,谁快用谁,最后特判<=k的距离 // #pragma comment(linker, "/STACK:102c000000,102c000000") #include <iostream> #include <cstdio> #include &…
题目链接: D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals t…
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d ki…
Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解: 首先要分成k段,k段的总长是ovmod,每一段可以选择修车坐车或选择走路,(只有第一段的时候不用修车),最后在加上剩下的那些路的时间,剩下的是mod,(可以选择修车坐车或选择走路)最后min答案就好了.但其中还有一种情况要注意,就是前ovmod也可以选择坐车之后不修走着,所以这种要特殊处理下.…
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d ki…
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d ki…
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d ki…
Codeforce 702 D. Road to Post Office 解析(思維) 今天我們來看看CF702D 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒想到意外的是思考非常簡單的一題 @copyright petjelinux 版權所有 觀看更多正版原始文章請至petjelinux的blog 想法 如果坐車\(k\)公里加上修理比走路\(k\)公里還要慢,那麼我們只需要先坐車\(k\)公里,然後不要修,直接走路走完全程. 如果坐車\(k\)公里加上…
题目描述 Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to ddkilometers. Vasiliy's car is not new — it breaks after driven every kk kilometers and Vasiliy needs tt seconds to repair it. Afte…
题目链接:http://codeforces.com/contest/543/problem/D 给你一棵树,初始所有的边都是坏的,要你修复若干边.指定一个root,所有的点到root最多只有一个坏边.以每个点为root,问分别有多少种方案数. dp[i]表示以i为子树的root的情况数,不考虑父节点,考虑子节点.   dp[i] = dp[i] * (dp[i->son] + 1) up[i]表示以i为子树的root的情况数(倒着的),考虑父节点,不考虑子节点.  这里需要逆元. 注意(a/b…
http://codeforces.com/contest/543/problem/D 题意: 给定n个点的树 问: 一开始全是黑边,对于以i为根时,把树边白染色,使得任意点走到根的路径上不超过一条黑边,输出染色的方案数(mod 1e9+7) 思路:得知f[x]=(f[s1]+1)*(f[s2]+1)*(f[s3]+1)..*(f[sn]+1),s为x的儿子 因为要么这条边修了,里面有f[s1]方案,要吗不修,那剩下的都必须修. 由于要计算每个点的答案. 我们令up[x]为x父亲为x儿子时的f答…
最小树形图裸题,只是须要记录路径 E. Road Repairs time limit per test 2 seconds memory limit per test 256 megabytes input input.txt output output.txt A country named Berland has n cities. They are numbered with integers from 1 to n. City with index 1 is the capital o…
题目链接 http://codeforces.com/problemset/problem/729/C 题意:n个价格c[i],油量v[i]的汽车,求最便宜的一辆使得能在t时间内到达s,路途中有k个位置在g[i]的加油站,可以免费加满油,且不耗时间.每辆车有两种运行模式可以随时切换:1.每米一分钟两升油:2.每米两分钟一升油. 看到10^5次加上循环两次就想到二分或者线段树或者看错题意了. 这题二分查找一下汽油就可以了,找到最少多少汽油够到达,然后再for一遍找汽油量大的且价格便宜的车即可. 还…
题意 输入第一行有4个数,分别为\(L,n,p,t\),分别表示总长度为\(L\)的路,中间有\(n\)个互不相交的区间,现在要用长度为\(p\)的小木棒从左往右铺路(木棒不能被折断,也不能有重叠,且所有的木棒必须在区间内),你可以连续铺路,但是一旦你主动或被迫中断铺路(比如区间内剩下的长度不足以放下一根木棍)那么下一根开铺的木棍最少也要在\(t\)距离之后.问最多能铺多少根木棍.接下来的\(n\)行表示从左到右的\(n\)个区间. 想法 首先当然是想暴力的算法...dp? \(f_i\)表示铺…
题目大概说给一棵树,树的边一开始都是损坏的,要修复一些边,修复完后要满足各个点到根的路径上最多只有一条坏的边,现在以各个点为根分别求出修复边的方案数,其结果模1000000007. 不难联想到这题和HDU2196是一种类型的树形DP,因为它们都要分别求各个点的答案.然后解法也不难想: dp0[u]表示只考虑以u结点为根的子树的方案数 dp1[u]表示u结点往上走,倒过来,以它父亲为根那部分的方案数 有了这两部分的结果,对于各个点u的答案就是dp0[u]*(dp1[u]+1).这两部分求法如下,画…
题目链接 Solution 比较明显的树形DP模型. 首先可以先用一次DFS求出以1为根时,sum[i](以i为子树的根时,满足要求的子树的个数). 考虑将根从i变换到它的儿子j时,sum[i]产生的变化. 在变化前sum[i]不为0时,可以用求逆元的方法求出新的sum[i]. sum[i]为0时,就需要遍历i的新的儿子. 官方的题解给出了一个比较好的做法是预处理i的儿子的前缀积,和后缀积.使用的时候只要去除相应的儿子. #include <bits/stdc++.h> #define LL…
Description 题库链接 给你一棵 \(n\) 个节点的树,定义 \(1\) 到 \(n\) 的代价是 \(1\) 到 \(n\) 节点间的最短路径的长度.现在给你 \(m\) 组询问,让你添加一条边权为 \(w\) 的边(不与原图重复),求代价的最大值.询问之间相互独立. \(1\leq n,m\leq 3\times 10^5\) Solution 辣鸡老余毁我青春 把 \(1\) 至 \(n\) 的路径提取出来,显然图就变成了一条链加上若干子树.贪心的思想是找这样一组点,满足 其所…
二分答案. 油量越多,显然通过的时间越少.可以二分找到最小的油量,可以在$t$时间内到达电影院. 一个油箱容量为$v$的车通过长度为$L$的路程需要的最小时间为$max(L,3*L-v)$.计算过程如下: 假设普通速度运行了距离$a$,加速运行了距离$b$,则$a+b=L$,即$b=L-a$. 因为$a+2*b≤v$,所以$a≥2*L-v$.所花时间为$2*a+b≥3*L-v$,因为最小需要$L$的时间,所以取个$max$.按照$max(L,3*L-v)$一段一段加起来验证就可以了. #prag…
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <vector> #include &…
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d ki…
A题Maximum Increase 大水题.最长连续递增子序列有多长. #include <cstdio> #include <algorithm> using namespace std; int main() { , len = , ans = ; scanf("%d",&n); ; i < n; i++) { scanf("%d", &a); if(a > rec) { rec = a, len++; }…
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis of Algorithms_Second Edition>> _ Anany LevitinNote that throughout the paper, we assume that inputs to algorithms fall within their specified ranges…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停下来,竖直走. // 问走到终点的最短时间 // 思路: // 1.贪心来做 // 2.我觉的二分更直观 // 可以抽象成:一条射线与凸边行相交,判断交点.二分找切点 #include <bits/stdc++.h> using namespace std; #define LL long lon…
B. President's Office 题目连接: http://codeforces.com/contest/6/problem/B Description President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a un…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a str…
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t m…
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t m…