Codeforces Round #303 (Div. 2)

Source: Internet
Author: User
Tags sort
A. Toy Cars

Little Susie, thanks to his 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 is 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, and both cars turned over. A car is good if it turned over in no collision. The results of the collisions was determined by an NXN matrixа: There was a number on the intersection of Theі-th Row A nd 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 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 this on the main diagonal there are-1, and-1 doesn ' t appear anywhere else in the matrix.

It is guaranteed that the input was correct, that's, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, t Hen Aji = 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 0
0-1 1
0 2-1
Output
2
1 3
Input
4
-1 3 3 3
3-1 3 3
3 3-1 3
3 3 3-1
Output
0 The problem is that in the matrix, the section J of row I shows the collision of the first vehicle with the J car, the value of which represents the collision result, the last output of the surviving vehicle number, the simulation.

#include <stdio.h> #include <string.h> int main () {int st[110];
    memset (St, 0, sizeof (ST));
    int n, A;  while (~SCANF ("%d", &n)) {for (int i = 1; I <= n; i + +) {for (int j = 1; J <= N; j
                + +) {scanf ("%d", &a);
                    if (!st[i]) {if (a = = 1) {St[i] = 1;
                        } else if (a = = 2) {if (!st[j])
                        {St[j] = 1;
                        }} else if (a = = 3) {if (!st[j])
                        {St[j] = 1;
                    } St[i] = 1;
        }}}} int ans = 0; for (int i = 1; i <= N;  
        i + +) {if (!st[i]) ans + +;
        } printf ("%d\n", ans);
        for (int i = 1; I <= n; i + +) {if (!st[i]) printf ("%d", I);
    } printf ("\ n");  }

}
B. Equidistant String

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

We'll define the distance between the strings s and t of the same length consisting of digits zero and one as the number of positions I, such that si isn ' t equal to TI.

As besides everything else Susie loves symmetry, she wants to find for both strings s and t of length n such string p of Le Ngth N, that the distance from P to s is equal to the distance from P to T.

It's time for Susie to go to the bed, help her find such string p or state that it's is impossible.

Input
The first line contains string s of length n.

The second line contains string t of length n.

The length of string n is within range from 1 to 105. It is guaranteed this both strings contain only digits zero and one.

Output
Print a string of length n, consisting of digits zero and one, that meets the problem statement. If No such string exist, print on a, "impossible" (without the quotes).

If There is multiple possible answers, print any of them.

Sample Test (s)
Input
0001
1011
Output
0011
Input
000
111
Output
Impossible
Note
In the first sample different answers is possible, namely-0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101. Get one and give the same length as the string, consistent with the same length of the STR1,STR2, there are many answers, the output of a good, simulation.

#include <stdio.h> #include <string.h> char str1[100010];
Char str2[100010];

BOOL s[100010];

        int main () {while (~SCANF ("%s", str1)) {memset (s,false,sizeof (s));
        scanf ("%s", str2);
        int len = strlen (str1); 
        int cnt = 0; 
            for (int i = 0; i < len; i + +) {if (Str1[i]! = Str2[i]) {cnt + +;
            } else {S[i] = true;
            }} if (cnt%2 = = 1) {printf ("impossible\n"); 
        Continue
        } int amt = 0;
            for (int i = 0; i < len; i + +) {if (S[i]) printf ("%c", Str1[i]);
                else if (!s[i] && Amt < CNT/2) {Amt + +;
            printf ("%c", Str1[i]);
            } else {printf ("%c", Str2[i]);
    }} printf ("\ n");  }
}
C. Woodcutters

Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation is described below.

There is n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree have its height hi. Woodcutters can cut down a tree and fell it to the right. After that it occupies one of the segments [Xi-hi, Xi] or [Xi;xi + hi]. The tree is not a cut-down occupies a, with coordinate XI. Woodcutters can fell a tree if the segment to is occupied by the fallen tree doesn ' t contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what's the maximum number of trees to fell.

Input
The first line contains integer n (1≤n≤105)-the number of trees.

Next n lines contain pairs of integers XI, hi (1≤xi, hi≤109)-the coordinate and the height of theі-th tree.

The pairs is given in the order of ascending XI. No. Trees is located at the point with the same coordinate.

Output
Print a single number-the maximum number of trees so can cut down by the given rules.

Sample Test (s)
Input
5
1 2
2 1
5 10
10 9
19 1
Output
3
Input
5
1 2
2 1
5 10
10 9
20 1
Output
4
Note
The first sample can fell the trees like that:

Fell the 1-st tree to the Left-now it occupies segment [-1;1]
Fell the 2-nd tree to the Right-now it occupies segment [2;3]
Leave the 3-rd tree-it occupies point 5
Leave the 4-th tree-it occupies point 10
Fell the 5-th tree to the Right-now it occupies segment [19;20]
In the second sample can also fell 4-th tree to the right and after that it'll occupy segment [10;19]. DP, get it out as soon as possible. D. Queue

Little girl Susie went shopping with her mom and she wondered what to improve service quality.

There is n people in the queue. For each person, we know time ti needed to serve him. A person would be disappointed if the time he waits was more than the time needed to serve him. The time a person, waits is, the total time, the people who stand in the queue in front of him are served. Susie thought that if we swaps some people in the queue and then we can decrease the number of people who is disappointed.

Help Susie find out what's the maximum number of not disappointed people can being achieved by swapping people in the queue.

Input
The first line contains integer n (1≤n≤105).

The next line contains n integers ti (1≤ti≤109), separated by spaces.

Output
Print a single number-the maximum number of is disappointed people in the queue.

Sample Test (s)
Input
5
15 2 1) 5 3
Output
4
Note
Value 4 is achieved at such a arrangement, for Example:1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. Ask for the minimum number of people, in fact, after the completion of the sequence, from small to large traversal, if the time is more than, in fact, in the last side is not related, so this problem has become very simple, sort.

#include <stdio.h>
#include <algorithm>

using namespace std;

int tt[100010];

int main ()
{
    int n;
    while (~SCANF ("%d", &n))
    {for
        (int i = 0; i < n; i + +)
        {
            scanf ("%d", &tt[i]);
        }
        Sort (TT, TT + N);
        long int sum = 0;
        int cnt = 0;
        for (int i = 0; i < n; i + +)
        {
            if (Tt[i] >= sum)
            {
                cnt + +;
                Sum + = Tt[i];}
        }
        printf ("%d\n", CNT);
    }
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.