zoukankan      html  css  js  c++  java
  • hbmy周赛1--D

    D - Toy Cars
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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

    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>
    using namespace std;
    
    int main()
    {
    	int a[110][110], b[110], c[110], d[110];
    	for (int i=0; i<110; i++)
    	{
    		b[i] = 0;
    		c[i] = 0;
    		d[i] = 0;
    	}
    	int n;
    	cin >> n;
    	for (int i=0; i<n; i++)
    	{
    		for (int j=0; j<n; j++)
    		{
    			cin >> a[i][j];
    		}
    	}
    	for (int i=0; i<n; i++)
    	{
    		for (int j=0; j<n; j++)
    		{
    			if (a[i][j] == 1)
    				b[i] = 1;
    			if (a[i][j] == 2)
    				c[j] = 1;
    			if (a[i][j] == 3)
    			{
    				b[i] = 1;
    				c[j] = 1;
    			}
    		}
    	}
    	int result=0;
    	int num = 0;
    	for (int i=0; i<n; i++)
    	{
    		if (b[i]==c[i] && b[i]==0)
    		{
    			d[num++] = i;
    			result++;
    		}
    	}
    	cout << result << endl;
    	if (num>0)
    	{
    		cout << d[0]+1;
    		for (int i=1; i<num; i++)
    			cout << " "<< d[i]+1;
    		cout << endl;
    	}
    	return 0;
    }


  • 相关阅读:
    android学习计划2
    在ubuntu12.04下编译android4.1.2添加JNI层出现问题
    android原生系统裁剪
    LM393,LM741可以用作电压跟随器吗?
    android-86-Can't create handler inside thread that has not called Looper.prepare()
    三星 PMU NXE2000,x-powers的AXP228,NXE2000
    当函数没有return时错误
    Perl OOP
    ORA-01031: 权限不足
    Oracle 10g 10.2.0.1 在Oracle Linux 5.4 32Bit RAC安装手冊(一抹曦阳)
  • 原文地址:https://www.cnblogs.com/Tovi/p/6194894.html
Copyright © 2011-2022 走看看