[Usaco2005 dec]Layout】的更多相关文章

[BZOJ1731][Usaco2005 dec]Layout 排队布局 Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a straight line waiting for feed. The cows are standin…
1731: [Usaco2005 dec]Layout 排队布局 题意: n头奶牛在数轴上,不同奶牛可以在同个位置处,编号小的奶牛必须在前面.m条关系,一种是两头奶牛距离必须超过d,一种是两头奶牛距离不能超过d.要求:如果不存在情况满足要求则输出-1,奶牛1到n的距离可以为无限大输出-2,否则输出1到n的最大距离. 题解: 差分约束系统.注意:如果是求最大值,则定义限制条件设定为≤并跑最短路,因为得到的是满足条件的最大值,如果是求最小值,则定义限制条件设定为≥并跑最长路,因为得到的是满足条件的最…
[问题描述] Czy喜欢将他的妹子们排成一队.假设他拥有N只妹纸,编号为1至N.Czy让他们站成一行,等待自己来派送营养餐.这些妹纸按照编号大小排列,并且由于它们都很想早点吃饭,于是就很可能出现多只妹纸挤在同一位置的情况(也就是说,如果我们认为妹纸位于数轴上,那么多只妹纸的位置坐标可能相同). 因为众所周知的原因,某些妹纸之间互相喜欢,他们希望互相之间的距离至多为一个定值.但某些妹纸之间互相厌恶,他们希望互相之间的距离至少为一个定值.现在给定ML个互相喜爱的妹纸对以及他们之间距离的最大值,MD个…
填坑- 差分约束一般是搞一个不等式组,求xn-x1的最大最小值什么的,求最大值就转化成xa<=xb+w这样的,然后建图跑最短路(这才是最终约束的),举个例子 x1<=x0+2x2<=x0+7x3<=x0+8x2<=x1+3x3<=x2+2 那么解出来 x3<=x0+7x3<=x0+8x3<=x0+9 结果肯定是 x3<=x0+7 所以直接对于已知条件建边,大于小于可以互相转换,注意:相邻的要保证顺序. #include<cstdio>…
差分约束系统...因为题目要求的是1和n的最大距离所以这题就跑最长路.. 对于互相反感的牛(i与j互相反感,彼此距离至少为len,i<j),就有dis[j]-dis[i]>=len.就加一条i->j,长度为len的边. 有好感的牛(i与j有好感,彼此距离至多len,i<j),就有dis[j]-dis[i]<=len;但因为我们跑的是最长路,所以得改成dis[i]-dis[j]>=-len的形式,就加一条j->i,长度-len的边. 又因为牛是按编号站成一列..所以…
Description 当排队等候喂食时,奶牛喜欢和它们的朋友站得靠近些.FJ有N(2<=N<=1000)头奶牛,编号从1到N,沿一条直线站着等候喂食.奶牛排在队伍中的顺序和它们的编号是相同的.因为奶牛相当苗条,所以可能有两头或者更多奶牛站在同一位置上.即使说,如果我们想象奶牛是站在一条数轴上的话,允许有两头或更多奶牛拥有相同的横坐标.一些奶牛相互间存有好感,它们希望两者之间的距离不超过一个给定的数L.另一方面,一些奶牛相互间非常反感,它们希望两者间的距离不小于一个给定的数D.给出ML条关于两…
[题意]给定按编号顺序站成一排的牛,给定一些约束条件如两牛距离不小于或不大于某个值,求1和n的最大距离.无解输出-1,无穷解输出-2. [算法]差分约束+最短路 [题解]图中有三个约束条件,依次分析: ①坐标顺序和编号顺序一致[一定一定要记得这个约束条件] xi-xi-1>=0 i向-1连边0 ②两牛距离不大于距离L xj-xi<=L i向j连边L ③两牛距离不小于距离D xj-xi>=D即xi-xj<=-D j向i连边-D 连边完毕,通过跑最短路得到起点和终点的直接约束xT-xS…
Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a straight line waiting for feed. The cows are standing in the same order as they are numbe…
题目描述 当排队等候喂食时,奶牛喜欢和它们的朋友站得靠近些.FJ有N(2<=N<=1000)头奶牛,编号从1到N,沿一条直线站着等候喂食.奶牛排在队伍中的顺序和它们的编号是相同的.因为奶牛相当苗条,所以可能有两头或者更多奶牛站在同一位置上.即使说,如果我们想象奶牛是站在一条数轴上的话,允许有两头或更多奶牛拥有相同的横坐标. 一些奶牛相互间存有好感,它们希望两者之间的距离不超过一个给定的数L.另一方面,一些奶牛相互间非常反感,它们希望两者间的距离不小于一个给定的数D.给出ML条关于两头奶牛间有好…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1731 对差分约束理解更深.还发现美妙博客:http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html 原来不是一定要有一个源点向每个点连0边.而且“不可到达”原来是那个意思. UPD(过了一会儿): vis[ ]被自己蒟掉了……但好在spfa也可以看松弛次数!一直以为只能看入队次数. #include<iostream…
差分约束裸题,用了比较蠢的方法,先dfs_spfa判负环,再bfs_spfa跑最短路 注意到"奶牛排在队伍中的顺序和它们的编号是相同的",所以\( d_i-d_{i-1}>=0 \),连(i,i-1,0):然后对于\( d_i-d_j<=L \),连(j,i,L):对于\( d_i-d_j>=D --> d_j-d_i<=-D \),连(i,j,-D) 然后先判负环再跑最短路即可 #include<iostream> #include<c…
[BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire…
[Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为了能安全地离开,贝茜不得不按照骑士们的要求,在森林寻找一种特殊的灌木并带一棵给他们.当然,贝茜想早点离开这可怕的森林,于是她必须尽快完成骑士们给的任务,贝茜随身带着这片森林的地图,地图上的森林被放入了直角坐标系,并按x,y轴上的单位长度划分成了W×H(1≤W,H≤1000)块,贝茜在地图上查出了她自…
1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 414  Solved: 191[Submit][Status] Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to…
1671: [Usaco2005 Dec]Knights of Ni Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 175  Solved: 107[Submit][Status][Discuss] Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through the forest that is guarded b…
题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most…
1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 254  Solved: 163[Submit][Status][Discuss] Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through the forest that is guarde…
BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树 题意:  约翰的奶牛们从小娇生惯养,她们无法容忍牛棚里的任何脏东西.约翰发现,如果要使这群有洁癖的奶牛满意,他不得不雇佣她们中的一些来清扫牛棚, 约翰的奶牛中有N(1≤N≤10000)头愿意通过清扫牛棚来挣一些零花钱.由于在某个时段中奶牛们会在牛棚里随时随地地乱扔垃圾,自然地,她们要求在这段时间里,无论什么时候至少要有一头奶牛正在打扫.需要打扫的时段从某一天的第M秒开始,到第E秒结束f0…
P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可以从 \(l_{i}\) 到 \(r_{i}\) 花费为 \(s_{i}\) 求覆盖整个区间的最小花费 错误日志: 初始化时应该是 \(dp[L - 1]\) 为 \(0\) 而不是 \(dp[1]\) 为 \(0\) , 因为只需要覆盖 \([L, R]\) Solution 设 \(dp[n]\) 表…
[Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of th…
1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 281  Solved: 180[Submit][Status][Discuss] Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through the forest that is guarde…
[Usaco2005 Dec]Cleaning Shifts 给出n段区间,左右端点分别为\(l_i,r_i\),以及选取这段区间的费用\(c_i\),现在要选出若干个区间,使其完全覆盖区间\([m,e]\),询问费用之和的最小值,\(1≤n≤10000,0≤m≤e≤86399\). 解 法一: 不妨把区间按左端点排序,如果在大区间范围外,可以筛除,虽然题目有保障,于是设\(f_i\)表示以第i个区间结尾,覆盖第i个区间前所有需要覆盖的位置的最少代价,于是有 \[f_i=\min_{j=1,r_…
bzoj1673[Usaco2005 Dec]Scales 天平 题意: n个砝码,每个砝码重量大于前两个砝码质量和,天平承重为c,求天平上最多可放多种的砝码.n≤1000,c≤2^30. 题解: 斐波那契数列到30多项就爆int了,所以本题n其实≤30.故爆搜即可,加个剪枝:当前选的砝码质量和+剩下砝码质量和仍≤ans就返回. 代码: #include <cstdio> #include <cstring> #include <algorithm> #define i…
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn. Farmer John…
题目:http://poj.org/problem?id=3169 题意:给你一组不等式了,求满足的最小解 分析: 裸裸的差分约束. 总结一下差分约束: 1.“求最大值”:写成"<=",求最短路 2.“求最小值”:写成">=",求最长路…
Description 约翰的N(1≤N≤100000)只奶牛中出现了K(1≤K≤25000)只爱惹麻烦的坏蛋.奶牛们按一定的顺序排队的时候,这些坏蛋总会站在一起.为了找出这些坏蛋,约翰让他的奶牛排好队进入牛棚,同时需要你的慧眼来识别坏蛋,为了区分,约翰给所有奶牛都发了号牌,上面写着一个1..S(1≤S≤25)之间的数字.虽然这不是一个完美的方法,但也能起一点作用.现在,约翰已经不记得坏蛋们的具体号码.但是凭他的记忆,他给出一个"模式串".原坏蛋的号码如果相同,模式串中他们的号码依然相…
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through the forest that is guarded by the Knights of Ni. In order to pass through safely, the Knights have demanded that she bring them a single shrubbery. Tim…
Description Farmer John has a balance for weighing the cows. He also has a set of N (1 <= N <= 1000) weights with known masses (all of which fit in 31 bits) for use on one side of the balance. He places a cow on one side of the balance and then adds…
题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1671 题解: 按题意分别从贝茜和骑士bfs然后meet_in_middle.. 把一个逗号打成分号调了20分钟... 代码: #include<bits/stdc++.h> using namespace std; ]={,-,,,},my[]={,,,-,}; ; int n,m,g[maxn][maxn],vis[maxn][maxn],f[maxn][maxn],sum,cnt,…
题目传送门 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn.…