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?
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.
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
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
水题:就是题意刚开始看的不明白
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int main()
{
// freopen("in.txt","r",stdin);
int n;
int s[110][110];
int ans=0;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>s[i][j];
}
}
int a[110];
memset(a,1,sizeof(a));
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
if(s[i][j]==1)
{
a[i]=0;
}
else if(s[i][j]==2)
{
a[j]=0;
}
else if(s[i][j]==3)
{
a[i]=0;
a[j]=0;
}
}
}
for(int i=1;i<=n;i++)
{
if(a[i])
ans++;
}
if(ans==0)
printf("0\n");
else
{
printf("%d\n",ans);
for(int i=1;i<=n;i++)
{
if(a[i])
{
printf("%d ",i);
}
}
printf("\n");
}
return 0;
}
本文介绍了一个简单的编程问题,即通过给定的碰撞矩阵确定哪些玩具车在比赛中未被翻转过,即为“好”车,并输出这些车的编号。
375

被折叠的 条评论
为什么被折叠?



