poj 1733_Parity game_并查集
来源:互联网 发布:怎么截图给淘宝客服 编辑:程序博客网 时间:2024/05/01 01:47
题目大意
每次给出一个01序列中一段数1的奇偶性,求不冲突的最大数
思路
就是一个并查集然后用map离散一下,将全部的数存起来就可以了
#include <stdio.h>#include <map>#include <string>#include <iostream>using namespace std;#define max 100000int f[max+1],n,m,a[max+1];map <int,int> p;int find(int x){ if (f[x]==-1) return x; int xx=f[x]; f[x]=find(f[x]); a[x]=(a[x]+a[xx])%2; return f[x];}int insert(int x,int y,int odd){ int xx=find(x),yy=find(y); if (xx!=yy) { f[xx]=yy; a[xx]=(a[x]+a[y]+odd)%2; return true; } else { if ((a[x]+a[y])%2==odd) return true; else return false; }}int main(){ scanf("%d%d",&m,&n); for (int i=0;i<=max;i++) f[i]=-1; int k=1,i; for (i=0;i<n;i++) { int x,y; string s; cin>>x>>y>>s; x--; if (p.find(x)==p.end()) { p[x]=k++; } if (p.find(y)==p.end()) { p[y]=k++; } int odd; if (s=="odd") odd=1; else odd=0; if (!insert(p[x],p[y],odd)) break; } printf("%d\n",i);}
1 0
- poj 1733_Parity game_并查集
- poj 1733 并查集
- poj 1733 并查集
- POJ 1733并查集
- Poj 并查集
- poj并查集
- POJ 并查集
- POJ 1733 并查集 偏移向量
- POJ 1733 Parity game(并查集)
- POJ 1733 Parity game (并查集)
- 【POJ】1733 Parity game 并查集
- poj-1733 Parity game 并查集
- poj 1733带权并查集
- poj 1733(带权并查集)
- [POJ 1733]Parity game[并查集]
- POJ 1733 Parity game(并查集)
- poj 2524 并查集
- POJ 2236 并查集
- git config
- invalidate()和requestLayout()方法调用过程
- 为什么在mysql_query()返回成功后,mysql_store_result()有时返回NULL?
- 停车场项目
- 小技巧:在每行末尾加字符--有没有快速的方法?(批量)
- poj 1733_Parity game_并查集
- mybatis框架中的#和$的区别
- C# HashTable深度解析
- jboss启动错误原因
- 杭电2091空心三角形
- Maven Failsafe 插件
- 题库统计的小玩意_python
- 《iOS移动开发从入门到精通》图书连载6——Xcode8的使用(下)
- Reverse Words in a String