zoukankan      html  css  js  c++  java
  • 牛客小白月赛17

    题目链接:https://ac.nowcoder.com/acm/contest/1085#question


    A:

    题意:一个数轴,再给定m个区间,问没被区间覆盖的最大连续区间是多大

    idea:按左端点为第一关键字排序,然后区间合并,从左到右再遍历一遍即可

    1 void
    View Code

    B:

    题意:询问每个点周围有多少炸弹

    idea:暴力遍历

     1 #include <bits/stdc++.h>
     2  
     3 using namespace std;
     4 int n, m, cnt[1010][1010];
     5 char a[1010][1010];
     6  
     7 int main()
     8 {
     9     cin >> n >> m;
    10     for (int i = 0; i < n; i ++ )
    11         for (int j = 0; j < m; j ++ )
    12              cin >> a[i][j];
    13               
    14     for (int i = 0; i < n; i ++ )
    15     {
    16         for (int j = 0; j < m; j ++ )
    17         {
    18             int ans = 0;
    19             if (a[i][j] == '.')
    20             {
    21                 if (a[i - 1][j] == '*') ans ++ ;
    22                 if (a[i - 1][j - 1] == '*') ans ++ ;
    23                 if (a[i - 1][j + 1] == '*') ans ++ ;
    24                 if (a[i][j - 1] == '*') ans ++ ;
    25                 if (a[i][j + 1] == '*') ans ++ ;
    26                 if (a[i + 1][j + 1] == '*') ans ++ ;
    27                 if (a[i + 1][j - 1] == '*') ans ++ ;
    28                 if (a[i + 1][j] == '*') ans ++ ;
    29             }
    30             cnt[i][j] = ans;
    31         }
    32     }  
    33      
    34     for (int i = 0; i < n; i ++ )
    35     {
    36         for (int j = 0; j < m; j ++ )
    37         {
    38             if (a[i][j] == '*')  cout << "*";
    39             else  cout << cnt[i][j];
    40         }
    41         cout << endl;
    42     }
    43     return 0;
    44 }
    View Code

    C:

    题意:给出一个数组,计算出现次数为奇数次的数的异或和

    idea:根据异或和的性质,把所有数全部异或计算即可

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4  
     5 using namespace std;
     6 int n;
     7  
     8 int main()
     9 {
    10     scanf("%d",&n);
    11     int ans = 0;
    12     for (int i = 0; i < n; i ++ )
    13     {
    14         int x;
    15         scanf("%d",&x);
    16         ans ^= x;
    17     }
    18     printf("%d",ans);
    19     return 0;
    20 }
    View Code

    D:

    题意:解密,给出一段密文,输出解密后的字符串

    idea:Ck1x+k2(mod  26),因为总共就26个字母,所以可以先打表,预处理出来每个密文对应的明文

     1 #include <bits/stdc++.h>
     2  
     3 using namespace std;
     4 int cnt[30];
     5  
     6 int main()
     7 {
     8     int k1, k2;
     9     cin >> k1 >> k2;
    10     for (int i = 0; i <26; i ++ )
    11     {
    12         for (int j = 0; j < 26; j ++ )
    13         {
    14             if ((k1 * j + k2) % 26 == i)
    15             {
    16                 cnt[i] = j;
    17                 break;
    18             }
    19         }
    20     }
    21     string s;
    22     cin >> s;
    23     int len = s.size();
    24     for (int i = 0; i < len; i ++ )
    25     {
    26         if (s[i] >= 'a' && s[i] <= 'z')
    27         {
    28             int c = s[i] - 'a';
    29             printf("%c",cnt[c] + 'a');
    30         }
    31         else
    32         {
    33             int c = s[i] - 'A';
    34             printf("%c",cnt[c] + 'A');
    35         }
    36     }
    37     return 0;
    38 }
    View Code

    I:

    题意:电梯上升一层需要一秒,问到你这层至少需要多少秒

    idea:签到,直接算就行

     1 #include <iostream>
     2 #include <cstdio>
     3  
     4 using namespace std;
     5 const int MAXN = 1e6 + 10;
     6 int n, k, a[MAXN];
     7  
     8 int main()
     9 {
    10     cin >> n >> k;
    11     for (int i = 0; i < n; i ++ )  scanf("%d",&a[i]);
    12      
    13     int ans = 0;
    14     for (int i = 0; i < n; i ++ )
    15     {
    16         if (a[i] > k && a[i] > ans)  ans = a[i];
    17     }
    18     ans = (ans - k) * 2 + k - 1;
    19     cout << ans << endl;
    20     return 0;
    21 }
    View Code

    PS:四题半,挺糟糕的,下次一定要五题,就这样。

  • 相关阅读:
    Python自动化开发学习的第十一周----WEB基础(html+css)
    oracle中的rownum详解
    oracle常用函数
    oracle使用exp命令无法导出空表解决方法
    plsql批量执行多个sql脚本示例
    oracle删除表空间和用户
    oracle系统相关表
    SpringMVC常用注解
    RequestMapping注解
    利用plsql只导出某些表,或者视图,或者触发器等
  • 原文地址:https://www.cnblogs.com/chuyds/p/11527603.html
Copyright © 2011-2022 走看看