[Nowcoder] 2020 cattle off winter training camp base algorithm 5

20,200,213 fifth

Progress (7/10) Unfinished: -

 

A, template

1 link

https://ac.nowcoder.com/acm/contest/3006/A

2, faces questions

Beef, beef cattle and cola can make up a team to participate in ACM Series tournament, they played a team called elegant ~ "Cow Troopers"

Taurus team in the absence of competition, will put all kinds of board cabinet password, to prevent lost. This whole team is headed by a password. Beef cattle and which can have two keys, each of which has a merely constituted by the capital letter string. Coke holds the cow decryption method. One day, you use a bottle of Coke Cola bribery cattle, it has been a way to decrypt.

Bovine Coke will attempt to use one key into another by as few steps as following:

  • Wherein any of the letter is replaced with another
  • To delete the last letter
  • Add a letter in the tail

Digital conversion step is to get the final password.

One day, you and your team dinner with them, you fill them with cola poured from the mouth of beef and cattle can set out two keys. You want to take them to wake up and get a copy of the template before putting them back. You can quickly calculate your password?

3, thinking

Attendance problems. Thinking a little.

4, the code

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3  
 4 #define MAXN 100005
 5  
 6 int n, m, ans;
 7 char s1[MAXN], s2[MAXN];
 8  
 9 int main() {
10     cin >> n >> m >> s1 >> s2;
11     for (int i = 0; i < min(n, m); i++)
12         ans += s1[i] != s2[i];
13     cout << ans + abs(n - m);
14     return 0;
15 }

 

B, ground beef clan match

1 link

https://ac.nowcoder.com/acm/contest/3006/B

2, faces questions

Because beef clan often away matches, so a lot of the country to establish training bases, each base has a coordinate (the X-, the y-) .

This weekend, Taurus team have to go out of the game, each match point game in x -axis. Taurus team for the convenience of the game, looking for a training base to reach the maximum and minimum distances as a place to race.
The problem for the Taurus team too simple, it is up to you, you to help him count ~

3, thinking

We set the current maximum distance r, at each training base for all points in the center of radius of the intersection point between the chord of the circle r, the x-axis to circle the training base distance <= r. To seek out all the strings, all the strings are all coincident points to the part of all the training base distances are <= r. All strings exactly overlapping portion (i.e. two or more of the cross string just a certain point), r is the minimum value at this time.

 

As shown, p1 into three strings (where the x-axis and tangent to the point C) exactly coincides with the point A, then r = 2, i.e. the answer. p2 point C in the x-axis no intersection, it is clear that simply can not get from point C, the answer will be greater; p3 not coincide, the answer will be smaller.

According to this idea, half of the answer can be resolved.

Solution to a problem is the rule of thirds, but I do not remember.

 

4, the code

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define MAXN 100005
 5 #define INF 0x3f3f3f3f
 6 
 7 int n;
 8 double x[MAXN], y[MAXN];
 9 
10 int main() {
11     cin >> n;
12     for (int i = 1; i <= n; i++) 
13         cin >> x[i] >> y[i], y[i] = abs(y[i]);
14     double l = 0, r = 100000000;
15     while (r - l > 1e-5) {
16         double m = (l + r) / 2, mi = INF, mx = -INF, f = 0;
17         for (int i = 1; i <= n; i++) {
18             if (y[i] > m) {
19                 f = 1;
20                 break;
21             }
22             double o = sqrt(m * m - y[i] * y[i]);
23             mi = min(mi, x[i] + o), mx = max(mx, x[i] - o);
24         }
25         if (mi >= mx && !f) r = m;
26         else l = m;
27     } 
28     cout << l;
29     return 0;
30 }    

 

D, and beef cattle sister appointments

1 link

https://ac.nowcoder.com/acm/contest/3006/D

2, faces questions

Beef after a hard day at the races, cattle sister to go to play, in fact, is also the day of the race cattle sister. In order to find the girl of his cattle to his game from the ground to her game as soon as possible.

Remember, the game is only in the x -axis, the coordinates satisfy the two Y = 0 . Cow addition to a movement speed of an arbitrary time unit distance / unit time, it also can take a unit time flash. Each time the flash, if the current coordinates are X = K , he will flash to k ^ (1/3) position.

Please help him calculate how much time the minimum required, he can find cow girl ~

3, thinking

Two movements of ways: a direct walked over, took equivalent to the distance; the last one kind of jump with a jump knife, took 1, we have to consider is the dagger would be more worthwhile than walk under what circumstances, and go the last time consuming greater than 1.

According to the meaning of problems, jump knife can only become self-cube root, that is, if it is positive only smaller; if it is negative only larger. We position where a and b into six cases discussed in terms of the sign and magnitude relationships:

① a < b; a > 0, b > 0.

② a > b; a < 0, b < 0.

In both cases the easiest, because the dagger is disabled, so ans = abs (a - b).

③ a < b; a < 0, b > 0.

④ a > b; a > 0, b < 0.

Both cases may be divided into two parts from the process, a first portion close to the origin, a positive number smaller negative large, it is necessary to consider a jump knife; second portion away from the origin, to go directly in the past.

⑤ a < b; a < 0, b < 0.

⑥ a > b; a > 0, b > 0.

In both cases, due to the same side, with a jump knife can not be too greedy, because you might skip the body, this is the time to jump in front of her decision to walk past, or skip past behind her again. Is similar to the bus / subway, if you're going down between stations, you need to consider is to sit down at a stand still after a stand.

Complete analysis of six kinds of situation, with a dagger or judgment is actually not difficult to walk, and do not do too much analysis.

This problem fucked me once, but now I know pow (a, b) in a can not be negative, because the compiler does not prejudge the value of b, directly across the board allowed a <0 a. So for this question can be used -pow (-a, b) to solve this problem.

Then fwl offers a cbrt function, too upset, really heard, check are finding out Orz ...

 

4, the code

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int t;
 5 
 6 int main() {
 7     cin >> t;
 8     for (int i = 1; i <= t; i++) {
 9         double ans = 0, a, b;
10         cin >> a >> b;
11         if (a < b) {
12             if (a <= 0 && b >= 0) {
13                 while (a + pow(-a, 1 / 3.0) < -1.0) a = -pow(-a, 1 / 3.0), ans += 1;
14                 ans += b - a;
15             }
16             else if (a >= 0 && b >= 0) ans = b - a;
17             else if (a < 0 && b < 0) {
18                 while (abs(-pow(-a, 1 / 3.0) - b) + 1 < abs(a - b)) a = -pow(-a, 1 / 3.0), ans += 1;
19                 ans += abs(a - b);
20             }
21         }
22         else if (a > b) {
23             if (a >= 0 && b <= 0) {
24                 while (a - pow(a, 1 / 3.0) > 1.0) a = pow(a, 1 / 3.0), ans += 1;
25                 ans += a - b;
26             }
27             else if (a <= 0 && b <= 0) ans = a - b;
28             else if (a > 0 && b > 0) {
29                 while (abs(pow(a, 1 / 3.0) - b) + 1 < abs(a - b)) a = pow(a, 1 / 3.0), ans += 1;
30                 ans += abs(a - b);
31             }
32         }
33         else ans = 0;
34         printf("%.9lf\n", ans);
35     }
36     return 0;
37 }

 

Guess you like

Origin www.cnblogs.com/jinkun113/p/12305997.html