SP1693 COCONUTS - 题解

SP1693 COCONUTS
题意:
几个士兵在投票,有支持与反对两种选择,每个人有自己的看法,但是他们有时也会为了支持朋友的看法而放弃自己的看法,请求出一种方案,使得违背自己初始看法的人数与看法不一致的朋友对数之和最小,人数不大于300。

做法:
这是一道网络流的题目。是源点s代表支持,汇点t代表反对,最小割即所有人决策的最小代价之和。如果一个人支持,则t向他连边,反之他向s连边。如果有一对朋友,那他们互相连边(所有边权为1)。然后跑最小割即可。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a),i##ed=(b);i<=i##ed;i++)
#define per(i,a,b) for(int i=(a),i##ed=(b);i>=i##ed;i--)
using namespace std;
const int N=1010,M=2000010,INF=0x3f3f3f3f;
int s,t,n,m,sum;
int cnt,hed[N],to[M],nxt[M],val[M];
int cur[M],dis[M],g[M];

inline void add(int x,int y,int z) { to[++cnt]=y,val[cnt]=z,nxt[cnt]=hed[x],hed[x]=cnt; }
inline int Min(int x,int y) { return x<y? x:y; }
int SAP(int u,int flow) {
    if(u==t) return flow; int v=flow;
    for(;cur[u];cur[u]=nxt[cur[u]])
        if(dis[to[cur[u]]]==dis[u]-1&&val[cur[u]]) {
            int f=SAP(to[cur[u]],Min(v,val[cur[u]]));
            val[cur[u]]-=f,val[cur[u]^1]+=f,v-=f;
            if(!v) return flow;
        }
    if(!--g[dis[u]++]) dis[s]=t-s+2;
    ++g[dis[u]],cur[u]=hed[u]; return flow-v;
}
int main() {
    for(;;) {
        scanf("%d%d",&n,&m); if(!n&&!m) break;
        cnt=1,memset(hed,0,sizeof(hed)),s=0,t=n+1,sum=0;
        rep(i,1,n) {
            int x;scanf("%d",&x);
            x? (add(s,i,1),add(i,s,0)):(add(t,i,0),add(i,t,1));
        }
        rep(i,1,m) {
            int x,y;scanf("%d%d",&x,&y);
            add(x,y,1),add(y,x,0),add(y,x,1),add(x,y,0);
        }
        rep(i,s,t) cur[i]=hed[i],g[i]=0,dis[i]=0;
        for(g[0]=t-s+1;dis[s]<=t-s+1;sum+=SAP(s,INF));
        printf("%d\n",sum);
    }
    return 0;
}

转载于:https://www.cnblogs.com/daniel14311531/p/10458249.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解决这个问题King Julien rules the Madagascar island whose primary crop is coconuts. If the price of coconuts is P , then King Julien’s subjects will demand D(P ) = 1200 − 100P coconuts per week for their own use. The number of coconuts that will be supplied per week by the island’s coconut growers is S(p) = 100P. (a) (2 pts) Calculate the equilibrium price and quantity for coconuts. (b) (2 pts) One day, King Julien decided to tax his subjects in order to collect coconuts for the Royal Larder. The king required that every subject who consumed a coconut would have to pay a coconut to the king as a tax. Thus, if a subject wanted 5 coconuts for himself, he would have to purchase 10 coconuts and give 5 to the king. When the price that is received by the sellers is pS, how much does it cost one of the king’s subjects to get an extra coconut for himself? (c) (3 pts) When the price paid to suppliers is pS, how many coconuts will the king’s subjects demand for their own consumption (as a function of pS)? 2 (d) (2 pts) Under the above coconut tax policy, determine the total number of coconuts demanded per week by King Julien and his subjects as a function of pS. (e) (3 pts) Calculate the equilibrium value of pS, the equilibrium total number of coconuts produced, and the equilibrium total number of coconuts consumed by Julien’s subjects. (f) (5 pts) King Julien’s subjects resented paying the extra coconuts to the king, and whispers of revolution spread through the palace. Worried by the hostile atmosphere, the king changed the coconut tax. Now, the shopkeepers who sold the coconuts would be responsible for paying the tax. For every coconut sold to a consumer, the shopkeeper would have to pay one coconut to the king. For this new policy, calculate the number of coconuts being sold to the consumers, the value per coconuts that the shopkeepers got after paying their tax to the king, and the price payed by the consumers.
03-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值