HDU周赛题

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列,a[i][j]表示第i个车和第j个车进行碰撞时哪一个会被撞翻,0表示都不会被撞翻,1表示第i个车会被撞翻,i车是坏的;2表示第j个车会被撞翻,j车是坏的;3表示两个都会撞翻,表示两个都是坏的。用for循环看看输入的数是对应的哪一种情况。

#include<stdio.h>
#include<string.h>
#define N 1010
int 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",&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)
                {
                    printf("%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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-10 10:29:52

HDU周赛题的相关文章

hdu 4891---水题 但是WA了很多次

这道题的坑在----过程中即使使用long  long 也会超出范围 自己看了很久读了很多遍题还是没想到 记得当时的想法是----反正我用了long long 已经是最大的范围了,肯定没法用更大的类型--即使unsigned也只是 比long long 大一倍,现在回头看,这种想法太唯心,不是理性分析的结果啊,, 代码: //1005 #include <cstdio> #include <cstring> #include <algorithm> #include &

HDU一百题纪念。

切一千个水题,不如思考一个难题.HDU百题纪念.

转载:hdu 动态规划题集

1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);    正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q[i

(hdu 简单题 128道)AC Me(统计一行文本中各个字母出现的次数)

题目: AC Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13465    Accepted Submission(s): 5927 Problem Description Ignatius is doing his homework now. The teacher gives him some articles and as

Hdu匹配题集

普通匹配,多重匹配[HDU]1068Girls and Boys 最大匹配★1150Machine Schedule 最小点覆盖★1151Air Raid 最小路径覆盖★1179Ollivanders 最大匹配★1281棋盘游戏 行列匹配+求关键点★★149850 years, 50 colors 行列匹配★1507Uncle Tom's Inherited Land* 黑白染色+奇偶匹配(1X2的矩形覆盖)★1528Card Game Cheater 最大匹配★1845Jimmy’s Assi

(hdu 简单题 128题)hdu 2005 第几天(计算当天是该年的第几天)

题目: 第几天? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89641    Accepted Submission(s): 33727 Problem Description 给定一个日期,输出这个日期是该年的第几天. Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,

hdu 水题

<h1 style="color: rgb(26, 92, 200); text-align: center; font-family: 'Times New Roman';">统计难题</h1><span style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;"><strong><span style=&

hdu 刷题记录

1007 最近点对问题,采用分治法策略搞定 1 #include<iostream> 2 #include<cmath> 3 #include<algorithm> 4 using namespace std; 5 int n; 6 struct node 7 { 8 double x; 9 double y; 10 }p[100005]; 11 int a[100005]; 12 double cmpx(node a,node b) 13 { 14 return a.

(hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)

题目: 平方和与立方和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 108212    Accepted Submission(s): 34915 Problem Description 给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和. Input 输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组