bzoj4397[Usaco2015 dec]Breed Counting*】的更多相关文章

bzoj4397[Usaco2015 dec]Breed Counting 题意: 给定一个长度为N的序列,每个位置上的数只可能是1,2,3中的一种.有Q次询问,每次给定两个数a,b,请分别输出区间[a,b]里数字1,2,3的个数.n≤100000,q≤100000. 题解: 裸前缀和. 代码: #include <cstdio> #include <cstring> #include <algorithm> #define inc(i,j,k) for(int i=j…
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Description Farmer John's N cows, conveniently numbered 1…N, are all standing in a row (they seem to do so often that it now takes very little prompting from Farmer John to…
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4397 用线段树维护区间和即可.时间复杂度\(O((N+Q)logN)\). #include<iostream> #include<cstring> #include<cstdio> #define maxn 100010 using namespace std; inline int read(){ register int x(0),f(1); regist…
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 29  Solved: 25 [Submit][Status][Discuss] Description Farmer John's N cows, conveniently numbered 1-N, are all standing in a row (they seem to do so often that it now…
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submit][Status][Discuss] Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), c…
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<set> using na…
[Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 353  Solved: 236[Submit][Status][Discuss] Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveni…
题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫就可以了TAT #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s…
BZOJ4390: [Usaco2015 dec]Max Flow Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveniently numbered 1…N. Each pipe connects a pair of stalls, and all stalls are conn…
bzoj4396[Usaco2015 dec]High Card Wins 题意: 一共有2n张牌,Alice有n张,Bob有n张,每一局点数大的赢.知道Bob的出牌顺序,求Alice最多能赢几局.n≤50000. 题解: 贪心.将Alice和Bob的牌按点数大小排序,然后如果Alice当前牌能赢Bob当前牌就ans++否则就不断调整Bob的当前牌直到Alice当前牌能赢Bob当前牌. 代码: #include <cstdio> #include <cstring> #includ…
bzoj4395[Usaco2015 dec]Switching on the Lights 题意: n*n个房间,奶牛初始在(1,1),且只能在亮的房间里活动.每当奶牛经过一个房间,就可以打开这个房间里控制其它房间灯的开关.问奶牛最多可点亮多少个房间.n≤100. 题解: 因为只要一个房间灯亮了,它将一直亮着,所以可以做bfs,每次由队列中的节点扩展可以到的节点.然而这样做不行,因为可能之前尝试过不能到达的房间的灯可以在之后到达的房间里被打开.解决方法是不停做bfs,直到答案不再更新. 代码:…
题目描述 Farmer John's N cows, conveniently numbered 1…N, are all standing in a row (they seem to do so often that it now takes very little prompting from Farmer John to line them up). Each cow has a breed ID: 1 for Holsteins, 2 for Guernseys, and 3 for…
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4392 [算法] 线段树 时间复杂度 : O(MlogN) [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 200010 typedef long long LL; int n , m; LL a[MAXN]; struct SegmentTree { struct Node { int l , r; L…
题目大意:给出一棵树,n(n<=5w)个节点,k(k<=10w)次修改,每次给定s和t,把s到t的路径上的点权+1,问k次操作后最大点权. 对于每次修改,给s和t的点权+1,给lca(s,t)和lca(s,t)的父亲的点权-1,每一个点的权就是它与它的子树权和,实际上就是树上的差分,又涨姿势了... 代码如下: uses math; type point=^rec; rec=record data:longint; next:point; end; var n,m,x,y,i,ans,fa,k…
每次到达一个点,或者点亮一个房间的灯的时候,检查一下它四周的点能否走. 一开始看错题了..要求的是最多能开多少房的灯. #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; ; ]={,,,-},yy[]={,-,,}; ];int tot,last[maxn]; int dlx[…
正解:贪心+线段树/set库 解题报告: 算辣直接甩链接qwq 恩这题就贪心?从前往后从后往前各推一次然后找一遍哪个地方最大就欧克了,正确性很容易证明 (这里有个,很妙的想法,就是,从后往前推从前往后推可能会有相同的牌嘛,但是其实这个是没有个关系的! 因为,既然有相同的牌那么就必定有多了的牌,然后如果这个多了的牌比重了的牌大我们就放前面,比重了的小我们就放后面,这样就不会影响答案的正确性了…… 哇我觉得这个想法真是太神仙了像我这种菜鸡自己单独想的话是绝对想不到这个的我可能就直接放弃贪心了TT 但…
Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a complete…
Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a complete…
---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化,则有一个比较容易发现的贪心: 设f[i]为从1开始到i位, 比较方式为点数大的获胜,最多能赢几局. 那么为了使答案尽可能优,每次我们都会在剩余牌中找到点数大于对方的 最小的牌,然后出掉. 同理,设g[i]为从n开始到i位,比较方式为点数小的获胜,最多能赢几局, 则每次都在剩余牌中选择点数小于对方的…
传送门 分析 神奇的贪心,令f[i]表示前i个每次都出比对方稍微大一点的牌最多能赢几次 g[i]表示从i-n中每次出比对方稍微小一点的牌最多赢几次 ans=max(f[i]+g[i+1]) 0<=i<=n 虽然方案可能会重合但是这是可行的 1:因为限制比原题目宽,所以ans>=真实的答案 2:对于重复取的数a,如果集合中有个没取的数<a,那么在用小的赢的时候可以代替a 如果>a,那么在用大的赢时可以代替a 用set来记录最接近的数 代码 #include<bits/st…
Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 275  Solved: 175[Submit][Status][Discuss] Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in…
DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf("%d%d%d",&T,&A,&B); F[0]=1; for (int i=0; i<=T; i++) F[i+A]|=F[i],F[i+B]|=F[i]; for (int i=0; i<=T; i++) G[i/2]|=F[i]; for (int i…
题目描述 Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveniently numbered 1…N. Each pipe connects a pair of stalls, and all stalls are connected to each-other via paths of pipes.FJ…
巧妙的贪心 Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a co…
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4397 [算法] 树状数组 时间复杂度 : O(QlogN) [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100010 int n , q; struct Binary_Indexed_Tree { int c[MAXN]; inline int lowbit(int x) { return x &a…
Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 129[Submit][Status][Discuss] Description Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveniently numbered 1…N. Each…
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem 10983 18765 Y 1036 [ZJOI2008]树的统计Count 5293 13132 Y 1588 [HNOI2002]营业额统计 5056 13607 1001 [BeiJing2006]狼抓兔子 4526 18386 Y 2002 [Hnoi2010]Bounce 弹飞绵羊 43…
本篇博客按照题号排序(带*为推荐题目) 1008 [HNOI2008]越狱 很经典的题了..龟速乘,龟速幂裸题,, 1010 [HNOI2008]玩具装箱toy* 斜率优化 基本算是裸题. 1012 最大数 单调队列/单调栈 随便搞一搞就好 (水题...) 1045 糖果传递(双倍经验请做 3293 分金币) 贪心+中位数  排序后搞一搞可过..(水题...) 1051 受欢迎的牛* tarjan (提高T1+ -- T2难度) 1106: [POI2007]立方体大作战tet* 树状数组+贪心…
初次接触python,写的很简单,开发工具PyCharm,python 3.4很方便 python 部分模块安装时需要其他的附属模块之类的,可以先 pip install wheel 然后可以直接下载whl文件进行安装 pip install lxml-3.5.0-cp34-none-win32.whl 定义一个类,准备保存的类型 class CnblogArticle: def __init__(self): self.num='' self.category='' self.title=''…
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ------------------------------------------------------------------------------------------------------- bzoj1597: [Usaco2008 Mar]土地购买  斜率优化DP h升序,w降序. f[i]=min(f[j]+h[i]*w[j+1])…