20181005 Improve Testing

Source: Internet
Author: User

T1: Factorial
Fact.cpp
"Problem description"
There are n positive integers a[i], set their product to p, you can multiply p by a positive integer q so that p*q is just
The factorial of the integer m, which is the minimum value of M.
Input
A total of two lines.
The first line is a positive integer n.
Second row n positive integers a[i].
Output
Total line
A positive integer m.
"Input Sample"
1
6
"Output Example"
3

Sample explanation:
When P=6,q=1, p*q=3!

"Data scope and conventions"
For 10% of data, n<=10
For 30% of data, n<=1000
For 100% of data, n<=100000,a[i]<=100000

"Wrong Solution"

First, the conjecture is related to the maximum value, but the sample is not.

And then started fooling around, breaking the product of two not-appearing numbers from big to small.

After a sample ...

Wait a minute? Seems to have the biggest repetition?

And then I was so blind.

Wa1+tle9

During the thought of two points, but do not know how to check, simply give up

"Positive Solution"

Two points

Because it is factorial, x! a factor a appears in the number of times

\ (\sum _{i=1}^{\infty} [\frac{x}{a^{i}}]\)

Decompose the number of readings, and then you can check the spicy

#include <iostream> #include <cstdio> #include <cctype> #define MAXN 100005#define MAX 100000#define    int long longusing namespace std;int np[maxn];int p[maxn],t[maxn],tot,pr[maxn];inline int read () {int ans=0,f=1;    Char C=getchar ();        while (!isdigit (c)) {if (c== '-') f=-1;    C=getchar ();    } while (IsDigit (c)) ans= (ans<<3) + (ans<<1) + (c^48), C=getchar (); return F*ans;}    void write (int x) {if (x<0) Putchar ('-'), x=-x;        if (x<10) {Putchar (x^48);    Return    } write (X/10); Putchar ((x%10) ^48);}    void Getprime () {np[1]=1;            for (int i=2;i<=max;i++) {if (!np[i]) {p[++tot]=i;                    Pr[i]=tot;            } for (int j=1;j<=tot&&i*p[j]<=max;j++) {np[i*p[j]]=1;        if (i%p[j]==0) break;        }}}void depart (int x) {if (pr[x]) {t[pr[x]]++;    Return    }int tx=x;            for (int i=2;i<=tx;i++) while (tx%i==0) {tx/=i;        t[pr[i]]++;        }}bool Check (int x) {for (int i=1;i<=tot;i++) {int tx=x;        int sum=0;            while (TX) {tx/=p[i];        SUM+=TX;    } if (Sum<t[i]) return false; } return true;    Main () {freopen ("fact.in", "R", stdin);    Freopen ("Fact.out", "w", stdout);    Getprime ();    int N=read ();    for (int i=1;i<=n;i++) depart (read ());    int l=0,r=1e8;        while (l<r) {int mid= (L+R) >>1;        if (check (mid)) R=mid;    else l=mid+1;    } write (L);  return 0;}

T2: Ascending sequence
(LIS)
"Problem description"
Given an ascending sequence of length m a (1≤a[i]≤n), please find out how many kinds of 1...N permutations, meet
A is one of its LIS.
Input
The first row of two integers n,m.
The next line is an M integer that represents A.
Output
An integer line represents the answer.
"Input Sample 1"
5 3
1 3 4
"Output Example 1"
11
"Input Sample 2"
4 2
3 4
"Output Example 2"
5
"Data scope and conventions"
For the first 30% data, n≤9;
For the first 60% data, n≤12;
For 100% of data, 1≤m≤n≤15.

"Wrong Solution"

Look at the data range and you know it's a mob search.

Found no regularity, Anger wrote a nlogn violence check

Maintain with linked list

No loss of branch

Ac6+tle4

"Positive Solution"

Why can't you just press it?

First recall the Nlogn method:

Define D[i] for the end of the minimum LIS, then two-point insertion to transfer

That is, the last array of Nlogn.

Of course not.

The state s indicates that the number is selected, and S1 indicates which numbers in D appear

To give a vivid image of chestnuts: 2 3 1 4 ...

s={1,1,1,1,0}

d={1,4}

s1={1,0,0,1,0}

Because D is monotonically increasing, so we can use S1 to restore D.

That is, if s1[i] is 1, then I appear in D in the position of 1 of the number of 1~i

The state can then be defined \ (f (s,s1) \)

Then the enumeration is inserted into a number and can be transferred

Specific operation: When I was inserted, there were K-bits in front

S|=i

S1 the K-bit before turning to D, then the back.

If 5 is inserted between 3 and 1

s={1,1,1,1,1}

S1 not change

Boundary: When S is complete,\ (f (s,s1) = (d length is the original sequence length) \)

However, complexity is unacceptable.

Observe that S1 is a subset of S

So it can be represented by a three-notation: 0 means no, 1 means that the S is not in the s1,2, both in S and S1

You can then AC this question

[code to be mended]

Meet
(Meet)
"Problem description"
Brother Hao lives in a tree-shaped city of N-points, every day to walk around. Although the walk is the comparison
Many, but Hao elder brother in this city inside of friend is not many.
One day, when Brother Monkey showed him the style of the big man, brother Hao decided to get some contacts to promote
The ability to go. Mr. Hao is now looking for a friend who intends to be with it (Mr. Hao does not let the eating melons know the sex)
To. Mr. Hao now the spy has a look at the beginning and end of all his journeys, and brother Ho intends to start from the end to the beginning and
Its encounter. But brother Hao is looking for a topic, he would like to know how many times before and this trip is the intersection, this
Like Hao elder brother can have a conversation. This path has a number of intersections with the previous path as Mr. Hao's opportunity to interact.
But Mr. Hao anxious to do with the preparation, so what is the opportunity of the small things to give you.
Input
The first line, a positive integer n, indicates the number of nodes. Next n-1 line, two positive integers per line are u,v representing nodes
There is a connecting edge between U and V. The next line is a positive integer m indicating the number of paths. Then there are m lines, two positive integers per line
The numbers are u,v, respectively, indicating a path between U and V.
Output
Outputs a total of M-lines, one integer per line, and line I represents the opportunity for brother Ho to get on this path.
"Input Sample"
5
1 2
1 3
3 4
3 5
4
4 5
4 2
1 3
1 2
"Output Example"
0
1
2
2
"Data scope and conventions"
For 20% of data n,m≤2000
For another 20% of the data n,m≤50000
For another 10% of the data n,m≤200000 ensure that the tree structure is a chain
For another 50% of the data n,m≤200000

"Wrong Solution"

WOC improve the examination of tree profile? Still can't maintain it?

Cheat points, give up

WA10

"Positive Solution"

One conclusion: There are two paths in the tree that intersect when and only if the LCA of one of the paths is on a different path

Then it translates to:

Single point modification, path check value

Path modification, single point check value

Then directly on the tree chain ... What the? Got a card?

Consider the path can be converted to 4 points to the root path, a similar to the tree prefix and the thing

And then straight up to the tree section

Because it is a single-point check, it has an effect on the root path when and only if it is on its subtree

And then it becomes a subtree of tree-like array to maintain the DFS sequence

[code to be mended]

20181005 Improve Testing

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.