bzoj4395[Usaco2015 dec]Switching on the Lights 题意: n*n个房间,奶牛初始在(1,1),且只能在亮的房间里活动.每当奶牛经过一个房间,就可以打开这个房间里控制其它房间灯的开关.问奶牛最多可点亮多少个房间.n≤100. 题解: 因为只要一个房间灯亮了,它将一直亮着,所以可以做bfs,每次由队列中的节点扩展可以到的节点.然而这样做不行,因为可能之前尝试过不能到达的房间的灯可以在之后到达的房间里被打开.解决方法是不停做bfs,直到答案不再更新. 代码:…
每次到达一个点,或者点亮一个房间的灯的时候,检查一下它四周的点能否走. 一开始看错题了..要求的是最多能开多少房的灯. #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; ; ]={,,,-},yy[]={,-,,}; ];int tot,last[maxn]; int dlx[…
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…
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…
[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…
P2845 [USACO15DEC]Switching on the Lights 开关灯 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把多少个牛棚的灯打开. 题目描述 有NN个房间,组成了一张NN的网格图,Bessie一开始位于左上角(1,1),并且只能上下左右行走. 一开始,只有(1,1)这个房间的灯是亮着的,Bessie只能在亮着灯的房间里活动.…
P2828 Switching on the Lights(开关灯) 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把多少个牛棚的灯打开. 题目描述 有N*N个房间,组成了一张N*N的网格图,Bessie一开始位于左上角(1,1),并且只能上下左右行走. 一开始,只有(1,1)这个房间的灯是亮着的,Bessie只能在亮着灯的房间里活动. 有另外M条信息,每…
题意: 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…
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…
P2845 [USACO15DEC]Switching on the Lights 开关灯 题意 题目背景 来源:usaco-2015-dec \(Farm\ John\)最近新建了一批巨大的牛棚.这些牛棚构成了一个\(N\times N\)的矩形网络.\((1<n<100)\) 然而\(Bessie\)十分怕黑,他想计算可以把多少个牛棚的灯打开. 题目描述 有\(N\times N\)个房间,组成了一张\(N\times N\)的网格图,\(Bessie\)一开始位于左上角\((1,1)\)…
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…
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…
题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把多少个牛棚的灯打开. 题目描述 有N*N个房间,组成了一张N*N的网格图,Bessie一开始位于左上角(1,1),并且只能上下左右行走. 一开始,只有(1,1)这个房间的灯是亮着的,Bessie只能在亮着灯的房间里活动. 有另外M条信息,每条信息包含四个数a,b,c,d,表示房间(a,b)里有房间(c,d)的…
题目大意:给出一棵树,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…
题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把多少个牛棚的灯打开. 题目描述 有N*N个房间,组成了一张N*N的网格图,Bessie一开始位于左上角(1,1),并且只能上下左右行走. 一开始,只有(1,1)这个房间的灯是亮着的,Bessie只能在亮着灯的房间里活动. 有另外M条信息,每条信息包含四个数a,b,c,d,表示房间(a,b)里有房间(c,d)的…
正解:贪心+线段树/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…
传送门 题目大意:n*n的网格,每个网格是一个房间 都关着灯,只有(1,1)开着灯,且(x,y)有着(z,k)房间灯的开关. 问从(1,1)开始走最多点开几盏灯. 题解:搜索+骗分. 劳资的骗分天下无敌,劳资的骗分世界第一 代码: #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<vector> #define N 102 using na…
---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化,则有一个比较容易发现的贪心: 设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=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…
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…
题目描述 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…