【题目链接】:click here~~
【题目大意】:
给一个n*n的矩阵,-1只在对角线出现(因为自己不能撞自己),0代表没有车在碰撞,1代表第i辆车(横坐标)被撞坏了,2代表第j辆车(纵坐标)被撞坏了,3代表两辆车都撞坏了。问哪几辆车完好无损。
代码:
/*
* Problem: CodeForces - 545A
* Running time: 15MS
* Complier: G++
* Author: herongwei
* Create Time: 7:47 2015/9/17 星期四
*统计每行1和3的个数,如果二者只要有其中之一,车就意味着坏了
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+100;
const int inf=0x7f7f7f7f;
bool ok[N];
int main()
{
int t,n,m;
memset(ok,false,sizeof(ok));
scanf("%d",&t);
for(int i=1; i<=t; ++i){
for(int j=1; j<=t; ++j){
int x;
scanf("%d",&x);
if(x==1||x==3)
ok[i]=true;
}
}
int ans=0;
for(int i=1; i<=t; ++i){
if(!ok[i]) ans++;
}
printf("%d\n",ans);
for(int i=1; i<=t; ++i){
if(!ok[i])
printf("%d ",i);
}
if(ans) puts("");
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
CodeForces - 545A Toy Cars (模拟)
原文地址:http://blog.csdn.net/u013050857/article/details/48516797