zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    左眼右眼
    Mac 的“任务管理器” —— 活动监视器
    [分享] VIM 常用命令及游戏练级
    iOS 7 如何关闭已打开的应用(App)
    iPhone 如何设置彩信 ?
    JavaScript —— attachEvent 方法的使用
    习惯&感恩
    MySQL 基础 备份和恢复
    Python 数据结构 树
    Python 正在表达式
  • 原文地址:https://www.cnblogs.com/iRedBean/p/5975480.html
Copyright © 2011-2022 走看看