• Codeforces Round #566 (div. 2)


    题目链接:https://codeforces.com/contest/1182


    A:

    一眼题。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int n;
    21 
    22 int main() {
    23     cin >> n;
    24     if (n & 1) return cout << 0, 0;
    25     cout << pow((ll)2, (ll)n / 2) << endl;
    26     return 0;
    27 }
    View Code

    B:

    找到十字的中心点,然后往四周dfs,统计星号数量即可。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 510, px[4] = {1, -1, 0, 0}, py[4] = {0, 0, 1, -1};
    21 int h, w, cnt = 0, n = 0, m = 0, flag = 1, cnt2 = 0;
    22 char s[maxn][maxn];
    23 
    24 void dfs(int x, int y, int i) {
    25     if (s[x][y] == '*' && x >= 1 && x <= h && y >= 1 && y <= w) {
    26         x += px[i]; y += py[i]; cnt2++; dfs(x, y, i);
    27     }
    28 }
    29 
    30 int main() {
    31     scanf("%d%d", &h, &w);
    32     rep1(i, 1, h) scanf("%s", s[i] + 1);
    33     rep1(i, 1, h) {
    34         rep1(j, 1, w)
    35         if (s[i][j] == '*') cnt++;
    36     }
    37     if (h < 3 || w < 3) return puts("NO"), 0;
    38     rep1(i, 2, h - 1) {
    39         rep1(j, 2, w - 1) {
    40             if (s[i][j] == '*' && s[i - 1][j] == '*' && s[i][j - 1] == '*' && s[i + 1][j] == '*' && s[i][j + 1] == '*')
    41                 if (!n) n = i, m = j;
    42                 else flag = 0;
    43         }
    44     }
    45     if (!flag || n == 0) return puts("NO"), 0;
    46     rep0(i, 0, 4) dfs(n + px[i], m + py[i], i);
    47     cnt2++;
    48     if (cnt2 == cnt) puts("YES"); else puts("NO");
    49     return 0;
    50 }
    View Code

    C:

    数据结构大模拟。交了个学费:string.c_str()只能用在printf,不能用在scanf,因为返回的是一个const char*。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 1e5 + 10;
    21 int n;
    22 string s[maxn];
    23 map<pair<int, int>, vector<int> >m;
    24 vector<pair<int, int> >fir, sec;
    25 vector<pair<pair<int, char>, int> >in;
    26 
    27 int isVowel(char c) {
    28     if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return 1;
    29     return 0;
    30 }
    31 
    32 int main() {
    33     scanf("%d", &n);
    34     rep0(i, 0, n) {
    35         cin >> s[i];
    36         pair<pair<int, char>, int> tmp = mp(mp(0, 'z'), i);
    37         rep0(j, 0, s[i].size()) {
    38             if (isVowel(s[i][j])) {
    39                 tmp.first.first++;
    40                 tmp.first.second = s[i][j];
    41             }
    42         }
    43         m[tmp.first].pb(i);
    44     }
    45     for (auto it : m) {
    46         vector<int>r = it.second;
    47         for (int j = 0; j < r.size(); j += 2)
    48             if (j + 1 < r.size())
    49                 sec.pb(mp(r[j], r[j + 1]));
    50             else
    51                 in.pb(mp(it.first, r[j]));
    52     }
    53     sort(in.begin(), in.end());
    54     rep0(i, 0, (int)in.size()) {
    55         pair<pair<int, char>, int>tmp = in[i];
    56         if (i + 1 < in.size()) {
    57             if (in[i + 1].first.first == tmp.first.first) {
    58                 fir.pb(mp(in[i + 1].second, tmp.second));
    59                 i++;
    60             } else continue;
    61         } else break;
    62     }
    63     int r = 0;
    64     rep1(i, 1, sec.size()) {
    65         int rem = sec.size() - i + fir.size();
    66         if (i <= rem) r = i;
    67     }
    68     rep0(i, r, sec.size()) fir.pb(sec[i]);
    69     printf("%d
    ", r);
    70     rep0(i, 0, r) {
    71         printf("%s %s
    ", s[fir[i].first].c_str(), s[sec[i].first].c_str());
    72         printf("%s %s
    ", s[fir[i].second].c_str(), s[sec[i].second].c_str());
    73     }
    74     return 0;
    75 }
    View Code

    D:

    不太会做的图论题。

    E:

    题目清晰易懂,一看就是个矩阵快速幂。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const ll mod = 1e9 + 7, MOD = 1000000006;
    21 const int maxn = 3;
    22 
    23 struct Matrix {
    24     ll mat[8][8];
    25 };
    26 
    27 ll n, f1, f2, f3, c, ans = 1;
    28 Matrix ma;
    29 
    30 // matrix multiply
    31 Matrix mat_mul(Matrix a, Matrix b) {
    32     Matrix ret;
    33     for ( int i = 1; i <= maxn; i++ )
    34         for ( int j = 1; j <= maxn; j++ )
    35             ret.mat[i][j] = 0;
    36     for ( int i = 1; i <= maxn; i++ )
    37         for ( int j = 1; j <= maxn; j++ )
    38             for ( int k = 1; k <= maxn; k++ )
    39                 ret.mat[i][j] = ( ret.mat[i][j] + a.mat[i][k] * b.mat[k][j] % MOD ) % MOD;
    40     return ret;
    41 }
    42 
    43 // matrix quick pow
    44 Matrix mat_pow(Matrix a, ll b) {
    45     Matrix ret;
    46     memset(ret.mat, 0, sizeof(ret.mat));
    47     for (int i = 1; i <= maxn; i++)
    48         ret.mat[i][i] = 1;
    49     while (b > 0) {
    50         if (b & 1)
    51             ret = mat_mul(ret, a);
    52         a = mat_mul(a, a);
    53         b >>= 1;
    54     }
    55     return ret;
    56 }
    57 
    58 // quick pow
    59 ll pow_mod(ll x, ll b) {
    60     ll ret = 1;
    61     while (b > 0) {
    62         if (b & 1)
    63             ret = ret * x % mod;
    64         x = x * x % mod;
    65         b >>= 1;
    66     }
    67     return ret;
    68 }
    69 
    70 int main() {
    71     cin >> n >> f1 >> f2 >> f3 >> c;
    72     ll inv = pow_mod(c, mod - 2);
    73     memset(ma.mat, 0, sizeof(ma.mat));
    74     ma.mat[1][1] = ma.mat[1][2] = ma.mat[1][3] = ma.mat[2][1] = ma.mat[3][2] = 1;
    75     ma = mat_pow(ma, n - 3);
    76     f1 = f1 * c % mod;
    77     f2 = f2 * c % mod * c % mod;
    78     f3 = f3 * c % mod * c % mod * c % mod;
    79     ans = pow_mod(f1, ma.mat[1][3]) * pow_mod(f2, ma.mat[1][2]) % mod * pow_mod(f3, ma.mat[1][1]) % mod;
    80     ans = ans * pow_mod(inv, n) % mod;
    81     cout << ans << endl;
    82     return 0;
    83 }
    View Code

    F:

    溜了溜了。

  • 相关阅读:
    python实现单链表及常用方法->判空|长度|头尾及指定插入|删除|搜索|反转
    k8s v1.21.9集群安装带认证的elk 6.8.18
    docker安装Elasticsearch6.8集群并设置密码
    kubernetes v1.20.9部署keepalived-vip实现高可用pod访问
    rsync远程同步工具的使用-实现跳板机与内网数据传输
    旧金山大学 大卫 算法演示
    IO多路复用之select、poll、epoll详解-转载
    docker容器中使用systemctl命令 set-hostname
    win7 安装ss
    常用相似度语料
  • 原文地址:https://www.cnblogs.com/JHSeng/p/11185841.html
Copyright © 2020-2023  润新知