【CF1016F】Road Projects(贪心)】的更多相关文章

题意:给你一棵n 个节点的树,定义1到n的代价是1到 n节点间的最短路径的长度. 现在给你 m 组询问,让你添加一条边权为 w 的边(不与原图重复),求代价的最大值.询问之间相互独立. 1≤n,m≤3×1e5,1<=c[i]<=1e9,1<=w<=1e9 思路:网上dalao们的写法好像都和我不太一样…… 考虑将1-n路径上所有的点取出,则原树变成了一条链和若干条子树 首先判断以链上某一点为根的子树size是否>=3,若是则可以在其内部连边,对最短路没有影响 若没有则考虑在链…
思路 可以考虑另一种想法:因为我们发现,答案是肯定不会大于在原来的树上的最短路径的.所以原来的最短路是(有可能的)最大值! 我们把树变成这样,提取出1~n的路径,方便观看撕烤: (它有个我起的名字,叫灯笼树态,处理树上路径与其余部分之间的关系时画图用,并非真实的数据结构) 我们称被提取出来的树上路径(本题为1~n)为灯笼线,路径上每一个节点及其下悬挂的子树称为灯笼子树,每一个灯笼子树的根节点叫悬挂点. 显然,悬挂点一定在灯笼线上.任意一个点的悬挂点就是它所在的灯笼子树的悬挂点.一个点如果在灯笼线…
Description 题库链接 给你一棵 \(n\) 个节点的树,定义 \(1\) 到 \(n\) 的代价是 \(1\) 到 \(n\) 节点间的最短路径的长度.现在给你 \(m\) 组询问,让你添加一条边权为 \(w\) 的边(不与原图重复),求代价的最大值.询问之间相互独立. \(1\leq n,m\leq 3\times 10^5\) Solution 辣鸡老余毁我青春 把 \(1\) 至 \(n\) 的路径提取出来,显然图就变成了一条链加上若干子树.贪心的思想是找这样一组点,满足 其所…
题目地址 Edu48 A.Death Note 翻译 你有一个无穷页的本子,每一页可以写\(m\)个名字, 你在第\(i\)天要写\(a_i\)个名字,如果这一页恰好写满了,你就会翻页, 问每天的翻页次数. 题解 傻逼题,求个前缀和,然后除\(m\)计算前缀翻页次数,再和前面一天减一下就好. 代码 #include<cstdio> #define ll long long #define MAX 200200 inline int read() { int x=0;bool t=false;c…
Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29, Accepted users: 29 Problem 12882 : No special judgement Problem description You are planning a road trip to visit your friends, each of whom live in…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) 问题描述 XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在…
题目 做法 对于加分的直接贪心 而掉分的用排序后的背包动规 假设有两个物品\((a_1,b_1)(a_2,b_2)\) 选第一个物品后无法选择第二个物品,假设开始值为\(r\):\(r>a_1,r+b_1<a_2\Longrightarrow r<a_2-b_1\) 如果先选择第二个物品后可以选择第一个物品:\(r>a_2,r+b_2\ge a_1\Longrightarrow r\ge a_1-b_2\) 则当\(a_1-b_2\le a_2-b_1\)时,先选择\(2\)更优:…
题目链接:传送门 思路: 对于对rating有提升的项目,肯定做越多越好,所以把$b_{i} >= 0$的项目按rating要求从小到大贪心地都做掉,得到最高的rating记为r. 对于剩余的$b_{i} < 0$的项目,因为r的范围很小,在6e4的亚子,可以考虑用01背包来做. 但是直接上01背包会WA,是因为不同项目选择的先后顺序会对结果有影响. 比如现在的r是5,有两个项目,(ai,bi)分别为(3,-3)和(3,-1),如果先做前面的项目,就会导致rating不够做后一个项目. 考虑任…
https://www.cnblogs.com/flipped/p/6083973.html       原博客转载 http://codeforces.com/group/1EzrFFyOc0/contest/738/problem/C     题目链接 题意:n个价格c[i],油量v[i]的汽车,求最便宜的一辆使得能在t时间内到达s,路途中有k个位置在g[i]的加油站,可以免费加满油,且不耗时间.每辆车有两种运行模式可以随时切换:1.每米一分钟两升油:2.每米两分钟一升油. 题解:二分求可以…
http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 YES input 3 - - output 3 YES input 4 - output 4 NO Note In the first example, the possible order is: 1,2,3. In the second example, the possible order…
题目:Qin Shi Huang's National Road System Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2049    Accepted Submission(s): 746 Problem Description During the W…
Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---…
题目链接: 传送门 find the most comfortable road Time Limit: 1000MS     Memory Limit: 32768 K Description XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Flycar的"舒适度"有特殊要求,即乘坐过程中最高速度与最低速度的差越小…
Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3843    Accepted Submission(s): 1336 Problem Description During the Warring States Period of ancient China(47…
Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a comment » Introduction Well after a long journey through Linux, Python, Python Libraries, the Stock Market, an Introduction to Neural Networks and tr…
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停下来,竖直走. // 问走到终点的最短时间 // 思路: // 1.贪心来做 // 2.我觉的二分更直观 // 可以抽象成:一条射线与凸边行相交,判断交点.二分找切点 #include <bits/stdc++.h> using namespace std; #define LL long lon…
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, biology, and even musicology as background. And now in this prob…
Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1287    Accepted Submission(s): 475 Problem Description During the Warring States Period of ancient China(47…
JavaScript Application Architecture On The Road To 2015 I once told someone I was an architect. It’s true in a way since I now have to design an intricate web of lies to back it up. On a serious note, I thought it might be salutary to look at the sta…
G - 贪心 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description   Simon and Garfunkel Corporation (SG Corp.) is a large steel-making company with thousand of customers. Keeping the customer satisfied is one of…
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…
Steal the Treasure Time Limit: 10000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 775    Accepted Submission(s): 213 Problem Description The alliance of thieves decides to steal the treasure from country A.…
E - 贪心 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.M…
Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Description John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachab…
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Fly…
题目描述 Farmer John's cows are trying to learn to cross the road effectively. Remembering the old "why did the chicken cross the road?" joke, they figure the chickens must be experts on crossing the road, and go off in search of chickens to help th…
Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 1371    Accepted Submission(s): 448 Problem Description There are n apple trees planted along a cyclic road, which is L metres…
Description During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China -- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally con…
来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's fuel tank. The truck now leaks one unit of fuel every…
[hdu P4081] Qin Shi Huang’s National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in…