zoukankan      html  css  js  c++  java
  • codeforces #588 ABCD

    A. Dawid and Bags of Candies

    Description

    给出4个数,判断能否分成权值相等的两部分。

    Solution

    排序判断$a[0]+a[3]==a[1]+a[2]||a[0]+a[1]+a[2]==a[3]$

    B. Ania and Minimizing

    Description

    Solution

    贪心+模拟。

    C. Anadi and Domino

    Description

     给出21张骨牌如上,以及一个无向简单图。

    骨牌可以放在边上,使得起点和终点对应骨牌的两侧。

    要求每个点对应的骨牌点数一致,问最多能放多少骨牌。

    Solution

    n的值较小,可以直接搜索。

    最后计算这样染色的贡献,取个最大值。

      1 #include <algorithm>
      2 #include <numeric>
      3 #include <cctype>
      4 #include <cmath>
      5 #include <cstdio>
      6 #include <cstdlib>
      7 #include <cstring>
      8 #include <iostream>
      9 #include <map>
     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 int x[50], y[50];
     88 int col[8], vis[8][8];
     89 int ans;
     90 void dfs(int now){
     91     if (now>n){
     92         int cur = 0;
     93         memset(vis ,0, sizeof vis);
     94         for (int i = 0; i < m;i++){
     95             int ta = col[x[i]], tb = col[y[i]];
     96             if (!vis[ta][tb])
     97                 ++cur, vis[ta][tb] = vis[tb][ta] = 1;
     98         }
     99         ans = max(cur, ans);
    100         return;
    101     }
    102     for (int i = 1; i <= 6;i++)
    103         col[now] = i, dfs(now + 1);
    104 }
    105 int main(int argc, char const *argv[])
    106 {
    107 #ifndef ONLINE_JUDGE
    108     freopen("in.txt","r", stdin);
    109     // freopen("out.txt","w", stdout);
    110 #endif
    111     n = read<int>(), m = read<int>();
    112     for (int i = 0; i < m;i++)
    113         x[i] = read<int>(), y[i] = read<int>();
    114     dfs(1);
    115     writeln(ans);
    116     return 0;
    117 }
    View Code

    D. Marcin and Training Camp

    Description

     给出n个人的技能点$a[i]$,技能权重$b[i]$.

    如果x有的技能y没有,x会看不起y,同样y会的x不会y也会看不起x。

    两个人可以互相看不上。

    要求分出一个小组,该小组满足组内没有一个人看不上其他所有人且技能权重最大。

    Solution

    如果两个人的技能点完全一致,那么显然这两个人不会互相看不上对方,就满足了不会看不上全部人的条件。

    那么我们可以将技能点一致的那些人直接加入优先答案集合,注意优先答案集合和下文答案集合不一样

    然后枚举在优先答案集合之外的其他人x,如果x的技能点是优先答案集合内某个人的技能点子集,那么显然x加入不会看不上其他所有人,加入答案集合计入贡献。

      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 = 1e4 + 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 inline int f(ll x, ll y)
     88 {
     89     while (x && y)
     90     {
     91         int t1 = x % 2, t2 = y % 2;
     92         if (t1 && !t2)
     93             return 1;
     94         x >>= 1, y >>= 1;
     95     }
     96     if (x && !y)
     97         return 1;
     98     return 0;
     99 }
    100 vector<ll> vec;
    101 ll a[maxn], b[maxn];
    102 unordered_map<ll, int> vis1, vis2;
    103 unordered_map<ll, int> mp;
    104 int main(int argc, char const *argv[])
    105 {
    106 #ifndef ONLINE_JUDGE
    107     freopen("in.txt", "r", stdin);
    108     // freopen("out.txt","w", stdout);
    109 #endif
    110 
    111     n = read<int>();
    112     for (int i = 1; i <= n; i++)
    113     {
    114         a[i] = read<ll>();
    115         mp[a[i]]++;
    116         if (mp[a[i]] >= 2 && !vis1[a[i]])
    117             vis1[a[i]] = 1, vec.emplace_back(a[i]);
    118     }
    119     for (int i = 1; i <= n; i++)
    120         b[i] = read<ll>();
    121     ll ans = 0;
    122     int sz = vec.size();
    123     for (int i = 0; i < sz; i++)
    124     {
    125         ll t = vec[i];
    126         for (int j = 1; j <= n; j++)
    127             if (!vis2[j] && (t | a[j]) == t)
    128                 ans += b[j], vis2[j] = 1;
    129     }
    130     writeln(ans);
    131     return 0;
    132 }
    View Code

    E

  • 相关阅读:
    大数据集群实验环境搭建
    ORACLE 自治事物
    UNDO内存结构剖析
    事物深度解析
    UNDO
    SCN
    检查点队列
    WPS Excel启用正则表达式
    Python遍历目录下xlsx文件
    Python 字符串指定位置替换字符
  • 原文地址:https://www.cnblogs.com/mooleetzi/p/11784622.html
Copyright © 2011-2022 走看看