• CodeForces 566B Replicating Processes


     1 #include <bits/stdc++.h>
     2 #define N 3010
     3 #define LL long long
     4 #define unsigned U
     5 using namespace std;
     6 int cas=1,T;
     7 int n,a[N<<2],b[N<<2],c[N<<2],v[N],s[N],vis[N<<2];
     8 int main()
     9 {
    10     //freopen("1.in","w",stdout);
    11     //freopen("1.in","r",stdin);
    12     //freopen("1.out","w",stdout);
    13     //scanf("%d",&T);
    14     while(scanf("%d",&n)==1)
    15     {
    16         memset(v,0,sizeof(v));
    17         memset(vis,0,sizeof(vis));
    18         for(int i=1;i<=n<<2;i++) scanf("%d%d%d",a+i,b+i,c+i);
    19         int all=n<<2;
    20         for(int i=1;i<=n;i++) s[i]=4;
    21         puts("YES");
    22         while(all)
    23         {
    24             for(int i=1;i<=n<<2;i++)
    25             {
    26                 if(!vis[i])
    27                 {
    28                     //for(int j=1;j<=n;j++) printf("
    %d %d
    ",s[j],v[j]);
    29                     if(b[i]==c[i]&&s[b[i]]+v[b[i]]<8)
    30                     {
    31                         vis[i]=1;
    32                         all--;
    33                         s[a[i]]--;
    34                         v[b[i]]+=2;
    35                         printf("%d ",i);
    36                         //break;
    37                     }
    38                     else if(b[i]!=c[i]&&s[b[i]]+v[b[i]]<9&&s[c[i]]+v[c[i]]<9)
    39                     {
    40                         vis[i]=1;
    41                         all--;
    42                         s[a[i]]--;
    43                         v[b[i]]++;
    44                         v[c[i]]++;
    45                         printf("%d ",i);
    46                         //break;
    47                     }
    48                 }
    49             }
    50         }
    51         printf("
    ");
    52     }
    53     //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
    54     return 0;
    55 }
    第二次打的代码
     1 #include <stdio.h>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <iterator>
     5 
     6 using namespace std;
     7 
     8 const int maxn = 30000;
     9 int a[4 * maxn + 10], b[4 * maxn + 10], c[4 * maxn + 10];
    10 int ans[4 * maxn + 10], vis[4 * maxn + 10];
    11 int cnt[maxn + 10], m;
    12 
    13 void f(int n) {
    14     m = 0;
    15     while (true) {
    16         bool flag = true;
    17         for (int i = 1; i <= 4 * n; ++i) {
    18             if (vis[i]) continue;
    19             if ((b[i] == c[i] and cnt[b[i]] + 2 <= 5)
    20                 or (b[i] != c[i] and cnt[b[i]] + 1 <= 5 and cnt[c[i]] + 1 <= 5)) {
    21                 --cnt[a[i]];
    22                 ++cnt[b[i]];
    23                 ++cnt[c[i]];
    24                 ans[m++] = i;
    25                 vis[i] = 1;
    26                 flag = false;
    27             }
    28         }
    29         if (flag)
    30             return;
    31     }
    32 }
    33 
    34 int main() {
    35     cin.tie(0);
    36     ios::sync_with_stdio(false);
    37 
    38     int n;
    39     while (scanf("%d",&n)==1) {
    40         memset(vis, 0, sizeof(vis));
    41         memset(cnt, 0, sizeof(cnt));
    42         for (int i = 1; i <= 4 * n; ++i) scanf("%d%d%d",a+i,b+i,c+i);
    43         f(n);
    44 
    45         if (m != 4 * n)
    46             cout << "NO" << endl;
    47         else {
    48             cout << "YES" << endl;
    49             copy(ans, ans + 4 * n, ostream_iterator<int>(cout, " "));
    50             cout << endl;
    51         }
    52     }
    53     return 0;
    54 }
    师兄代码

      为减轻服务器负担,将一个进程分为两个进程,每个服务器上原来有四个进程,分完后每个服务器有八个进程,分的过程中每个服务器最多有九个进程

      做法:先把每个服务器的四个小进程放到同一个数组,循环遍历所有服务器,遍历到每个服务器时就将其中一个服务器分成两个,如果不符合分解条件就先不分,分下一个,一直循环到所有服务器原来的四个小进程都分完

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<vector>
     4 using namespace std;
     5 struct node
     6 {
     7     int b, c, i;
     8     node(int x = 0, int y = 0, int z = 0)
     9     {
    10         b = x;
    11         c = y;
    12         i = z;
    13     }
    14 };
    15 vector<node>a[30010];
    16 int n;
    17 char vis[30010];
    18 int main()
    19 {
    20     while (scanf("%d", &n) == 1)
    21     {
    22         memset(vis, 4, sizeof(vis));
    23         int i, tmp, tmp1, tmp2, j,num;
    24         for (i = 0; i <= n; i++)
    25             a[i].clear();
    26         n *= 4;
    27         num = n;
    28         for (i = 1; i <= n; i++)
    29         {
    30             scanf("%d%d%d", &tmp, &tmp1, &tmp2);
    31             a[tmp].push_back(node(tmp1, tmp2, i));
    32         }
    33         n /= 4;
    34         puts("YES");
    35         int work = 1;
    36         while (work)
    37         {
    38             work = 0;
    39             for (j = 1; j <= n; j++)
    40             {
    41                 if (!a[j].empty())
    42                     for (vector<node>::iterator k = a[j].begin(); k != a[j].end(); k++)
    43                     {
    44                         --vis[j];
    45                         ++vis[k->b];
    46                         ++vis[k->c];
    47                         work = 1;
    48                         if (vis[k->b] < 10 && vis[k->c] < 10)
    49                         {
    50                             printf("%d", k->i);
    51                             num--;
    52                             if (num) printf(" ");
    53                             a[j].erase(k);
    54                             break;
    55                         }
    56                         else
    57                         {
    58                             ++vis[j];
    59                             --vis[k->b];
    60                             --vis[k->c];
    61                         }                    
    62                     }
    63             }
    64         }
    65         puts("");
    66     }
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    Service
    adb server is out of date
    Notification.Builder
    eclipse连接小米2调试程序的问题
    Date类
    this指向冒泡排序二分查找
    Dom事件键盘事件
    Dom事件键盘事件
    12.4Dom事件键盘事件
    事件对象
  • 原文地址:https://www.cnblogs.com/cdyboke/p/4868020.html
Copyright © 2020-2023  润新知