今天是6.1儿童节小朋友们节日快乐!!!
关于此题,一开始犯了一个致命的错误, 一开始没在b数组内设置初始化的值。碰到0 就b[i] = 0,b[j] = 0.
碰到3 就b[i] = 1,b[j] = 1,碰到1 就b[i] = 1,b[j] = 0,碰到2 就b[i] = 0,b[j] = 1(1代表撞翻,0代表未撞翻),结果导致 WA。什么原因你们懂得。
后来就都设为0, 直接筛1,2,3三种情况
#include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[105][105];
int i ,j;
int b[105]={0};
int cnt;
for(i = 0; i < n; i++)
for(j = 0 ; j < n ; j++)
{
scanf("%d", &a[i][j]);
}
// for(i = 0; i < n; i++)
// for(j = 0 ; j < n ; j++)
// {
// printf("%d ", a[i][j]);
// if(j == n-1)
// printf("\n");
for(i = 0; i < n; i++)
for(j = 0 ; j < n ; j++)
{
if(a[i][j] == -1)
break;
if(a[i][j] == 3)
{
b[i] = 1;
b[j] = 1;
}
if(a[i][j] == 1)
b[i] = 1;
if(a[i][j] == 2)
b[j] = 1;
}
// for( i = 0 ; i < n ; i++)
// printf("b[%d] = %d ",i, b[i]);
for( i = 0 , cnt = 0; i < n; i++)
{
if(b[i] == 0)
cnt++;
}
printf("%d\n", cnt);
for( i = 0; i < n; i++)
{
if(b[i] == 0)
printf("%d ", i+1);
}
return 0;
}
就行了。
Description
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 Input
3 -1 0 0 0 -1 1 0 2 -1
2 1 3
4 -1 3 3 3 3 -1 3 3 3 3 -1 3 3 3 3 -1
0