Codeforces Round #303 A. Toy Cars
2015-08-09 20:22
633 查看
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results
of the collisions are determined by an n × n matrixА: there is a number on the intersection of theі-th row and
j-th column that describes the result of the collision of theі-th and the
j-th car:
- 1: if this pair of cars never collided.
- 1 occurs only on the main diagonal of the matrix.
0: if no car turned over during the collision.
1: if only the i-th car turned over during the collision.
2: if only the j-th car turned over during the collision.
3: if both cars turned over during the collision.
Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.
Each of the next n lines contains
n space-separated integers that determine matrix
A.
It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix.
It is guaranteed that the input is correct, that is, if
Aij = 1, then
Aji = 2, if
Aij = 3, then
Aji = 3, and if
Aij = 0, then
Aji = 0.
Output
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
Sample test(s)
Input
Output
Input
Output
There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results
of the collisions are determined by an n × n matrixА: there is a number on the intersection of theі-th row and
j-th column that describes the result of the collision of theі-th and the
j-th car:
- 1: if this pair of cars never collided.
- 1 occurs only on the main diagonal of the matrix.
0: if no car turned over during the collision.
1: if only the i-th car turned over during the collision.
2: if only the j-th car turned over during the collision.
3: if both cars turned over during the collision.
Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.
Each of the next n lines contains
n space-separated integers that determine matrix
A.
It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix.
It is guaranteed that the input is correct, that is, if
Aij = 1, then
Aji = 2, if
Aij = 3, then
Aji = 3, and if
Aij = 0, then
Aji = 0.
Output
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
Sample test(s)
Input
3 -1 0 0 0 -1 1 0 2 -1
Output
2 1 3
Input
4 -1 3 3 3 3 -1 3 3 3 3 -1 3 3 3 3 -1
Output
0
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <cmath> #define LL long long #define INF 0x3f3f3f3f using namespace std; int s[110][110]; bool vis[110]; int a[110]; int main() { //freopen("in.txt","r",stdin); int n; while(cin>>n) { memset(vis,false,sizeof(vis)); int ant = 0; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { int x; cin>>x; if(x == 1) vis[i] = true; else if(x == 3) vis[i] = true; } } for(int i=1; i<=n; i++) { if(!vis[i]) { a[ant++] = i; } } printf("%d\n",ant); for(int i=0; i<ant; i++) { cout<<a[i]; if(i == ant-1) cout<<endl; else cout<<" "; } } return 0; }
相关文章推荐
- Android编译系统环境初始化过程分析
- hnuoj 13375 Flowery Trails(SPFA)
- 关于二分查找分
- Java栈的实例模拟
- a++与++a的一个误区
- [Ptrace]Linux内存替换(四)代码注入
- [C++11 并发编程] 05 - Mutex 基本操作
- hdu 2119
- MFC之托盘
- [HDU 3923] Invoker polya
- 设计模式--中介者模式
- Android OOM异常解决方案
- 关于进程间互发信息
- 【ME】互联网创业公司失败的7大特征
- QQ连连看辅助c++版本的
- 单例,函数的三种调用方式
- Scut游戏server引擎Unity3d访问
- Android ANR异常解决方案
- 模板方法设计模式
- 代理模式(基础)