CodeForces 303A Toy Cars

来源:互联网 发布:国泰安数据库是什么 编辑:程序博客网 时间:2024/05/16 09:19

time limit per test 1 second
memory limit per test256 megabytes
inputstandard input

outputstandard output
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
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

想要知道小车是否相撞,开车后是否有完好无埙的小车,有N个小车,形成N*N的矩阵,矩阵中,a[i][i]的坐标为-1,因为同样的小车不会相撞,如果是1,那么横向对应的小车被撞翻,如果是2,那么纵向的小车被撞翻,如果是0,则没有撞车。

#include<iostream>#include<string.h>using namespace std;int a[110][110];int b[110];int main(){    int n;    int i,j;    while(cin>>n)    {        for(i=1;i<=n;i++)        {            for(j=1;j<=n;j++)  cin>>a[i][j];        }        int flag=0;        int count=0;        for(i=1;i<=n;i++)        {            for(j=1;j<=n;j++)            {                if(a[i][j]==1||a[i][j]==3)  flag=1;            }            if(flag==1)            {                b[i]=1;                flag=0;            }        }        flag=0;        for(j=1;j<=n;j++)        {            for(i=1;i<=n;i++)            {                if(a[i][j]==2||a[i][j]==3)  flag=1;            }            if(flag==1)            {                b[j]=1;                flag=0;            }        }        flag=0;        for(i=1;i<=n;i++)        {            if(b[i]==0)  count++;        }        cout<<count<<endl;        if(count!=0)        {            for(i=1;i<=n;i++)            {                if(b[i]==0)                 {                    if(flag==0)                     {                        flag=1;                        cout<<i;                    }                     else  cout<<" "<<i;                }             }            cout<<endl;        }        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));     }    return 0;} 
0 0