http://poj.org/problem?id=1275

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 2000
using namespace std;
const int inf=<<;
int r[],t[maxn],s[maxn],dis[maxn];
int n,e;
int sum;
struct node
{
int u,v,w;
}p[maxn];
void add(int u,int v,int w)
{
p[e].u=u;
p[e].v=v;
p[e++].w=w;
}
bool bellman_ford()
{
for(int i=; i<=; i++) dis[i]=inf;
dis[]=;
bool flag;
for(int i=; i<=; i++)
{
flag=false;
for(int j=; j<e; j++)
{
if(dis[p[j].v]>dis[p[j].u]+p[j].w)
{
dis[p[j].v]=dis[p[j].u]+p[j].w;
flag=true;
}
}
if(!flag) break;
}
if(flag) return false;
else return true;
}
void buil(int x)
{
e=;
int j;
for(j=; j<=; j++)
{
int i=(j+)%;
if(i>j)
{
add(i,j,-r[i]);
}
else if(i<j)
{
add(i,j,x-r[i]);
}
}
add(,,-x);
} void bear(int r,int l)
{
int low=r,high=l;
while(low<=high)
{
//printf("%d\n",sum);
int mid=(low+high)/;
buil(mid);
if(bellman_ford())
{
sum=mid;
high=mid-;
}
else
low=mid+;
}
} int main()
{
int m,x;
scanf("%d",&m);
while(m--)
{
for(int i=; i<=; i++)
{
scanf("%d",&r[i]);
}
scanf("%d",&n);
memset(t,,sizeof(t));
for(int i=; i<n; i++)
{
scanf("%d",&x);
t[x+]++;
}
e=;
for(int i=; i<=; i++)
{
add(i-,i,t[i]);
add(i,i-,);
}
sum=-;
bear(,n);
if(sum==-)
printf("No Solution\n");
else
printf("%d\n",sum);
}
return ;
}

poj 1275 Cashier Employment的更多相关文章

  1. 图论(差分约束系统):POJ 1275 Cashier Employment

    Cashier Employment Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7651   Accepted: 288 ...

  2. POJ 1275 Cashier Employment(差分约束)

    http://poj.org/problem?id=1275 题意 : 一家24小时营业的超市,要雇出纳员,需要求出超市每天不同时段需要的出纳员数,午夜只需一小批,下午需要多些,希望雇最少的人,给出每 ...

  3. poj 1275 Cashier Employment - 差分约束 - 二分答案

    A supermarket in Tehran is open 24 hours a day every day and needs a number of cashiers to fit its n ...

  4. POJ 1275 Cashier Employment 挺难的差分约束题

    http://poj.org/problem?id=1275 题目大意: 一商店二十四小时营业,但每个时间段需求的雇员数不同(已知,设为R[i]),现有n个人申请这份工作,其可以从固定时间t连续工作八 ...

  5. POJ - Problem 1275 - Cashier Employment

    · 对于差分约束,题目要求求什么便设什么,令$Sum[i]$表示由$0 ~ i$的雇佣人数. · 要充分利用题目所给条件,令$Have[i]$表示i时刻申报的人数,$Need[i]$表示i时刻需要的人 ...

  6. HDU [1529] || POJ [P1275] Cashier Employment

    经典的差分约束+二分答案. 本题的难点在于如何建图. 设x[i] 表示第i个小时可以开始工作的有多少个人. num[i] 表示第i个小时最少需雇佣多少人. s[i] 表示1...i小时实际开始工作的有 ...

  7. 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)

    [POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS   Memory Limit: 10 ...

  8. POJ1275 Cashier Employment[差分约束系统 || 单纯形法]

    Cashier Employment Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7997   Accepted: 305 ...

  9. 【POJ1275】Cashier Employment 差分约束

    [POJ1275]Cashier Employment 题意: 超市经历已经提供一天里每一小时需要出纳员的最少数量————R(0),R(1),...,R(23).R(0)表示从午夜到凌晨1:00所需要 ...

随机推荐

  1. 转载:Ununtu下中文乱码解决方案

    转载: 添加中文字符编码: $sudo vim /var/lib/locales/supported.d/local #添加下面的中文字符集 zh_CN.GBK GBK zh_CN.GB2312 GB ...

  2. Lucene 4.x实践1

    在Lucene 3.x时代,<Lucene In Action>是一本相当不错的参考书,书中详细介绍了Lucene各种高级使用技术,对于开发者来说非常实用.但是近期Lucene升级到了4. ...

  3. 统计学习导论:基于R应用——第四章习题

    第四章习题,部分题目未给出答案 1. 这个题比较简单,有高中生推导水平的应该不难. 2~3证明题,略 4. (a) 这个问题问我略困惑,答案怎么直接写出来了,难道不是10%么 (b) 这个答案是(0. ...

  4. html contenteditable

    contenteditable 是html中的一個屬性,在HTML中,某些元素設置 contenteditable='true'  屬性時可以開啟該元素的編輯模式,contenteditable 可以 ...

  5. java多态 -- 猫狗案列

    我们用猫狗案例来表明在java中使用多态的好处: class Animal{ public Animal(){} public void eat(){ System.out.println(" ...

  6. 转:SVN使用教程总结

    转自:http://www.cnblogs.com/tugenhua0707/p/3969558.html SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版 ...

  7. Day2 - Python基础2 列表、字典、集合

    Python之路,Day2 - Python基础2   本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一, ...

  8. JY02-HTML/CSS-京东01 定位是很粗暴的页面布局方法

    1.学习重点 1. 独立完成开发前的准备工作 1.1 配置开发环境 已使用sublime,webstorm,,,vscode,ato,Hbuilder 1.2 建立项目文件 项目文件名/ css.js ...

  9. 登录模块需要用到session留底

    <% HttpSession sessions=request.getSession(); Object sessionValues=sessions.getAttribute("ui ...

  10. java 跳转地址栏地址改变

    在strtus1 中,很多都是直接的action 配置后进行跳转的 这样地址栏是不会改变的 如果需要进行浏览器跳转 ActionForward actionForward = new ActionFo ...