Codeforces Round #303 (Div.2)-A. Toy Cars(模拟)
2016-04-12 19:43
316 查看
A. Toy Carstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle 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 turnedover, 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-thcolumn that describes the result of the collision of the і-th and the j-thcar: - 1: if this pair of cars never collided. - 1 occursonly on the main diagonal of the matrix.0: if no car turned over during the collision.1: if only the i-thcar turned over during the collision.2: if only the j-thcar 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?InputThe first line contains integer n (1 ≤ n ≤ 100)— the number of cars.Each of the next n lines contains n space-separatedintegers that determine matrix A.It is guaranteed that on the main diagonal there are - 1, and - 1 doesn'tappear 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.OutputPrint the number of good cars and in the next line print their space-separated indices in the increasing order.Examplesinput
3 -1 0 0 0 -1 1 0 2 -1output
2 1 3input
4 -1 3 3 3 3 -1 3 3 3 3 -1 3 3 3 3 -1output
0
题意:
有1,2,3三个操作,1是i车翻了,2是j车翻了,3是i,j两辆车都翻了,问你还有几辆车没翻。
AC代码:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<vector>using namespace std;int main(){#ifdef zscfreopen("input.txt","r",stdin);#endifint n,m,i,j,k;while(~scanf("%d",&n)){int vis[110]={0};for(i=1;i<=n;++i){for(j=1;j<=n;++j){scanf("%d",&k);if(j>i){if(k==1)vis[i]=true;if(k==2)vis[j]=true;if(k==3)vis[i]=vis[j]=true;}}}vector<int> ve;for(i=1;i<=n;++i){if(!vis[i])ve.push_back(i);}printf("%d\n",ve.size());for(i=0;i<ve.size();++i){printf("%d ",ve[i]);}printf("\n");}return 0;}
相关文章推荐
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- 用javascript和css模拟select的脚本
- PHP模拟asp.net的StringBuilder类实现方法
- C#使用ImitateLogin模拟登录百度
- javascript用层模拟可移动的小窗口
- JS模拟简易滚动条效果代码(附demo源码)
- 自编jQuery插件实现模拟alert和confirm
- JS模拟按钮点击功能的方法
- PHP模拟asp中response类实现方法
- 模拟Spring的简单实现
- javascript 模拟点击广告
- JQuery中模拟image的ajaxPrefilter与ajaxTransport处理
- php实现模拟post请求用法实例
- JavaScript实现MIPS乘法模拟的方法
- 模拟xcopy的函数
- JS模拟实现Select效果代码
- php模拟服务器实现autoindex效果的方法
- C# SendInput 模拟鼠标操作的实现方法
- PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法
- js实现模拟银行卡账号输入显示效果