Problem C Shopping 闭环贪心】的更多相关文章

#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); }…
Problem UVA11134-Fabled Rooks Accept: 716  Submit: 6134Time Limit: 3000mSec Problem Description We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to the following restrictions• The i-th rook can only be placed within the rectangl…
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo…
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of t…
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. A…
题意:鞋匠一口气接到了不少生意,但是做鞋需要时间,鞋匠只能一双一双地做,根据协议每笔生意如果拖延了要罚钱. 给出每笔生意需要的天数和每天的罚钱数,求出最小罚钱的排列顺序. 只要按罚款/天数去从大到小排序,如果比例一样就按序号排序(要求字典序). 解释我就不献丑了,附上Staginner大神的证明: 对于为什么贪心策略是这个样子的,我们不妨拿相邻的两个事件a.b来说明一下.由于a.b之后的事件是固定的,所以我们无论排成ab还是排成ba后面部分的损失都是固定的,那么损失的差别主要来源于究竟是排成ab…
正题 题目链接: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\)先\(\%\)上一个…
一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不上人,而A已经赢了一场,所以A只要再赢一场就可以了,A的最优策略是把自己剩下的全上去,即为(a,n-a,0)的形式,B的最优为(0,m-1,1)的形式,若A要赢就是(n-a) >= (m-1).如果B选择在第一场赢的话,那B应该在第一场放上a+1个人,A的最优为(a,(n-a)/2,(n-a)/2)…
Problem J: 幻化 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 18 Solved: 3 [Submit][Status][Web Board] Description 遇见你是我一世的春暖花开, 从此清风明月浩瀚星海. 不论结局,很高兴认识你. 她给了他一个长度为n的整数序列a[],他还给了她另外一个长度为n的整数序列b[],现在他想通过每次交换a[i],a[j]使序列a变成b,但是每次交换的代价是|j-i|. 请问最少的代价是多少呢?…
题意 A和B在树上轮流选点,记A的联通块个数为\(x\),B的联通块个数为\(y\) A使\(x - y\)最大,B使\(x - y\) 二人采取最优策略,求\(x-y\) 题解 树联通块个数 = 点数 - 边数 有这个转化,我们记二人选的点数为P,联通块内边数为E 则\(ans = (P_{A} - E_{A}) - (P_{B} - E_{B})\) 其中\(P\)的差是固定的 我们要求的是\(E_{A} - E_{B}\) A会使这个值尽量大,会使其选的边尽量少 B会使这个值尽量小,会使其…