AT3949-[AGC022D]Shopping【贪心】】的更多相关文章

Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走,走到n+1点需要最少步数.思路是:因为走某些点时,必须先走另外一点,所以可以用贪心算法,将限制条件可以看成区间,求出它们的并集,如下图: #include<iostream> #include<algorithm> #include<cstring> #include&l…
题意:给定 n 个商店,然后有 m个限制,去 c 之前必须先去d,问你从0到n+1,最短路程是多少. 析:我们我们要到c,必须要先到d,那么举个例子,2 5, 3 7,如果我们先到5再到2,再到7再到3,那么3-5这个区间我们走了4次,如果我们先到7再到2, 那么就只走了3次,这很明显是最优的,所以我们把能合并的区间都合并起来,然后再一块计算. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include…
A    Knight 留坑. B    Tree 思路:两次树形DP,但是要考虑0没有逆元 可以用前缀后缀做 #include <bits/stdc++.h> using namespace std; #define N 1000010 #define ll long long ; int n; ll dp[N], dp2[N]; ll prefix[N], suffix[N]; vector <int> G[N]; void Init() { ; i <= n; ++i)…
Day2 上午 <IOI题型与趣题分析> 来源 题目 完成情况 备注 IOI2002 Day1T1 Frog 已完成 IOI2002 Day1T2 Utopia IOI2002 Day1T3 xor 已完成 提交答案 IOI2002 Day2T1 Batch IOI2002 Day2T2 Bus IOI2002 Day2T3 Rods 交互题 NEERC2002 Cricket Field POI2001 Goldmine IOI2008 Pyramid Base IOI2019 Day1T3…
题目传送门 /* 题意:有n个商店排成一条直线,有一些商店有先后顺序,问从0出发走到n+1最少的步数 贪心:对于区间被覆盖的点只进行一次计算,还有那些要往回走的区间步数*2,再加上原来最少要走n+1步就是答案了 详细解释:http://blog.csdn.net/u013625492/article/details/45640735 */ #include <cstdio> #include <algorithm> #include <cstring> #include…
正题 题目链接:https://www.luogu.com.cn/problem/AT3949 题目大意 长度为\(L\)的坐标轴上,给出\(n\)个点,每个点\(x_i\)需要购物\(t_i\)的时间,一辆车在\(0\sim L\)折返跑,求从\(0\)出发购物完回到\(0\)的最短时间. \(n\in[1,3\times 10^5],L\in[1,10^9]\),输入的\(x_i\)单调递增. 解题思路 挺奇妙的题目,\(WC2021\)讲课的题. 首先每个\(t_i\)先\(\%\)上一个…
#include <bits/stdc++.h> using namespace std; ; int fa[maxn]; int main(){ int n, m; scanf("%d%d", &n, &m); ; i <= n+; i++) fa[i] = i; ; i <= m; i++){ int x, y; scanf("%d%d", &x, &y); fa[x] = max(fa[x], y); }…
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For e…
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goo…