P3045 [USACO12FEB]牛券Cow Coupons】的更多相关文章

P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 86分求救 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget…
P3045 [USACO12FEB]牛券Cow Coupons 贪心题.先选中 \(c_i\) 最小的 \(k\) 头牛,如果这样就超过 \(m\) ,直接退出,输出答案.否则考虑把后面的牛依次加入,替换前面用过券的牛.这里贪心得选择省钱最少的牛替换掉(这样影响最小,最有可能多买几头).加入牛的顺序按照 \(p\) 从小到大,因为如果换不掉就只能话 \(p\) 的钱去买 #include<bits/stdc++.h> using namespace std; #define int long…
[USACO12FEB]牛券Cow Coupons(堆,贪心) 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). Cow i costs P_i money (1 <= P_i <= 10^9), b…
嘟嘟嘟 这其实是一道贪心题,而不是dp. 首先我们贪心的取有优惠券中价值最小的,并把这些东西都放在优先队列里,然后看[k + 1, n]中,有些东西使用了优惠券减的价钱是否比[1, k]中用了优惠券的物品更划算,是的话就更新. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> #include<cstdlib&g…
LuoguP3045 [USACO12FEB]牛券Cow Coupons 果然我贪心能力还是太差了 ZR讲过的原题我回来对做法没有一丁点印象 有时候有这样一种题目 每个数有两种不同的价值 你可以选择价值低的,也可能花费一些神秘能力去获得价值高的 这时候我们直接贪心就可能会出现这种情况 当前最后解不是全局最优解 一般这种时候有两节决策, 要么DP 要么尝试进行可反悔的贪心 我们先按照所有牛的优惠后的价格排序,开一个小根堆 将前\(k\)个用优惠劵去买,很明显这可能是错误的 我们就将优惠券买的每一头…
USACO12FEB 久违的奶牛题. 题意: FJ准备买一些新奶牛,市场上有 $ N $ 头奶牛 $ (1 \leq N \leq 50000) $ ,第i头奶牛价格为 $ P_i (1 \leq P_i \leq 10^9) $ .FJ有K张优惠券,使用优惠券购买第i头奶牛时价格会降为 $ C_i(1\leq C_i \leq P_i) $ ,每头奶牛只能使用一次优惠券.FJ想知道花不超过 $ M(1 \leq M \leq 10^{14}) $ 的钱最多可以买多少奶牛? 解法: 在ZR时摸鱼…
[Usaco2012 Feb] Cow Coupons 一个比较正确的贪心写法(跑得贼慢...) 首先我们二分答案,设当前答案为mid 将序列按照用券之后能省掉的多少排序,那么我们对于两种情况 \(mid \leq k\) 全部取用券后的,取最小的\(mid\)个 排序后我们枚举分界点,对于右边\(p-c\)较大的,我们肯定考虑把k个券用给它们,就可以在左边取\(p\)最小的\(mid-k\)个,和右边的\(c\)最小的\(k\)个即可 这个我们用堆维护即可 #include<bits/stdc…
P2877 [USACO07JAN]牛校Cow School 01分数规划是啥(转) 决策单调性分治,可以解决(不限于)一些你知道要用斜率优化却不会写的问题 怎么证明?可以暴力打表 我们用$ask(l,r,dl,dr)$表示处理区间$[l,r]$时,这段区间的决策点已固定在$[dl,dr]$中 设$mid=(l+r)/2$,暴力处理$mid$的最优决策点$dm$ 再向下分治$ask(l,mid-1,dl,dm)$,$ask(mid+1,r,dm,dr)$ 对于本题,先按$t[i]/p[i]$从大…
P2883 [USACO07MAR]牛交通Cow Traffic 对于每一条边$(u,v)$ 设入度为0的点到$u$有$f[u]$种走法 点$n$到$v$(通过反向边)有$f2[v]$种走法 显然经过这条边的方案数为$f[u]*f2[v]$ 两边递推处理$f$数组,然后枚举每条边取个$max$. #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namesp…
康托展开 康托展开为全排列到一个自然数的映射, 空间压缩效率很高. 简单来说, 康托展开就是一个全排列在所有此序列全排列字典序中的第 \(k\) 大, 这个 \(k\) 即是次全排列的康托展开. 康托展开是这样计算的: 对于每一位, 累计除了前面部分, 字典序小于本位的排列总数, 即 LL cantor(){ LL ans = 0; for(LL i = 1;i <= num;i++){ LL cnt = 0; for(LL j = i + 1;j <= num;j++){ if(ask[j]…
P2419 [USACO08JAN]牛大赛Cow Contest Floyd不仅可以算最短路,还可以处理点之间的关系. 跑一遍Floyd,处理出每个点之间是否有直接或间接的关系. 如果某个点和其他$n-1$个点都有关系,那么它的排名就是可确定的. #include<iostream> #include<cstdio> #include<cstring> #define re register using namespace std; ][],ans; int main(…
P3048 [USACO12FEB]牛的IDCow IDs 12通过 67提交 题目提供者lin_toto 标签USACO2012 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 谁能解释一下这个样例啊.... 题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitiou…
P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing a game similar to human hopscotch. Their hopscotch game features a line of N (3 <= N <= 250,000) squares conveniently labeled 1..N that are chalked o…
P2952 [USACO09OPEN]牛线Cow Line 题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a line. The line begins with no cows and then, as time progresses, one by one, the cows join the line on the left or right side. Every once in a while, s…
P2419 [USACO08JAN]牛大赛Cow Contest 题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating t…
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Submit][Status][Discuss] Description Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his bud…
P2883 [USACO07MAR]牛交通Cow Traffic 随着牛的数量增加,农场的道路的拥挤现象十分严重,特别是在每天晚上的挤奶时间.为了解决这个问题,FJ决定研究这个问题,以能找到导致拥堵现象的瓶颈所在. 牧场共有M条单向道路,每条道路连接着两个不同的交叉路口,为了方便研究,FJ将这些交叉路口编号为1..N,而牛圈位于交叉路口N.任意一条单向道路的方向一定是是从编号低的路口到编号高的路口,因此农场中不会有环型路径.同时,可能存在某两个交叉路口不止一条单向道路径连接的情况. 在挤奶时间到…
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 306  Solved: 154[Submit][Status][Discuss] Description Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his bud…
P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The cows will arrange themselves in a line and ask Far…
P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N cows jogging on an infinitely-long single-lane track (1 <= N <= 100,000). Each cow starts at a distinct position on the track, and some cows jog at…
Description Farmer  John  needs  new  cows! There  are  N  cows  for  sale (1 <= N <= 50,000), and  FJ  has  to  spend  no  more  than  his  budget  of  M  units  of  money (1 <= M <=$10^{14}$). Cow  i  costs $ P_i$  money (1 <=$ P_i$ <=…
题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competito…
如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里:  简陋的博客    百度百科 题目描述 N(1<=N<=20)头牛,编号为1...N,正在与FJ玩一个疯狂的游戏.奶牛会排成一行(牛线),问FJ此时的行号是多少.之后,FJ会给牛一个行号,牛必须按照新行号排列成线. 行号是通过以字典序对行的所有排列进行编号来分配的.比如说:FJ有5头牛,让他们排为行号3,排列顺序为: 1:1 2 3 4 5 2:1 2 3 5 4 3:1 2 4 3 5 因此,牛将在牛线1 2 4 3 5中. 之后,…
题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competito…
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=118 传送门2:http://www.lydsy.com/JudgeOnline/problem.php?id=2590 又挂了一道贪心,好烦啊. 这一题应该要想到“撤回”操作就好办了.假设现在已经没有优惠券了,那么如果你想以优惠价格买下一头牛,就要撤回以前的用优惠券买的牛,具体就是加回p[i] - c[i]就行了,可以理解为花这么多钱买一张优惠券.然后就是维护3个小根堆了.…
题目大意 有N (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同.由于是单人跑道,所有他们之间不能相互超越.当一头速度快的奶牛追上另外一头奶牛的时候,他必须降速成同等速度.我们把这些跑走同一个位置而且同等速度的牛看成一个小组. 请计算T (1 <= T <= 1,000,000,000)时间后,奶牛们将分为多少小组. 题解 定义两头牛"能单独追上"为:若跑道上只有这两头牛,则它们能否追上.牛i和牛j(j>i)将…
https://www.luogu.org/problem/show?pid=2419 题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant ski…
想找原题请点击这里:传送门 原题: 题目背景 [Usaco2008 Jan] 题目描述 N ( ≤ N ≤ ) cows, conveniently numbered ..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among…
题目描述 FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:).在赛场上,奶牛们按1..N依次编号.每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名. 整个比赛被分成了若干轮,每一轮是两头指定编号的奶牛的对决.如果编号为A的奶牛的编程能力强于编号为B的奶牛(1 <= A <= N; 1 <= B <= N; A != B) ,那么她们的对决中,编号为A的奶牛总是能胜出. FJ想知道奶牛们编程能力的…
题目描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each…