zoukankan      html  css  js  c++  java
  • Codeforces Round #303 (Div. 2) A. Toy Cars 水题

     A. Toy Cars

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/545/problem/A

    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

    3
    -1 0 0
    0 -1 1
    0 2 -1

     

    Sample Output

    2
    1 3

     

    HINT

    题意

     给你一个矩阵,然后撞来撞去,问你最后有几辆车还是好的

    题解:

    就扫一遍就好啦~

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    
    int dp[110][110];
    int ans[110];
    int main()
    {
        //freopen("test.txt","r",stdin);
        int n=read();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                dp[i][j]=read();
                
        }
        
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(dp[i][j]==3)
                    ans[i]=ans[j]=1;
                if(dp[i][j]==2)
                    ans[j]=1;
                if(dp[i][j]==1)
                    ans[i]=1;
            }
        }
        int k=0;
        for(int i=1;i<=n;i++)
            if(!ans[i])
                k++;
        printf("%d
    ",k);
        for(int i=1;i<=n;i++)
            if(!ans[i])
                printf("%d ",i);
    }
  • 相关阅读:
    [noip2018]day1
    [CF1110d]JONGMAH
    BZOJ 2733 [HNOI2012]永无乡
    BZOJ 3123 [SDOI2013] 森林
    Nowcoder 练习赛26E 树上路径
    Luogu 2575 高手过招-SG函数
    BZOJ 1123[POI2008]BLO-Tarjan
    Nowcoder OI赛制测试2 F 假的数学题
    Luogu 2467[SDOI2010]地精部落
    Luogu 2216[HAOI2007]理想的正方形
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4516129.html
Copyright © 2011-2022 走看看