A - Toy Cars
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
Input3
-1 0 0
0 -1 1
0 2 -1Output2
1 3Input4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1Output0
题意:
共有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的更多相关文章
- 周赛-Toy Cars 分类: 比赛 2015-08-08 15:41 5人阅读 评论(0) 收藏
Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- 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 ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- [POI2005]Toy Cars
题目大意: 有n种物品,地上有k个格子,p次操作. 每次操作要求将某一个指定的物品移动到任意一个格子中,同时你可以选择是否将格子中的某一个物品收起来,并消耗1的代价. 如果下达指令时,这个物品刚好在格 ...
- 题解 CF545A 【Toy Cars】
题目传送门 太弱了,只能写写A题的题解 题意 给你一个 $n·n$ 的矩阵,翻车分三种情况: 如果 $a_i,_j=1$ ,记录第 $i$ 辆车 如果 $a_i,_j=2$ ,记录第 $j$ 辆车 如 ...
- P3419 [POI2005]SAM-Toy Cars / SP688 SAM - Toy Cars
一道很妙的贪心题 题面 我们考虑当我们插入时会面临的两种情况 当地上的玩具,不满 \(k\) 个时,那我们直接放就可以了. 当满了 \(k\) 个的时候,我们就要从地上拿出一个来给当前的腾位置. 这就 ...
- [POI2005]SAM-Toy Cars
题目描述 Johnny is a little boy - he is only three years old and enjoys playing with toy cars very much. ...
- bzoj1528 sam-Toy Cars(贪心,优先队列)
「BZOJ1528」[POI2005] sam – Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Ja ...
- 洛谷 P3419 [POI2005]SAM-Toy Cars
P3419 [POI2005]SAM-Toy Cars 题目描述 Johnny is a little boy - he is only three years old and enjoys play ...
随机推荐
- javascript 高级编程系列 - 创建对象
1. 工厂模式 function createPerson(name, age) { var obj = {}; obj.name = name; obj.age = age; obj.getName ...
- 《Android Studio有用指南》7.1 AndroidStudio代码检查工具概述
本文节选自<Android Studio有用指南> 作者: 毕小朋 博客: http://blog.csdn.net/wirelessqa 眼下本书已上传到百度阅读, 在百度中搜索[Anr ...
- 根据百度地图API获取指定地点的经纬度
做项目时,遇到对地点获取地图中对应的经纬度,作一下笔记,以备以后直接使用 package com.hpzx.data; import java.io.BufferedReader; import ja ...
- teradata培训文档 相关索引
teradata培训文档 http://wenku.baidu.com/view/ec44c201cc175527072208ba.html Teradata 和Greenplum 的讨论 http: ...
- Asynchronous programming with async and await (C#)
Asynchronous Programming with async and await (C#) | Microsoft Docs https://docs.microsoft.com/en-us ...
- 升级python到最新2.7.13
python2.7是2.X的最后一个版本,同时也加入了一部分3.X的新特性.并且具有更好的性能,修改多个bug.所以决定升级到最新的2.7版,我的目前的版本是2.6.6 查看当前python版本 # ...
- poj3295 Tautology —— 构造法
题目链接:http://poj.org/problem?id=3295 题意: 输入由p.q.r.s.t.K.A.N.C.E共10个字母组成的逻辑表达式, 其中p.q.r.s.t的值为1(true)或 ...
- HackerRank leonardo-and-lucky-numbers —— 模线性方程的通解
题目链接:https://vjudge.net/problem/HackerRank-leonardo-and-lucky-numbers 题解: 1.根据扩展欧几里得:7*x + 4*y = gcd ...
- Chrome 插件 Vimium——让你脱离鼠标
下面是帮助,按?就能出现.什么时候忘了可以随时查看.^_^
- hadoop集群异常问题总结
1. Could not find or load main class java.library.path=.opt.hadoop.lib 我的环境上是 hadoopopts变量的配置问题,至于为啥 ...