zoukankan      html  css  js  c++  java
  • A

    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

    题意:

    共有n辆车互相碰撞,表现为一个n*n的矩阵,矩阵的对角线为-1表示自己对自己。行和列分别表示为i-th和j-th,当(i-th,j-th)为1时表示i-th翻车,2时表示j-th翻车,3

    时表示两车全部翻车。0表示没有车翻车。只要没有翻过的车就是好车。

    思路:

    对于每行扫描,当出现1/3时,就说明翻过车。

    附AC代码:

     1 #include<iostream>
     2 #include<vector>
     3 using namespace std;
     4 
     5 int a[110][110];
     6 vector<int> v; //用一个vector容器来储存好车
     7 
     8 int main(){
     9     int n;
    10     cin>>n;
    11     for(int i=1;i<=n;i++){
    12         int flag=1;
    13         for(int j=1;j<=n;j++){
    14             cin>>a[i][j];
    15             if(a[i][j]==1||a[i][j]==3){
    16                 flag=0;
    17             }    
    18         }
    19         if(flag==1)
    20             v.push_back(i);
    21     }
    22     int s=v.size();
    23     cout<<s<<endl;
    24     if(s!=0){
    25         for(int i=0;i<s-1;i++){
    26         cout<<v[i]<<" ";
    27     }
    28     cout<<v[s-1]<<endl;
    29     }
    30     
    31     return 0;
    32 } 
  • 相关阅读:
    XGBoost算法--学习笔记
    机器学习--学习书籍
    一天搞懂深度学习-深度学习新浪潮
    如何在 Office 365 环境中设置联机 Exchange 邮箱大小和限制
    玩转Office 365中的Exchange Online服务 之十一 怎样在Exchange Online中配置邮件传递限制《转》
    玩转Office 365中的Exchange Online服务 之六 了解Exchange Online对于邮箱使用的限制《转》
    Hyper-V Ubuntu修改分辨率
    k8s 集群基本概念<转>
    Azure 中 Linux VM 的 SSH 公钥和私钥对
    docker学习笔记(k8s) 《转》
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5709782.html
Copyright © 2011-2022 走看看