Niu Ke practice 17

A cuboid

Topic description

Given the area of ​​the three faces that share a vertex of the cuboid, find the sum of the lengths of its twelve sides.

Enter description:

A row of three integers a, b, c represents the area (1 <= a, b, c <= 10000).

Output description:

One integer per line represents the sum of the side lengths.
Example 1

enter

1 1 1

output

12
Example 2

enter

4 6 6

output

28 

Save time and do it directly with violence.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     int a, b,c;
 6     cin >> a >> b >> c;
 7     for(int x = 1; x <= a; x ++) {
 8         int y = a/x;
 9         int z = c/x;
10         if(x*y == a && y*z == b && x*z == c) {
11             return 0*printf("%d\n",4*(x+y+z));
12         }
13     }
14 
15     return 0;
16 }

B good location

Topic description

Given two strings s and x
, define a bit i in s as a good position if and only if there exists a subsequence of s that satisfies y=x and there exists j such that i=k j holds.
Ask if all the positions in s are good positions.

Enter description:

A line contains two strings s, x, both of which consist of lowercase letters. 
1 <= |s|, |x| <= 200000

Output description:

Yes means yes. 
No means not.
Example 1

enter

abab
away

output

Yes
Example 2

enter

abacaba
aba

output

No
Example 3

enter

abc
ba

output

No 

KMP problem, as long as the substring in s has the x string, then those positions are good positions. Just ask if there is anything that is not in the substring.
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N = 200010;
 4 char str[N], str1[N];
 5 int nex[N];
 6 int vis[N];
 7 void init(){
 8     int j = nex[0] = -1, i = 0;
 9     int len = strlen(str);
10     while(i < len){
11         if(j == -1 || str[i] == str[j]){
12             nex[++i] = ++j;
13         }else j = nex[j];
14     }
15 }
16 void KMP(){
17     int i  = 0, j = 0, sum = 0;
18     int len = strlen(str), len1 = strlen(str1);
19     while(j < len1){
20         if(i == -1 || str[i] == str1[j]){
21             i++;j++;
22         }else i = nex[i];
23         if(i == len) {
24             // printf("j:%d %d %d\n",j,j+1,j-len+1);
25             vis[j+1]--;
26             vis[j-len+1]++;
27         }
28     }
29 }
30 int main() {
31     cin >> str1 >> str;
32     init();
33     int len1 = strlen(str1);
34     KMP();
35     int ans = 0;
36     for(int i = 1; i <= len1; i ++) {
37         ans += vis[i];
38         if(ans == 0) return 0*printf("No\n");
39     }
40     printf("Yes\n");
41     return 0;
42 }

D latitude and longitude

Topic description

Given two latitude and longitude coordinates of the earth, ask the difference between the spherical distance and the linear distance of these two points. Suppose the earth is a sphere with a radius of 6371009 meters.

Enter description:

An integer T in the first line represents the number of data groups. 
The next n lines, each line of four numbers lat1, lng1, lat2, lng2 respectively represent the latitude and longitude of the two points.
Positive numbers indicate north latitude and east longitude.
Negative numbers indicate south latitude and west longitude.
Data is guaranteed to be legal.

Output description:

The n lines represent the answer. 
The answer is reserved to meters.
Example 1

enter

1
43.466667 -80.516667 30.058056 31.228889

output

802333 

has a pit, the input is latitude and longitude, not latitude and longitude. Pit for a long time.
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     int t;
 6     cin >> t;
 7     int r = 6371009;
 8     double PI = acos(-1);
 9     while(t--) {
10         double lat1, lng1, lat2, lng2;
11         cin >> lat1 >> lng1 >> lat2 >> lng2;
12         lat1+= 180; lat2+=180;
13         lat1 *= PI/180;lat2 *= PI/180;
14         lng1 *= PI/180;lng2 *= PI/180;
15         double x1, x2, y1, y2, z1, z2;
16         z1 = r * sin(lat1);
17         y1 = r * cos(lat1) * sin(lng1);
18         x1 = r * cos(lat1) * cos(lng1);
19         z2 = r * sin(lat2);
20         y2 = r * cos(lat2) * sin(lng2);
21         x2 = r * cos(lat2) * cos(lng2);
22         double len1 = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
23         double len2 = 2 * r * asin(len1 / (2 * r));
24         //printf("%.lf %lf\n",len1,len2);
25         // printf("%.lf %.lf %.lf %.lf %.lf %.lf\n",x1,y1,z1,x2,y2,z2 );
26         printf("%lld\n",(long long)(len2 - len1 + 0.5));
27     }
28     return 0;
29 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325280893&siteId=291194637