Codeforces Round #303 (Div. 2) A,B,D题解

A. Toy Cars

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 arentoy 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 ann×nmatrixА: there is a number on the intersection of the-th row andj-th column that describes the result of the collision of the-th and thej-th car:

-1: if this pair of cars never collided.-1occurs only on the main diagonal of the matrix.0: if no car turned over during the collision.1: if only thei-th car turned over during the collision.2: if only thej-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 integern(1≤n≤100) — the number of cars.

Each of the nextnlines containsnspace-separated integers that determine matrixA.

It is guaranteed that on the main diagonal there are-1, and-1doesn’t appear anywhere else in the matrix.

It is guaranteed that the input is correct, that is, ifAij=1, thenAji=2, ifAij=3, thenAji=3, and ifAij=0, thenAji=0.

Output

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

Sample test(s)

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

0A题的题意短时间内对于我这种英语不好的很难啊,有点感觉,这一题(1,,2)数字为单向成立的,而(0,0)为双向成立的。

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int a[105][105];int main(){//freopen("i.txt", "r",stdin);//freopen("o.txt", "w",stdout);int n;int ans[105];scanf("%d", &n);memset(ans, 0, sizeof(ans));int q = 0;for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){scanf("%d", &a[i][j]);}}int tt;for (int i = 0; i < n; i++){tt =1;for (int j = 0; j < n; j++){if (i != j){if (a[i][j] == a[j][i] && a[i][j] !=0){tt = 0;break;}else if(a[i][j]==1&&a[j][i]==2){tt = 0;break;}}}if (tt){ans[q++] = i + 1;}}printf("%d\n", q);for (int i = 0; i < q; i++)printf("%d ", ans[i]);return 0;}

B. Equidistant String

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:

We will define the distance between two stringssandtof the same length consisting of digits zero and one as the number of positionsi, such thatsiisn’t equal toti.

As besides everything else Susie loves symmetry, she wants to find for two stringssandtof lengthnsuch stringpof lengthn, that the distance fromptoswas equal to the distance fromptot.

It’s time for Susie to go to bed, help her find such stringpor state that it is impossible.

Input

The first line contains stringsof lengthn.

The second line contains stringtof lengthn.

两粒种子,一片森林。

Codeforces Round #303 (Div. 2) A,B,D题解

相关文章:

你感兴趣的文章:

标签云: