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 } 
  • 相关阅读:
    经常让程序员恼火的一些事情你是否也遇到过一些?
    CRC文件解压缩问题
    你在淘宝买件东西背后的复杂技术 技术普及帖
    程序员需要戒骄戒躁
    IT路上的应该注意自我规划 学习规划与自我修炼
    腾讯,我最恨别人用枪顶着我的头(转)
    软件管理,软件生命周期,软件过程名词解释
    程序员需要掌握的最终技术是什么? “终极技术”:应对困境的方法和信念
    程序员如何缓解“电脑病”
    新浪微博XSS攻击事件
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5709782.html
Copyright © 2011-2022 走看看