Guessing Game 题目连接: http://codeforces.com/gym/100015/attachments Description Jaehyun has two lists of integers, namely a1,...,aN and b1,...,bM.Je!rey wants to know what these numbers are, but Jaehyun won't tell him the numbers directly. So, Je!rey as…
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> using namespace std; <<;…
题面 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…
[POJ1275]Cashier Employment 题意: 超市经历已经提供一天里每一小时需要出纳员的最少数量————R(0),R(1),...,R(23).R(0)表示从午夜到凌晨1:00所需要出纳员的最少数目:R(1)表示凌晨1:00到2:00之间需要的:等等.每一天,这些数据都是相同的. 有N人申请这项工作,每个申请者i在每天24小时当中,从一个特定的时刻开始连续工作恰好8小时.定义ti(0<=ti<=23)为上面提到的开始时刻,也就是说,如果第i个申请者被录用,他(或她)将从ti时…
题意:n头牛,按照编号从左到右排列,两头牛可能在一起,接着有一些关系表示第a头牛与第b头牛相隔最多与最少的距离,最后求出第一头牛与最后一头牛的最大距离是多少,如         果最大距离无限大则输出-2,如果关系不能保证则输出-1 题解:差分约束的入门题 差分约束就是如果dis[b]-dis[a]<=c转化为a到b建一条有向边权值为c,接着求最短路就得出了两点的最大距离(最短距离都保证了,那么长一些的也可以成立),注意没有         最短路就是可能性无限,有一个负权回路就是关系不能保证,…
题意:给你以i为结尾的最长上升子序列的值,和每个值的区间范围求可行的a[i] 题解:差分约束,首先满足l[i]<=a[i]<=r[i],可以建一个虚拟节点n+1,那么有a[n+1]-a[i]<=-l[i],a[i]-a[n+1]<=r[i],同时对于之前出现过f[i](假设为j)的情况,此时a[i]>=a[j](保证没法转移),a[j]-a[i]<=0,还有对于从上一个f[i]-1转移过来的点j,有a[i]>a[j],即a[j]-a[i]<=-1 //#pr…
---题面--- 题解: 差分约束学得实在是太烂了,,,,QAQ 这里先记下: a - b >= x  ---> a >= b + x     ---->        b ---> a = x(b连a,边权为x),      ----> 找最长路, --->f[a][b]对应a - b的最小值, a - b <=x ---->后面的都反过来就好了 关于这道题: 首先我们可以发现它实际上就是告诉了我们一堆这样的关系: a > b, a <…
Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 39666   Accepted: 11168 题目链接:http://poj.org/problem?id=3159 Description: During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought…
裸的差分约束 dfs判断负环,如果有负环就false,否则就是true 注意有多组数据,数组要清空 #include <cstdio> #include <algorithm> #include <queue> #include <cstring> #include <iostream> using namespace std; ; ; ,u[MAXM],v[MAXM],w[MAXM],first[MAXN],next[MAXM]; int vi…
看到题就可以想到差分约束 判断负环要用dfs,bfs-spfa会TLE 4个点 bfs-spfa #include <cstdio> #include <algorithm> #include <queue> #include <cstring> #include <iostream> using namespace std; ; ; ,u[MAXM],v[MAXM],w[MAXM],first[MAXN],next[MAXM]; bool vi…