• codeforces educational round 76


    A. Two Rival Students

    B. Magic Stick

    C. Dominated Subarray

    Description

    给出一个序列串,求满足下述要求的最短子串序列。

    - 子串序列内出现最多的元素有且仅有一种。

    Solution

    贪心思路:原序列相等的两个值最近的间距。

    最开始想偏了,写了个滑窗,tle。

    D. Yet Another Monster Killing Problem

    Description

    Solution

    思路来自codeforces论讨赛后讨论

    对英雄而言,求每种耐力对应最大的攻击力,并求前缀最大值。

    那么有判断条件

     

     pre[i]代表耐力大于等于i的最大攻击值,c

    F. Make Them Similar

    Description

    给定一个序列a,求一个数x使得a中每一个数与x异或后的二进制中1的个数相同。

    Solution

    看了题解发现了一种记录两个数组对应索引项之和是否相等的骚操作。

    如对于$a={1,2,3,4,7},b={7,6,5,4,1}$

    求a中数据全部减去a[0]后的值$a^1={0,1,2,3,6}$

    求b中数据全部被b[0]减去后的值$b^1={0,1,2,3,6}$

    发现$a^1=b^1$,那么就可以知道a+b中元素都相等。

    回到本题,枚举每一个$x in [0,2^{30}-1]$显然复杂度炸裂,那么可以采用meet in the middle的方法。

    先枚举高位再枚举低位,反过来亦可。

    利用map对类差分序列进行记录。

      1 #include <algorithm>
      2 #include <cctype>
      3 #include <cmath>
      4 #include <cstdio>
      5 #include <cstdlib>
      6 #include <cstring>
      7 #include <iostream>
      8 #include <map>
      9 #include <numeric>
     10 #include <queue>
     11 #include <set>
     12 #include <stack>
     13 #if __cplusplus >= 201103L
     14 #include <unordered_map>
     15 #include <unordered_set>
     16 #endif
     17 #include <vector>
     18 #define lson rt << 1, l, mid
     19 #define rson rt << 1 | 1, mid + 1, r
     20 #define LONG_LONG_MAX 9223372036854775807LL
     21 #define pblank putchar(' ')
     22 #define ll LL
     23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
     24 using namespace std;
     25 typedef long long ll;
     26 typedef long double ld;
     27 typedef unsigned long long ull;
     28 typedef pair<int, int> P;
     29 int n, m, k;
     30 const int maxn = 1e5 + 10;
     31 template <class T>
     32 inline T read()
     33 {
     34     int f = 1;
     35     T ret = 0;
     36     char ch = getchar();
     37     while (!isdigit(ch))
     38     {
     39         if (ch == '-')
     40             f = -1;
     41         ch = getchar();
     42     }
     43     while (isdigit(ch))
     44     {
     45         ret = (ret << 1) + (ret << 3) + ch - '0';
     46         ch = getchar();
     47     }
     48     ret *= f;
     49     return ret;
     50 }
     51 template <class T>
     52 inline void write(T n)
     53 {
     54     if (n < 0)
     55     {
     56         putchar('-');
     57         n = -n;
     58     }
     59     if (n >= 10)
     60     {
     61         write(n / 10);
     62     }
     63     putchar(n % 10 + '0');
     64 }
     65 template <class T>
     66 inline void writeln(const T &n)
     67 {
     68     write(n);
     69     puts("");
     70 }
     71 template <typename T>
     72 void _write(const T &t)
     73 {
     74     write(t);
     75 }
     76 template <typename T, typename... Args>
     77 void _write(const T &t, Args... args)
     78 {
     79     write(t), pblank;
     80     _write(args...);
     81 }
     82 template <typename T, typename... Args>
     83 inline void write_line(const T &t, const Args &... data)
     84 {
     85     _write(t, data...);
     86 }
     87 const int bit = 15;
     88 map<vector<int>, int> mp;
     89 int a[maxn];
     90 int main(int argc, char const *argv[])
     91 {
     92 #ifndef ONLINE_JUDGE
     93     freopen("in.txt", "r", stdin);
     94     // freopen("out.txt", "w", stdout);
     95 #endif
     96     n = read<int>();
     97     for (int i = 0; i < n; i++)
     98         a[i] = read<int>();
     99     mp.clear();
    100     int tmp = 1 << bit;
    101     for (int i = 0; i < tmp; i++)
    102     {
    103         vector<int> cur(n);
    104         for (int j = 0; j < n; j++)
    105             cur[j] = __builtin_popcount((a[j] & (tmp - 1)) ^ i);
    106         for (int j = n - 1; j >= 0; j--)
    107             cur[j] -= cur[0];
    108         mp[cur] = i;
    109     }
    110     int f = 0;
    111     for (int i = 0; i < tmp && !f; i++)
    112     {
    113         vector<int> cur(n);
    114         for (int j = 0; j < n; j++)
    115             cur[j] = __builtin_popcount((a[j] >> bit) ^ i);
    116         for (int j = n - 1; j >= 0; j--)
    117             cur[j] = cur[0] - cur[j];
    118         if (mp.count(cur))
    119         {
    120             f = 1;
    121             writeln((i << bit) | mp[cur]);
    122         }
    123     }
    124     if (!f)
    125         puts("-1");
    126     return 0;
    127 }
    View Code
  • 相关阅读:
    Wannafly挑战赛13 C:zzf的好矩阵(思维)
    Wannafly挑战赛13 B:Jxc军训(逆元)
    TZOJ 1221 Tempter of the Bone(回溯+剪枝)
    AtCoder Regular Contest 092 C
    TZOJ 3030 Courses(二分图匹配)
    TOJ 2778 数据结构练习题――分油问题(广搜和哈希)
    PAT L3-001 凑零钱(01背包dp记录路径)
    [HNOI2009]通往城堡之路
    [HNOI2006]潘多拉的宝盒
    [bzoj4361]isn
  • 原文地址:https://www.cnblogs.com/mooleetzi/p/11859365.html
Copyright © 2020-2023  润新知