A - Toy Cars

时间:2022-09-02 13:08:24

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代码:

 #include<iostream>
#include<vector>
using namespace std; int a[][];
vector<int> v; //用一个vector容器来储存好车 int main(){
int n;
cin>>n;
for(int i=;i<=n;i++){
int flag=;
for(int j=;j<=n;j++){
cin>>a[i][j];
if(a[i][j]==||a[i][j]==){
flag=;
}
}
if(flag==)
v.push_back(i);
}
int s=v.size();
cout<<s<<endl;
if(s!=){
for(int i=;i<s-;i++){
cout<<v[i]<<" ";
}
cout<<v[s-]<<endl;
} return ;
}

A - Toy Cars的更多相关文章

  1. 周赛-Toy Cars 分类: 比赛 2015-08-08 15&colon;41 5人阅读 评论&lpar;0&rpar; 收藏

    Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  2. Codeforces Round &num;303 &lpar;Div&period; 2&rpar; A&period; Toy Cars 水题

     A. Toy Cars Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/problem ...

  3. 水题 Codeforces Round &num;303 &lpar;Div&period; 2&rpar; A&period; Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  4. &lbrack;POI2005&rsqb;Toy Cars

    题目大意: 有n种物品,地上有k个格子,p次操作. 每次操作要求将某一个指定的物品移动到任意一个格子中,同时你可以选择是否将格子中的某一个物品收起来,并消耗1的代价. 如果下达指令时,这个物品刚好在格 ...

  5. 题解 CF545A 【Toy Cars】

    题目传送门 太弱了,只能写写A题的题解 题意 给你一个 $n·n$ 的矩阵,翻车分三种情况: 如果 $a_i,_j=1$ ,记录第 $i$ 辆车 如果 $a_i,_j=2$ ,记录第 $j$ 辆车 如 ...

  6. P3419 &lbrack;POI2005&rsqb;SAM-Toy Cars &sol; SP688 SAM - Toy Cars

    一道很妙的贪心题 题面 我们考虑当我们插入时会面临的两种情况 当地上的玩具,不满 \(k\) 个时,那我们直接放就可以了. 当满了 \(k\) 个的时候,我们就要从地上拿出一个来给当前的腾位置. 这就 ...

  7. &lbrack;POI2005&rsqb;SAM-Toy Cars

    题目描述 Johnny is a little boy - he is only three years old and enjoys playing with toy cars very much. ...

  8. bzoj1528 sam-Toy Cars&lpar;贪心,优先队列&rpar;

    「BZOJ1528」[POI2005] sam – Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Ja ...

  9. 洛谷 P3419 &lbrack;POI2005&rsqb;SAM-Toy Cars

    P3419 [POI2005]SAM-Toy Cars 题目描述 Johnny is a little boy - he is only three years old and enjoys play ...

随机推荐

  1. php&colon; zend server 安装及相关配置

    运行安装文件(ZendServer-CE-php-5.3.2-5.0.1-Windows_x86.exe)开始安装,选项请参照我的选择. 这里不做改动,维持默认选择即可 点击Browse按钮更改安装目 ...

  2. 黄聪:PHP 防护XSS&comma;SQL&comma;代码执行&comma;文件包含等多种高危漏洞

    版本:v1.1更新时间:2013-05-25更新内容:优化性能功能说明: 可以有效防护XSS,sql注射,代码执行,文件包含等多种高危漏洞. 使用方法: 将waf.php传到要包含的文件的目录 在页面 ...

  3. 使用sem&lowbar;post信号量进行线程同步

    写了一小段程序,测试一下线程同步的问题,如下: #include <stdio.h> #include <string.h> #include <semaphore.h& ...

  4. ANDROID&lowbar;MARS学习笔记&lowbar;S05&lowbar;001&lowbar;用SensorManager获取传感器

    1. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...

  5. 深入JVM锁机制1-synchronized

    目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...

  6. httpclient案例二(调用百度地图的接口)

    一,class T package com.http.test; import org.junit.Test; import com.http.BaiduMapProxyService; import ...

  7. SAP开发系统中开发和配置客户端请求号变更

    假如102为开发客户端,800为配置客户端 正常操作,创建开发请求,应该在102客户端里去创建,但由于操作疏忽开发请求建在了800客户端,如何调整请求到102? 调整步骤:登陆102,SE09找到80 ...

  8. 《剑指offer》 反转链表

    本题来自<剑指offer> 反转链表 题目: 输入一个链表,反转链表后,输出新链表的表头. 思路: 需要三个变量,来保存当前节点的,前面节点和反转后的节点. C++ Code: /* st ...

  9. 【涨姿势】Prince2和PMP的区别,大多数人都没搞清楚!

    项目管理领域有2个流行的知识体系:      ☑ 一个是美国项目管理协会(PMI)开发的“项目管理知识体系(PMBOK,Project Management Body of Knowledge)”,目 ...

  10. probably another instance of uWSGI is running on the same address

    probably another instance of uWSGI is running on the same address 可以用命令杀掉这个端口在重启: /tcp