HDU Week Game problem

Source: Internet
Author: User

Description

Little Susie, thanks to his 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 is 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, and both cars turned over. A car is good if it turned over in no collision. The results of the collisions is determined by an  n? x? 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 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 this on the main diagonal there be   ?-? 1 , and   ?-? 1   doesn ' t appear anywhere else in the matrix.

It is guaranteed and the input is correct, which is, if   A ij ? =?1 , then   A ji ? =?2 , if   A ij ? = 3 , then   A ji ? =?3 , and if   A ij ? =?0 , then   A ji ? =?0 .

Output

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

Sample Input

Input
3-1 0 00-1) 10 2-1
Output
Input
4-1 3 3 33-1 3 33 3-1 33 3 3-1
Output
0

Idea: Enter an integer n, the following n rows n columns, A[i][j] said that the first car and the first J car collision when which will be knocked over, 0 said will not be knocked over, 1 said that the first car will be knocked over, I car is bad; 2 means that the first J car will be knocked over, J car is bad; 3 means two will be knocked over, It means that two of them are bad. Use the For loop to see which number of inputs is the corresponding case.

#include <stdio.h> #include <string.h> #define N 1010int Main () {int n,i,j;    int a[n][n],b[n];        while (~SCANF ("%d", &n)) {int t=n;        for (i=0; i<=n-1; i++) {b[i]=i+1; } for (i=0; i<=n-1; i++) {for (j=0; j<=n-1; J + +) {scanf ("%d", &amp            ; a[i][j]); }} for (i=0, i<=n-1; i++) {for (j=0; j<=n-1; J + +) {if (a[i                        ][j]==1) {if (b[i]!=0) {b[i]=0;                        t--;                    Continue                    } else {continue;                    }} else if (a[i][j]==2) {if (b[j]!=0)                        {b[j]=0;                        t--;  Continue                  } else {continue;                    }} else if (a[i][j]==3) {if (b[i]==0&&b[j]!=0)                        {b[j]=0;                        t=t-1;                    Continue                        } else if (b[i]!=0 && b[j]!=0) {b[i]=0;                        b[j]=0;                        T=t-2;                    Continue                    } else {continue;        }}}} if (t<=0) {printf ("0\n");            } else {printf ("%d\n", t); for (i=0; i<=n-1; i++) {if (b[i]!=0 && i==n-1) {pri    NTF ("%d\n", B[i]);            } else if (b[i]!=0 && i!=n-1) {if (t==1)                    {printf ("%d\n", B[i]);                } else printf ("%d", b[i]); }}}} return 0;}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU Week Game problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.