本文整理汇总了C++中Pair::reverse方法的典型用法代码示例。如果您正苦于以下问题:C++ Pair::reverse方法的具体用法?C++ Pair::reverse怎么用?C++ Pair::reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pair
的用法示例。
在下文中一共展示了Pair::reverse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
//read data
/*{{{*/
scanf("%d %d", &n_var, &n_ineq);
if(n_ineq == 0){
printf("0\n");
return 0;
}
list<Pair> equal;
list<Pair> less_than;
for(int i=0 ; i<n_ineq ; i++){
Pair p;
int option;
scanf("%d %d %d", &p.a, &p.b, &option);
if(option == 0){
equal.push_back(p);
}
else if(option == -1){
less_than.push_back(p);
}
else{
p.reverse();
less_than.push_back(p);
}
}
#ifdef DEBUG
printf("equalities: \n");
for_each(equal.begin(), equal.end(), print_pair);
printf("inequalities: \n");
for_each(less_than.begin(), less_than.end(), print_pair);
#endif
/*}}}*/
//make equal values equal
/*{{{*/
Elem elems[n_var+1];
list<Pair>::iterator itr = equal.begin();
while(itr != equal.end()){
Union(elems + itr->a, elems + itr->b);
itr++;
}
//translate pairs
for(itr = less_than.begin(); itr != less_than.end(); itr++){
itr->a = elems[itr->a].find() - elems;
itr->b = elems[itr->b].find() - elems;
}
#ifdef DEBUG
printf("translated inequalities: \n");
for_each(less_than.begin(), less_than.end(), print_pair);
#endif
/*}}}*/
//remove duplicates
/*{{{*/
less_than.sort(pair_compare);
less_than.unique();
#ifdef DEBUG
printf("unique inequalities: \n");
for_each(less_than.begin(), less_than.end(), print_pair);
#endif
/*}}}*/
//convert inequalities to graph
Node graph[n_var + 1];
for(itr = less_than.begin(); itr != less_than.end(); itr++){
graph[itr->a].exists = true;
graph[itr->a].next.push_back(itr->b);
graph[itr->b].exists = true;
graph[itr->b].in_degree++;
}
//do topological sort
list<int> zero;
list<int>::iterator rti1;
list<int>::iterator rti2;
int res = 0;
while(find_zero_in(graph, n_var+1, zero)){
res ++;
for(rti1 = zero.begin(); rti1 != zero.end(); rti1++){
graph[*rti1].exists = false;
for(rti2 = graph[*rti1].next.begin() ; rti2 != graph[*rti1].next.end(); rti2++)
graph[*rti2].in_degree -- ;
}
zero.clear();
}
//check if any cycles exist
for(int i =0 ;i<=n_var; i++){
if(graph[i].exists){
printf("NO\n");
return 0;
}
}
//.........这里部分代码省略.........