Central heating
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 678   Accepted: 310

Description

Winter has come, but at the Ural State University heating is not turned on yet. There's one little problem: the University is heated only if all of the valves are opened. There are some technicians at the University. Each of them is responsible for one or more valves. There may be several technicians responsible for the same valve. When a technician gets an instruction to turn on the heating he goes round all of his valves and turns them. It means that if a valve was opened then he closes it, and if it was closed then he opens it. It is well known that every technician earns his money not in vain so it's impossible to replace any technician by any combination of other technicians. 
Your task is to determine who of the technicians is to get an instruction "to turn on the heating" in order to heat all the Ural State University. Note that there are N technicians and N valves at the University (1 <= N <= 250). 

Input

The first line of an input contains the number N. The next N lines contain lists of the valves in charge of each of the technicians. It means that a line number i + 1 contains numbers of the valves that the i-th technician is responsible for. Each list of valves is followed by –1.

Output

An output should contain a list of technicians' numbers sorted in ascending order. If several lists are possible, you should send to an output the shortest one. If it's impossible to turn on the heating at the University, you should write "No solution" .

Sample Input

4
1 2 -1
2 3 4 -1
2 -1
4 -1

Sample Output

1 2 3

Source

/*
* @Author: Lyucheng
* @Date: 2017-08-09 16:37:47
* @Last Modified by: lyuc
* @Last Modified time: 2017-08-14 11:31:17
*/ /*
题意:有n个窗口,有n个师傅,每个师傅可以管理很多窗口,可以重复的,给一个师傅下命令,这个师傅会管理他所有的
窗口,如果是关闭的就打开,如果是打开的就关闭,现在想让所有的窗口打开,问你怎么下命令 思路:将每个师傅管理的窗口转化成01序列,末尾加0,表示方程的结果,然后凑成矩阵,高斯消元解方程,消元的时候
变成异或
*/ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define MAXN 255 using namespace std; int n;
int cur;
int a[MAXN][MAXN];//增广矩阵
int x[MAXN];//解集 void Gauss(){
for(int i=;i<n;i++){
int col=-;
for(int j=i;j<n;j++){//找到第一个不为零的行
if(a[j][i]){
col=j;
break;
}
}
for(int j=i;j<=n;j++){
swap(a[i][j],a[col][j]);
}
for(int j=i+;j<n;j++){
if(a[j][i]!=){
for(int k=i;k<=n;k++){
a[j][k]^= a[i][k];
}
}
}
}
for (int i=n-;i>=;--i){
x[i] = a[i][n];
for (int j=i-;j>=;--j){
a[j][n]^=(x[i]&a[j][i]);
}
}
} inline void init(){
memset(a,,sizeof a);
memset(x,,sizeof x);
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;i++){
while(scanf("%d",&cur)&&cur!=-){
a[cur-][i]=;
}
a[i][n]=;
} Gauss();
bool flag=true;
for (int i=;i<n;i++){
if(x[i]){
if(flag==true){
flag=false;
printf("%d",i+);
}else{
printf(" %d",i+);
}
}
}
printf("\n");
}
return ;
}

poj 2345 Central heating的更多相关文章

  1. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

  2. POJ 2345 Central heating(高斯消元)

    [题目链接] http://poj.org/problem?id=2345 [题目大意] 给出n个开关和n个人,每个人可以控制一些开关,现在所有的开关都是关着的 一个指令可以让一个人掰动所有属于他控制 ...

  3. js地址下拉列表中全职工作

    /******************************************************************* *输出全国各省辖市下拉列表项writeCitys() *输出企 ...

  4. 每日英语:Air Pollution From Coal Use Cuts Lifespans in China, Study Shows

    Air pollution from coal combustion likely cut life expectancy in parts of China by more than five ye ...

  5. words2

    餐具:coffee pot 咖啡壶coffee cup 咖啡杯paper towel 纸巾napkin 餐巾table cloth 桌布tea -pot 茶壶tea set 茶具tea tray 茶盘 ...

  6. poj 2732 Countdown(East Central North America 2005)

    题意:建一个家庭树,找出有第d代子孙的名字,按照要求的第d代子孙的数从大到小输出三个人名,如果有一样大小子孙数的,就按字母序从小到大将同等大小的都输出,如果小于三个人的就全输出. 题目链接:http: ...

  7. POJ 1240 Pre-Post-erous! && East Central North America 2002 (由前序后序遍历序列推出M叉树的种类)

    题目链接:http://poj.org/problem?id=1240 本文链接:http://www.cnblogs.com/Ash-ly/p/5482520.html 题意: 通过一棵二叉树的中序 ...

  8. POJ 1240 Pre-Post-erous! && East Central North America 2002 (由前序后序遍历序列推出M叉树的种类)

    题目链接 问题描述 : We are all familiar with pre-order, in-order and post-order traversals of binary trees. ...

  9. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

随机推荐

  1. Sql Server——运用代码创建数据库及约束

    在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...

  2. Dijkstra堆优化学习

    最短路径例题 今天特地学习了Dijkstra的堆优化(主要是慕名已久). 我们需要一个堆来记录[编号,到编号这个点的最短路径值(当然只是当前的)] 与原来的Dijkstra操作基本一致,主要有以下几点 ...

  3. 第5章 不要让线程成为脱缰的野马(Keeping your Threads on Leash) ---简介

    这一章描述如何初始化一个新线程,如何停止一个执行中的线程,以及如何了解并调整线程优先权.    读过这一章之后,你将有能力回答一个 Win32 多线程程序设计的最基本问题.你一定曾经在 Usenet ...

  4. JSP入门 taglib

    自定义标签库(taglib),将原本需要写在jsp中的java代码封装起来,成为可复用的组件. taglib的写法和jsp动作(action)很相似,是由taglib前缀,冒号,标签名三者的组合体.其 ...

  5. B树、B+树、B*树

    二叉搜索树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右指针指向大于其关键字的子树: 如 ...

  6. .NET DateTime 源码学习

    今天下载了微软.Net 源码,看了一下DateTime类,做下记录 DaysInMonth 这个方法是获取某年某月的天数,平时直接用觉得很简单,今天看到源码,发现设计的还是很好的 我想如果是我的话,封 ...

  7. Java历程-初学篇 Day07 循环结构2 for循环

    一,格式 for(赋值语句//为循环变量赋初值;条件语句//循环结构的循环条件;赋值语句//迭代,修改循环变量的值){ //循环体; } 二,简单举例 for(int i=1;i<=10;i++ ...

  8. springMVC中的redirect和forward区别?

    1.forward在跳转后可以取到message值,redirect在跳转后无法取到message值. 2.forward跳转后地址栏URL不会改变,而redirect会改变.

  9. Python实战之双向队列deque/queue学习笔记及简单练习

    ['__add__', '__bool__', '__class__', '__contains__', '__copy__', '__delattr__', '__delitem__', '__di ...

  10. ELK日志收集分析系统配置

    ELK是日志收益与分析的利器. 1.elasticsearch集群搭建 略 2.logstash日志收集 我这里的实现分如下2步,中间用redis队列做缓冲,可以有效的避免es压力过大: 1.n个ag ...