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 compare with the task?
InputThe 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? -? 1 doesn' 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.
OutputPrint the number of good cars and in the next line print their space-separated indices in the increasing order.
Sample test (s) input3-1 0 00 -1 10 2 -1
Output21 3
Input4-1 3 3 33 -1 3 33 3 -1 33 3 3 -1
Output0
/*************************************** * ******** Author: CKbossCreated Time: Wednesday, June 16, May 20, 2015 File Name:. cpp *************************************** * *********/# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; const int maxn = 111; int n; int mat [maxn] [maxn]; vector
Vi; int main () {// freopen ("in.txt", "r", stdin); // freopen ("out.txt", "w", stdout ); scanf ("% d", & n); for (int I = 1; I <= n; I ++) {bool flag = true; for (int j = 1; j <= n; j ++) {scanf ("% d", & mat [I] [j]); if (mat [I] [j] = 1 | mat [I] [j] = 3) flag = false;} if (flag) vi. push_back (I);} int sz = vi. size (); printf ("% d \ n", sz); for (int I = 0; I
B. Equidistant Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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 equalTI.
As besides everything else Susie loves ry, 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.
The length of stringNIs within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Output
Print a string of lengthN, Consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes ).
If there are multiple possible answers, print any of them.
Sample test (s) input
00011011
Output
0011
Input
000111
Output
impossible
Note
In the first sample different answers are possible, namely-0010,001 1, 0110,011 1, 1000,100 1, 1100,110 1.
Situation analysis:
/*************************************** * ******** Author: CKbossCreated Time: Wednesday, January 1, May 20, 2015 File Name: B. cpp *************************************** * *********/# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; const int maxn = 1001000; int n; char s [maxn]; char t [maxn]; char p [maxn]; int main () {// freopen ("in.txt", "r", stdin); // freopen ("out.txt", "w", stdout); scanf ("% s ", s); scanf ("% s", t); int n = strlen (s); int diff01 = 0, diff10 = 0; for (int I = 0; I
C. Woodcutterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
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 that is described below.
There areNTrees located along the road at points with coordinatesX1 ,?X2 ,?...,?XN. Each tree has its heightHI. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [XI? -?HI,?XI] Or [XI;XI? +?HI]. The tree that is not cut down occupies a single point with coordinateXI. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. the woodcutters want to process as your trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input
The first line contains integerN(1? ≤?N? ≤? 105)-the number of trees.
NextNLines contain pairs of integersXI,?HI(1? ≤?XI,?HI? ≤? (109)-the coordinate and the height of?-Th tree.
The pairs are given in the order of ascendingXI. No two trees are located at the point with the same coordinate.
Output
Print a single number-the maximum number of trees that you can cut down by the given rules.
Sample test (s) input
51 22 15 1010 919 1
Output
3
Input
51 22 15 1010 920 1
Output
4
Note
In the first sample you 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 you can also fell 4-th tree to the right, after that it will occupy segment [10; 19].
Greedy, try to reverse to the left, if not to the right (it will not affect the optimal value)
/*************************************** * ******** Author: CKbossCreated Time: July 22, Wednesday, File Name: C. cpp *************************************** * *********/# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; const int maxn = 100100; int n; struct Tree {int x, h;} tree [maxn]; bool cmp (Tree a, Tree B) {if (. x! = B. x) return a. x
D. Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There areNPeople in the queue. For each person we know timeTINeeded to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. the time a person waits is the total time when all the people who stand in the queue in front of him are served. susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
Input
The first line contains integerN(1? ≤?N? ≤? 105 ).
The next line containsNIntegersTI(1? ≤?TI? ≤? 109), separated by spaces.
Output
Print a single number-the maximum number of not disappointed people in the queue.
Sample test (s) input
515 2 1 5 3
Output
4
Note
Value 4 is achieved at such an arrangement, for example: 1 ,? 2 ,? 3 ,? 5 ,? 15. Thus, you can make everything feel not disappointed before t for the person with time 5.
Greedy: Sorting from small to large. skip this step if angry already exists.
/*************************************** * ******** Author: CKbossCreated Time: Wednesday, June 17, May 20, 2015 File Name: D. cpp *************************************** * *********/# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; typedef long int LL; int n; LL t [100100]; int main () {// freopen ("in.txt", "r", stdin ); // freopen ("out.txt", "w", stdout); scanf ("% d", & n); for (int I = 0; I
> T [I]; sort (t, t + n); LL total = 0; int allright = 0; for (int I = 0; I
= T [I]) {continue;} int angry = 0; total = 0; for (int I = 0; I
T [I]) angry ++; else total + = t [I];} printf ("% d \ n", max (allright, n-angry )); return 0 ;}
E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output
Little girl Susie accidentally found her elder brother's notebook. she has implements things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. so, the problem statement is as follows.
Let's assume that we are given a connected weighted undirected graphG? =? (V,?E) (HereVIs the set of vertices,EIs the set of edges). The shortest-path tree from vertexUIs such graphG1? =? (V,?E1) that is a tree with the set of edgesE1 that is the subset of the set of edges of the initial graphE, And the lengths of the shortest paths fromUTo any vertexGAndG1 are the same.
You are given a connected weighted undirected graphGAnd vertexU. Your task is to find the shortest-path tree of the given graph from vertexU, The total weight of whose edges is minimum possible.
Input
The first line contains two numbers,NAndM(1? ≤?N? ≤? 3 · 105, 0? ≤?M? ≤? 3. 105)-the number of vertices and edges of the graph, respectively.
NextMLines contain three integers each, representing an edge-UI,?VI,?WI-The numbers of vertices connected by an edge and the weight of the edge (UI? ?VI,? 1? ≤?WI? ≤? 109). It is guaranteed that graph is connected and that there is no more than one edge between any pair of vertices.
The last line of the input contains integerU(1? ≤?U? ≤?N)-The number of the start vertex.
Output
In the first line print the minimum total weight of the edges of the tree.
In the next line print the indices of the edges that are stored in the tree, separated by spaces. the edges are numbered starting from 1 in the order they follow in the input. you may print the numbers of the edges in any order.
If there are multiple answers, print any of them.
Sample test (s) input
3 31 2 12 3 11 3 23
Output
21 2
Input
4 41 2 12 3 13 4 14 1 24
Output
42 3 4
Note
In the first sample there are two possible shortest path trees:
- With edges 1? -? 3 and 2? -? 3 (the total weight is 3 );
- With edges 1? -? 2 and 2? -? 3 (the total weight is 2 );
And, for example, a tree with edges 1? -? 2 and 1? -? 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 in this tree equals 3, and in the original graph it is 1.
Greedy: Add as small an edge as possible when Dijkstra adds an edge
/*************************************** * ******** Author: CKbossCreated Time: Wednesday, June 16, May 20, 2015 File Name: e2.cpp *************************************** * *********/# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; typedef long int LL; typedef pair
PII; const LL maxn = 300300; const ll inf = 0x3f3f3f3f3f3f3f; LL n, m, S; struct Edge {LL to, next, len, id ;} edge [maxn * 2]; LL Adj [maxn], Size; void init () {memset (Adj,-1, sizeof (Adj); Size = 0 ;} void Add_Edge (LL u, LL v, LL len, LL id) {edge [Size]. to = v; edge [Size]. len = len; edge [Size]. id = id; edge [Size]. next = Adj [u]; Adj [u] = Size ++;} LL dist [maxn]; bool vis [maxn]; LL ex [maxn]; LL pre [maxn]; void dijkstra () {memset (dist, 63, sizeof (dist); memset (ex, 63, sizeof (ex )); dist [S] = 0; ex [S] = 0; priority_queue
Q; //-distance, click q. push (make_pair (0, S); while (! Q. empty () {pII tp = q. top (); q. pop (); LL u = tp. second; if (vis [u] = true) continue; vis [u] = true; for (LL I = Adj [u]; ~ I; I = edge [I]. next) {LL v = edge [I]. to; LL len = edge [I]. len; LL id = edge [I]. id; if (vis [v]) continue; if (dist [v]> dist [u] + len) {dist [v] = dist [u] + len; pre [v] = id; ex [v] = len; q. push (make_pair (-dist [v], v);} else if (dist [v] = dist [u] + len & ex [v]> len) {pre [v] = id; ex [v] = len ;}} LL all = 0; memset (vis, 0, sizeof (vis); vector
Ve; for (LL I = 1; I <= n; I ++) {if (ex [I]! = INF) all + = ex [I]; if (I! = S) ve. push_back (pre [I]);} printf ("% I64d \ n", all); sort (ve. begin (), ve. end (); unique (ve. begin (), ve. end (); for (int I = 0, sz = ve. size (); I