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 ...
随机推荐
- EC知识总结ITE5570
以笔记本上的EC ITE5570进行讲解 ITE EC代码解析 1.一简介 EC(Embed Controller,嵌入式控制器)是一个16位单片机,它内部本身也有一定容量的Flash来存储EC的代 ...
- mongodb3.0 性能測试报告 二
mongodb3.0 性能測试报告 一 mongodb3.0 性能測试报告 二 mongodb3.0 性能測试报告 三 測试环境: 服务器:X86 pcserver 共6台 cpu: 单颗8核 ...
- 如何打造你的独特观点(一) ——形成“自己的想法”的基础课zz
信息过载的时代,能在各种KOL的声音中保持独立思考很不容易,能输出独特观点又进一层.不断练习我们独立思考的能力,有助于看清周围复杂的事物,也能让我们在日常生活中给人留下“有趣之人”的印象,提升人际交往 ...
- Learning English From Android Source Code:2 Ampersand
这一次想把标点符号的英语表达总结一下,这些单词非常重要但easy被我们忽视.以我的经验,还是多认识几个.以备不时之需. 以下从"标点符号"開始: punctuation [英][ˌ ...
- windows常用命令(转载)
1.最基本,最常用的,测试物理网络的 ping 192.168.0.8 -t ,参数-t是等待用户去中断测试 2.查看DNS.IP.Mac等 A.Win98:winipcfg B.Win2000 ...
- Winform拖拽改变无边框窗体大小
大家在进行Winform开发过程中,很容易就可以完成一个窗口的布局工作,但现在的软件界面美化效果一个比一个好,很多软件都是无边框的,于是乎,你是不是也感叹:winform的带边框的窗体如此丑陋,我一定 ...
- 【洛谷 2405】 non天平
题目背景 non最近正在为自己的体重而苦恼,他想称量自己的体重.于是,他找来一个天平与许多砝码. 题目描述 砝码的重量均是n的幂次,n^1.n^2.n^3.n^4.n^5的……non想知道至少要多少个 ...
- 在图片上加字符-base64转图片-图片转base64
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C++ ini解析器
在gitee上找到的一个很好用的ini文件解析器,纯C++代码,移植方便. 项目地址:https://gitee.com/sollyu/IniParser 稍微修改了下,去掉了Windows平台相关定 ...
- HTML初级教程
1:标题h1~h6HTML标签有专门的标签处理你页面上的标题,它们是h1,h2,h3,h4,h5和h6,象封建社会一样,h1就是万能的君主而h6就是最底层的百姓. 注意,h1标签在一个页面只能使用一次 ...