【POJ 3169 Layout】】的更多相关文章

Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 12565Accepted: 6043 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 li…
3169 -- Layout 继续差分约束. 这题要判起点终点是否连通,并且要判负环,所以要用到spfa. 对于ML的边,要求两者之间距离要小于给定值,于是构建(a)->(b)=c的边.同理,对于MD的,构建(b)->(a)=-c的边.然后就是(i+1)->(i)=0,两者距离大于0的限制. 代码如下: #include <cstdio> #include <iostream> #include <algorithm> #include <cst…
<题目链接> 题目大意: 一些母牛按序号排成一条直线.有两种要求,A和B距离不得超过X,还有一种是C和D距离不得少于Y,问可能的最大距离.如果没有最大距离输出-1,如果1.n之间距离任意就输出-2,否则输出最大的距离. 解题分析:典型的差分约束,第一种约束,v-u<=c:第二种约束:v-u>=c  可以转化为 u-v<=c ,还有一种约束,因为题目要求按序号排序,所以 loc[i] - loc[i-1]>=0 ,即 loc[i-1]-loc[i]<=0 .以上就是…
题目链接:http://poj.org/problem? id=3169 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…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11612   Accepted: 5550 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…
题目链接:http://poj.org/problem?id=3169 差分约束的解释:http://www.cnblogs.com/void/archive/2011/08/26/2153928.html 我也不是特别理解,要是给你a - b <= k 就建一条b->a权值为k的有向边,要是a - b >= k 就建一条a -> b边权是-k的有向边,要是让你求n到1的最大差,就是让你求1到n的最短距离. 差分约束系统有两种方式可以求解,最短路和最长路.当我们把不等式整理成d[a…
题目链接:http://poj.org/problem?id=3169 题目大意:n头牛,按编号1~n从左往右排列,可以多头牛站在同一个点,给出ml行条件,每行三个数a b c表示dis[b]-dis[a]<=c,接下来有md行条件,每行三个数a b c,表示dis[b]-dis[a]>=c.求出出第一头牛和第n头牛的最大可能距离.若不可能把所有牛排成一排即条件有矛盾,则输出“-1”,若第一头牛和第n头牛的距离可以无限大,则输出“-2”. 解题思路:第二道差分约束的题目.根据题目给出的三个约束…
Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 947Accepted: 345Special Judge Description The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a loc…
Time Limit: 2000MSMeamory Limit: 65536K Total Submissions: 27949Accepted: 10764 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.Write a program that:reads the number of intervals, their end points and integer…
http://poj.org/problem?id=3169 http://acm.hdu.edu.cn/showproblem.php?pid=3592 题目大意: 一些母牛按序号排成一条直线.有两种要求,A和B距离不得超过X,还有一种是C和D距离不得少于Y,问可能的最大距离.如果没有输出-1,如果可以随便排输出-2,否则输出最大的距离. 思路: 对于第一种 B - A <=X 第二种有 D - C >=Y也就是  C-D<=-Y 还有就是题目要求的是按照序号升序排. 然后又不等式3…
题目链接:http://poj.org/problem?id=3169 题意:n头牛编号为1到n,按照编号的顺序排成一列,每两头牛的之间的距离 >= 0.这些牛的距离存在着一些约束关系:1.有ml组(u, v, w)的约束关系,表示牛[u]和牛[v]之间的距离必须 <= w.2.有md组(u, v, w)的约束关系,表示牛[u]和牛[v]之间的距离必须 >= w.问如果这n头无法排成队伍,则输出-1,如果牛[1]和牛[n]的距离可以无限远,则输出-2,否则则输出牛[1]和牛[n]之间的最…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6415   Accepted: 3098 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…
Layout 题目链接: Rhttp://acm.hust.edu.cn/vjudge/contest/122685#problem/S 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 waitin…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8610   Accepted: 4147 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…
题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意只扩散一圈,不是连锁反应. 求最少翻转几个位置能够使所有n*m个位置都变为白色.若有解,求字典序最小的翻转方案(给出每个位置的翻转次数). 数据范围:n, m 属于 [1, 15] 思路:我们把翻转方案中的翻转称为“主动翻转”,翻转过程中受邻居影响而发生的翻转称为“被动翻转”.观察例子可得出如下几个…
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头牛用). 求这L瓶防晒液最多能让多少头牛安全地晒太阳. 思路:贪心策略,按spf从小到大或从大到小的顺序取出防晒液,供给尽可能多的剩余的牛. 具体如何判断当前这瓶防晒液最多能供给几头牛呢? 以spf从小到大排序所有防晒液为例,可以维护一个小顶堆,每取出一瓶防晒液l,就把剩余的所有min值低于l.sp…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6574   Accepted: 3177 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…
描述 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 numbered, and…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15349   Accepted: 7379 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…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6549   Accepted: 3168 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…
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 numbered, and sin…
题目传送门 题意:有两种关系,n牛按照序号排列,A1到B1的距离不超过C1, A2到B2的距离不小于C2,问1到n的距离最大是多少.如果无限的话是-2, 如果无解是-1 分析:第一种可以写这样的方程:d[v] - d[u] <= w1, u到v连一条权值为w1的边,第二种这样:d[v] - d[u] >= w2 => d[u] - d[v] <= -w2,v到u连一条-w2的边.当然根据题目还有i+1 到 i连权值0的边.最短路就是为了d[v] <= d[u] + w[u][…
题意:给定一些母牛,要求一个排列,有的母牛距离不能超过w,有的距离不能小于w,问你第一个和第n个最远距离是多少. 析:以前只是听说过个算法,从来没用过,差分约束. 对于第 i 个母牛和第 i+1 个,D[i] - D[i+1] <= 0,  D[j] -D[i ]<= k, D[i] - D[j] <= - k,那么这个题就可以用差分约束来求这个不等式组了. 1.对于差分不等式,a - b <= c ,建一条 b 到 a 的权值为 c 的边,求的是最短路,得到的是最大值(本题求的就…
介绍下差分约束系统:就是多个2未知数不等式形如(a-b<=k)的形式 问你有没有解,或者求两个未知数的最大差或者最小差 转化为最短路(或最长路) 1:求最小差的时候,不等式转化为b-a>=k的标准形式建图,求最长路 2:求最大差的时候,不等式转化为b-a<=k的标准形式建图,求最短路 然后具体的写的好的博客以供大家参考 1 http://www.cnblogs.com/void/archive/2011/08/26/2153928.html 2 http://blog.csdn.net/…
此题按照<挑战程序设计竞赛(第2版)>P89的解法,不容易想到,但想清楚了代码还是比较直观的. 并查集模板(包含了记录高度的rank数组和查询时状态压缩) *; int par[MAX_N]; int rank[MAX_N]; //初始化,根为自身,高度为0 void init(int scab) { ;i<=scab;i++) { par[i]=i; rank[i]=; } } //查找,途径的所有结点都直接连到根上 int find(int x) { if(par[x]==x) re…
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…
题意:有一串数字1~n,按顺序排序,给两种要求,一是给定u,v保证pos[v] - pos[u] <= w:二是给定u,v保证pos[v] - pos[u] >= w.求pos[n] - pos[1]最大,若无解输出-1,无穷多解输出-2. 思路:光看题目好像和最短路无关,其实这里用到了spfa的松弛操作来保证所给出的两种要求.若pos[v] - pos[u] >= w,则pos[v] +(- w) >=  pos[u],也就是pos[v] +(- w) < pos[u]时进…
题意: 有N头牛, 有以下关系: (1)A牛与B牛相距不能大于k (2)A牛与B牛相距不能小于k (3)第i+1头牛必须在第i头牛前面 给出若干对关系(1),(2) 求出第N头牛与第一头牛的最长可能距离, 若无解输出-1, 若无限长输出-2 分析: 3个关系对应的 <= 式子是: dis[b] - dis[a] <= d(1) dis[a] - dis[b] <= -d(2) dis[i] - dis[i+1] <= -1(2) 目标式:dis[N] - dis[1] <=…
[#Auto Layout#]Xcode6创建Auto Layout 约束时产生的一些变化     通过两个小Demo来展示下变化: Demo1需求: 为控制器的根视图(图中的“控制器View”)的子视图(图中的View)添加顶部约束10     运行效果: 没有从顶部开始,似乎是从statusbar的20高度以外开始计算的     出错原因 添加到控制器根视图的顶部约束,默认添加到的是Buttom Layout Guide,也就是从status bar 的20高度开始, 同理设置底部约束时,也…
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以她总是收到许多情书.虽然她十分有魅力,然而她却是个低调的人.因此她从来不会告诉别人她到底收到了多少情书. ftiasch的好朋友1tthinking想知道她到底收到了多少情书.1tthinking知道,ftiasch每次收到一封情书,就会在日记最后写下一个包含"luvletter"子序列的…