bzoj1934【shoi2007】Vote善意的投票
来源:互联网 发布:纸箱厂专业软件 编辑:程序博客网 时间:2024/05/19 23:24
1934: [Shoi2007]Vote 善意的投票
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1533 Solved: 942
[Submit][Status][Discuss]
Description
幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉。对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神。虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可以投和自己本来意愿相反的票。我们定义一次投票的冲突数为好朋友之间发生冲突的总数加上和所有和自己本来意愿发生冲突的人数。 我们的问题就是,每位小朋友应该怎样投票,才能使冲突数最小?
Input
第一行只有两个整数n,m,保证有2≤n≤300,1≤m≤n(n-1)/2。其中n代表总人数,m代表好朋友的对数。文件第二行有n个整数,第i个整数代表第i个小朋友的意愿,当它为1时表示同意睡觉,当它为0时表示反对睡觉。接下来文件还有m行,每行有两个整数i,j。表示i,j是一对好朋友,我们保证任何两对i,j不会重复。
Output
只需要输出一个整数,即可能的最小冲突数。
Sample Input
3 3
1 0 0
1 2
1 3
3 2
1 0 0
1 2
1 3
3 2
Sample Output
1
HINT
在第一个例子中,所有小朋友都投赞成票就能得到最优解
Source
Day2
很简单的最小割问题
如果一个同学赞成睡觉,就从源点向他连权值为1的边,否则从他向汇点连权值为1的边。对于一对好朋友,互相连权值为1的边。求出的最小割即为答案。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<cmath>#include<queue>#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define ll long long#define pa pair<int,int>#define maxn 310#define maxm 100000#define inf 1000000000using namespace std;struct edge_type{int next,to,v;}e[maxm];int head[maxn],cur[maxn],dis[maxn];int ans=0,cnt=1,s,t,n,m,x,y;inline int read(){int x=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}inline void add_edge(int x,int y,int v1,int v2){e[++cnt]=(edge_type){head[x],y,v1};head[x]=cnt;e[++cnt]=(edge_type){head[y],x,v2};head[y]=cnt;}inline bool bfs(){queue<int>q;memset(dis,-1,sizeof(dis));dis[s]=0;q.push(s);while (!q.empty()){int tmp=q.front();q.pop();if (tmp==t) return true;for(int i=head[tmp];i;i=e[i].next) if (e[i].v&&dis[e[i].to]==-1){dis[e[i].to]=dis[tmp]+1;q.push(e[i].to);}}return false;}inline int dfs(int x,int f){if (x==t) return f;int tmp,sum=0;for(int &i=cur[x];i;i=e[i].next){int y=e[i].to;if (e[i].v&&dis[y]==dis[x]+1){tmp=dfs(y,min(f-sum,e[i].v));e[i].v-=tmp;e[i^1].v+=tmp;sum+=tmp;if (sum==f) return sum;}}return sum;}inline void dinic(){while (bfs()){F(i,1,t) cur[i]=head[i];ans+=dfs(s,inf);}}int main(){n=read();m=read();s=n+1;t=s+1;F(i,1,n){x=read();if (x) add_edge(s,i,1,0);else add_edge(i,t,1,0);}F(i,1,m){x=read();y=read();add_edge(x,y,1,1);}dinic();printf("%d\n",ans);}
0 0
- 【bzoj1934】 [Shoi2007]Vote 善意的投票
- bzoj1934【shoi2007】Vote善意的投票
- [bzoj1934]: [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票
- bzoj1934 [Shoi2007]Vote 善意的投票
- BZOJ1934: [Shoi2007]Vote 善意的投票
- bzoj1934 [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票 最小割
- [BZOJ1934][Shoi2007]Vote 善意的投票(最小割)
- [SHOI2007]BZOJ1934 Vote善意的投票-最小割
- [bzoj1934][SHOI2007] Vote 善意的投票 最小割
- BZOJ1934 [Shoi2007]Vote 善意的投票 【最小割】
- bzoj1934 [Shoi2007]Vote 善意的投票(最小割)
- 【SHOI2007】bzoj1934 善意的投票
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- bzoj 1934: [Shoi2007]Vote 善意的投票
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ-1934-Vote善意的投票-SHOI2007
- SQLServer 维护脚本分享(06)CPU
- TCP/IP四层协议栈
- TCP的交互数据流
- 解决键盘遮挡输入框问题
- 单例模式
- bzoj1934【shoi2007】Vote善意的投票
- 【Android】《第一行代码—Android》第四章总结
- 笔试题目总结之二——常用数据结构与算法
- do{}while(0);详解
- <二>Material主题的使用
- Leetcode-300.Longest Increasing Subsequence
- 笔试题目总结之三——软件工程中的开发模式
- Gfx.WaitForPresent
- utips面试小记