• 牛客练习赛17 ABD


    A 长方体

    题目描述

    给出共享长方体一个顶点的三个面的面积,求它十二条边的边长和。

    输入描述:

    一行三个整数a, b, c表示面积(1 <= a, b, c <= 10000)。

    输出描述:

    一行一个整数表示边长和。
    示例1

    输入

    1 1 1

    输出

    12
    示例2

    输入

    4 6 6

    输出

    28

    节约时间就直接暴力做了。

     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
    ",4*(x+y+z));
    12         }
    13     }
    14 
    15     return 0;
    16 }

    B 好位置

    题目描述

    给出两个串s和x
    定义s中的某一位i为好的位置,当且仅当存在s的子序列 满足y=x且存在j使得i=kj成立。
    问s中是否所有的位置都是好的位置。

    输入描述:

    一行两个字符串s,x,这两个串均由小写字母构成。
    1 <= |s|, |x| <= 200000

    输出描述:

    Yes表示是。
    No表示不是。
    示例1

    输入

    abab
    ab

    输出

    Yes
    示例2

    输入

    abacaba
    aba

    输出

    No
    示例3

    输入

    abc
    ba

    输出

    No

    KMP问题,在s中的子串只要出现了x串,那么那些位置都是好位置。只要求下是否存在没在子串里的就行。
     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
    ",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
    ");
    39     }
    40     printf("Yes
    ");
    41     return 0;
    42 }

    D 经纬度

    题目描述

    给定地球的两个经纬度坐标,问这两个点的球面距离和直线距离的差。假设地球为球体,半径为6371009米。

    输入描述:

    第一行一个整数T表示数据组数。
    接下来n行,每行四个数lat1, lng1, lat2, lng2分别表示两个点的经纬度。
    正数表示北纬和东经。
    负数表示南纬和西经。
    数据保证合法。

    输出描述:

    n行表示答案。
    答案保留到米。
    示例1

    输入

    1
    43.466667 -80.516667 30.058056 31.228889

    输出

    802333

    有个坑,输入的是纬经度,不是经纬度。坑了好久。
     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
    ",len1,len2);
    25         // printf("%.lf %.lf %.lf %.lf %.lf %.lf
    ",x1,y1,z1,x2,y2,z2 );
    26         printf("%lld
    ",(long long)(len2 - len1 + 0.5));
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    c#,简单的冒泡排序
    uwp,c#,listView与gridView列表控件进阶
    使用gensim之KeyedVectors操作词向量模型
    python时间戳
    通过Python查找目录下含有指定字符串的所有文件
    聚类之DBSCAN
    使用pyhanlp进行分词
    将Python对象和变量保存在本地
    通过selenium进行博客备份
    matplotlib颜色代码
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8992622.html
Copyright © 2020-2023  润新知