离散作业之goodguy and badguy
来源:互联网 发布:网络主播策划方案 编辑:程序博客网 时间:2024/05/12 06:25
1. There are two types of professional wrestlers: "good guys" and "bad guys." Between any pair
of professional wrestlers, there may or may not be a rivalry. Suppose we have n professional
wrestlers and we have a list of r pairs of wrestlers for which there are rivalries. Give an O(n +
r)-time algorithm that determines whether it is possible to designate some of the wrestlers as
good guys and the remainder as bad guys such that each rivalry is between a good guy and a
bad guy. If is it possible to perform such a designation, your algorithm should produce it.
这个月太忙,都没时间写博客
刚写了离散作业,实际是BFS的变体
直接上代码
bool Graph::designation(int s){
initBFS();
graNodes[s].color=GRAY;
graNodes[s].level=0;
deque<Node*> blocks;
blocks.clear();
blocks.push_back(&graNodes[s]);
Node* tempNode;
while(!blocks.empty()){
tempNode=blocks.front();
blocks.pop_front();
cout<<"*"<<tempNode->nodeID<<"*";
for (vector<Node*>::iterator ivl = (tempNode->adjList).begin(); ivl != (tempNode->adjList).end(); ivl++) {
if(((*ivl)->color)!=WHITE){
if(((*ivl)->level%2)==(tempNode->level%2)){
cout<<"节点"<<(*ivl)->nodeID<<"和节点"<<(tempNode->nodeID)<<"不能满足条件"<<endl;
return false;
}
}
else{
(*ivl)->color=GRAY;
(*ivl)->level=tempNode->level+1;
(*ivl)->pre=tempNode->nodeID;
blocks.push_back(*ivl);
}
}
tempNode->color=BLACK;
}
return true;
}
- 离散作业之goodguy and badguy
- 离散作业之真值表
- 离散作业之无环图两点间路径数目
- badguy 176-194
- Mayor's posters----POJ_2528----线段树之成段更新and离散化
- opencv之离散傅里叶变换
- OpenCV之离散傅里叶变换
- [数据离散化]codeforces510D fox and jumping
- HDU 6012 Lotus and Horticulture 离散化
- 5.opencv之离散傅里叶变换
- 存储管理之离散存储
- 线段树 之 离散化
- 离散对数之ElGamal 密码
- 南邮离散大作业欧拉回路
- 离散事件模拟——银行队列问题//数据结构作业
- 机器学习作业之 Multi-class Classification and Neural Networks(week4)
- Coursera-Deep Learning Specialization 课程之(一):Neural Networks and Deep Learning-weak2编程作业
- Coursera-Deep Learning Specialization 课程之(一):Neural Networks and Deep Learning-weak3编程作业
- 对面的师弟
- DAO 设计4、事务处理(1)
- java也能写出漂亮的界面(Java开源Swing外观)
- Generic Data Access Objects
- SQL Injection Scanner
- 离散作业之goodguy and badguy
- poj1035
- DAO设计模式
- 阳历算阴历-----C语言程序
- 这种生活同猪有什么不同?
- java代理模式 (转)
- 使用外部 JavaScript
- ggggg
- 服务器常用端口