1934: [Shoi2007]Vote 善意的投票
来源:互联网 发布:福利彩票不能网络购买 编辑:程序博客网 时间:2024/05/19 21:01
1934: [Shoi2007]Vote 善意的投票
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1920 Solved: 1189
[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
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<bitset>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 333;const int maxm = 2*maxn*maxn;const int INF = ~0U>>1;struct E{int to,cap,flow; E(){}E(int to,int cap,int flow): to(to),cap(cap),flow(flow){}}edgs[maxm];int n,m,cnt,tot,s,t,cur[maxn],L[maxn];bool vis[maxn];vector <int> v[maxn];queue <int> Q;void Add(int x,int y,int cap){v[x].push_back(cnt); edgs[cnt++] = E(y,cap,0);v[y].push_back(cnt); edgs[cnt++] = E(x,0,0);}bool BFS(){for (int i = 1; i <= t; i++) L[i] = 0,vis[i] = 0;Q.push(s); vis[s] = 1; L[s] = 1;while (!Q.empty()){int k = Q.front(); Q.pop();for (int i = 0; i < v[k].size(); i++){E e = edgs[v[k][i]];if (e.cap == e.flow) continue;if (vis[e.to]) continue;vis[e.to] = 1; L[e.to] = L[k] + 1; Q.push(e.to);}}return vis[t] == 1;}int Dinic(int x,int a){if (x == t) return a;int flow = 0;for (int &i = cur[x]; i < v[x].size(); i++){E &e = edgs[v[x][i]];if (e.cap == e.flow) continue;if (L[e.to] != L[x] + 1) continue;int f = Dinic(e.to,min(a,e.cap - e.flow));if (!f) continue;e.flow += f;edgs[v[x][i]^1].flow -= f;flow += f;a -= f;if (!a) return flow;}if (!flow) L[x] = 0;return flow;}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n >> m; s = n + 1; t = n + 2;for (int i = 1; i <= n; i++){int x; scanf("%d",&x);if (x == 1) Add(i,t,1);else Add(s,i,1);}while (m--){int x,y; scanf("%d%d",&x,&y);Add(x,y,1); Add(y,x,1);}int MaxFlow = 0;while (BFS()){for (int i = 1; i <= t; i++) cur[i] = 0;MaxFlow += Dinic(s,INF);}cout << MaxFlow;return 0;}
0 0
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- bzoj 1934: [Shoi2007]Vote 善意的投票
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ-1934-Vote善意的投票-SHOI2007
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ 1934 [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票 (网络流)
- BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)
- bzoj 1934: [Shoi2007]Vote 善意的投票(最小割)
- 【bzoj 1934】[Shoi2007]Vote 善意的投票 最小割
- 2768: [JLOI2010]冠军调查/1934: [Shoi2007]Vote 善意的投票
- 【bzoj1934】 [Shoi2007]Vote 善意的投票
- bzoj1934【shoi2007】Vote善意的投票
- [bzoj1934]: [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票
- 数据结构实验之链表五:单链表的拆分
- java面试题
- Uva136 Ugly Numbers 【优先队列】【例题5-7】
- java Scanner类常用方法
- 数据结构实验之链表六:有序链表的建立
- 1934: [Shoi2007]Vote 善意的投票
- KindEditor结合ssm框架使用
- WebBasic
- POJ-3276-尺取法,greedy
- 矩阵的广义逆
- 数据结构实验之链表七:单链表中重复元素的删除
- ie点击任何网页都显示不安全信息
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
- Laravel教程一 搭建Homestead环境