• Codeforces732E Sockets


    首先检测有木有和Computer匹配的Socket,如果有则将其匹配。

    然后将所有没有匹配的Socket连上Adapter,再去检测有木有Computer与Socket匹配。

    重复这个操作31次,所有Socket的power都变成1了,如果再不能匹配就结束程序。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 struct PC
     5 {
     6     int power;
     7     int idx;
     8     friend bool operator< (const PC& a, const PC& b)
     9     {
    10         return a.power < b.power;
    11     }
    12 };
    13 int s[200010];
    14 bool vis[200010];
    15 int a[200010];
    16 int b[200010];
    17 
    18 int main()
    19 {
    20     int n, m;
    21     scanf("%d%d", &n, &m);
    22     multiset<PC> pc;
    23     int p;
    24     for (int i = 1; i <= n; i++)
    25     {
    26         scanf("%d", &p);
    27         pc.insert({p, i});
    28     }
    29     for (int i = 1; i <= m; i++)
    30         scanf("%d", s + i);
    31     int c = 0, u = 0;
    32     for (int i = 0; i < 31; i++)
    33     {
    34         for (int j = 1; j <= m; j++)
    35         {
    36             if (!vis[j])
    37             {
    38                 multiset<PC>::iterator it = pc.find({s[j], 0});
    39                 if (it != pc.end())
    40                 {
    41                     b[it->idx] = j;
    42                     vis[j] = true;
    43                     pc.erase(it);
    44                     c++;
    45                     u += a[j];
    46                 }
    47             }
    48         }
    49         for (int j = 1; j <= m; j++)
    50             if (!vis[j])
    51                 a[j]++, s[j] = (s[j] + 1) / 2;
    52     }
    53     printf("%d %d
    ", c, u);
    54     for (int i = 1; i <= m; i++)
    55         printf("%d ", vis[i] ? a[i] : 0);
    56     puts("");
    57     for (int i = 1; i <= n; i++)
    58         printf("%d ", b[i]);
    59     return 0;
    60 }
  • 相关阅读:
    MySQL数据表类型 = 存储引擎类型
    删除链表节点
    链表逆序(反转)
    腾讯2012笔试题
    MysqL数据表类型
    进程间的通信方式
    网络套接字编程学习笔记一
    HTTP报头
    C语言排序算法
    交换排序经典的冒泡排序算法总结
  • 原文地址:https://www.cnblogs.com/iRedBean/p/5975480.html
Copyright © 2020-2023  润新知