CodeForces 545A
2015-08-08 17:10
239 查看
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 00 -1 10 2 -1
Output
21 3
Input
4-1 3 3 33 -1 3 33 3 -1 33 3 3 -1
Output
0
///这是本次这周赛中传说最简单的一道题,抠英文抠了好半天就是读不懂题意,英语是硬伤啊>_<最后看明白的差不多了,输入的n是指小汽车的数量,矩阵中的-1是指小车不会和自己相撞,0表示两个车都不会撞坏,1表示矩阵中该行所表示的车号被撞坏,2表示矩阵中该列所表示的车号被撞坏,3表示都被撞坏。以下有两种方法:
法一:
#include<stdio.h>
#include<string.h>
int s[110][110], a[110], b[110], vis[110];
int main()
{
int n, i, j;
scanf("%d", &n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d", &s[i][j]);
}
}
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
a[i]=i;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(s[i][j]==1)
{
vis[i]=1;
}
else if(s[i][j]==2)
{
vis[j]=1;
}
else if(s[i][j]==3)
{
vis[i]=vis[j]=1;
}
}
}
int t=0, sum=0;
for(int i=0;i<n;i++)
{
if(vis[i]==0)
{
b[t++]=a[i];
sum++;
}
}
printf("%d\n", sum);
if(sum!=0)
{
for(int i=0;i<t;i++)
{
printf("%d", b[i]+1);
if(i<t-1)
printf(" ");
}
}
return 0;
}
法二:
#include<stdio.h>
int main()
{
int n;
int s[110][110];
scanf("%d", &n);
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
scanf("%d", &s[i][j]);
}
}
int f;
int a[110], t=0, sum=0;
for(int i=0; i<n; i++)
{
f=1;
for(int j=0; j<n; j++)
{
if(s[i][j]==1 || s[i][j]==3)
{
f=0;
break;
}
}
if(f==1)
{
a[t++]=i+1;//
sum++;
}
}
printf("%d\n", sum);
if(sum!=0)
{
for(int i=0; i<t; i++)
{
printf("%d", a[i]);
if(i<t-1)
printf(" ");
}
}
return 0;
}
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 00 -1 10 2 -1
Output
21 3
Input
4-1 3 3 33 -1 3 33 3 -1 33 3 3 -1
Output
0
///这是本次这周赛中传说最简单的一道题,抠英文抠了好半天就是读不懂题意,英语是硬伤啊>_<最后看明白的差不多了,输入的n是指小汽车的数量,矩阵中的-1是指小车不会和自己相撞,0表示两个车都不会撞坏,1表示矩阵中该行所表示的车号被撞坏,2表示矩阵中该列所表示的车号被撞坏,3表示都被撞坏。以下有两种方法:
法一:
#include<stdio.h>
#include<string.h>
int s[110][110], a[110], b[110], vis[110];
int main()
{
int n, i, j;
scanf("%d", &n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d", &s[i][j]);
}
}
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
a[i]=i;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(s[i][j]==1)
{
vis[i]=1;
}
else if(s[i][j]==2)
{
vis[j]=1;
}
else if(s[i][j]==3)
{
vis[i]=vis[j]=1;
}
}
}
int t=0, sum=0;
for(int i=0;i<n;i++)
{
if(vis[i]==0)
{
b[t++]=a[i];
sum++;
}
}
printf("%d\n", sum);
if(sum!=0)
{
for(int i=0;i<t;i++)
{
printf("%d", b[i]+1);
if(i<t-1)
printf(" ");
}
}
return 0;
}
法二:
#include<stdio.h>
int main()
{
int n;
int s[110][110];
scanf("%d", &n);
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
scanf("%d", &s[i][j]);
}
}
int f;
int a[110], t=0, sum=0;
for(int i=0; i<n; i++)
{
f=1;
for(int j=0; j<n; j++)
{
if(s[i][j]==1 || s[i][j]==3)
{
f=0;
break;
}
}
if(f==1)
{
a[t++]=i+1;//
sum++;
}
}
printf("%d\n", sum);
if(sum!=0)
{
for(int i=0; i<t; i++)
{
printf("%d", a[i]);
if(i<t-1)
printf(" ");
}
}
return 0;
}
相关文章推荐
- C++中引用(&)的用法和应用实例
- hongyang的博文深入理解Android中的自定义属性 学习笔记
- Vanya and Lanterns
- linux系统的颜色配置
- 快速幂
- Parcelable接口的使用
- HDU 1677 二分法进行判断
- 解决 Jenkins 没有权限监听 Gerrit 的 ‘Stream Events’的问题
- ZOJ 3430 Detect the Virus (AC自动机)
- 堆排序(初学者)
- jquery 实现可编辑div
- HDU A Mathematical Curiosity
- 【ITOO高校云平台】——浅析权限系统中角色与职位
- 数据结构学习---堆栈的动态数组实现及链表实现
- NDK环境配置
- 数据结构学习---堆栈的动态数组实现及链表实现
- [Java]如何避免啰嗦的代码风格
- 自定义view(视图类)
- Java学习笔记------BufferedLine类的readLine()方法 使用须知
- poj3104 Drying(二分)