#include <bits/stdc++.h>
#define N 3010
#define LL long long
#define unsigned U
using namespace std;
int cas=,T;
int n,a[N<<],b[N<<],c[N<<],v[N],s[N],vis[N<<];
int main()
{
//freopen("1.in","w",stdout);
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
//scanf("%d",&T);
while(scanf("%d",&n)==)
{
memset(v,,sizeof(v));
memset(vis,,sizeof(vis));
for(int i=;i<=n<<;i++) scanf("%d%d%d",a+i,b+i,c+i);
int all=n<<;
for(int i=;i<=n;i++) s[i]=;
puts("YES");
while(all)
{
for(int i=;i<=n<<;i++)
{
if(!vis[i])
{
//for(int j=1;j<=n;j++) printf("\n%d %d\n",s[j],v[j]);
if(b[i]==c[i]&&s[b[i]]+v[b[i]]<)
{
vis[i]=;
all--;
s[a[i]]--;
v[b[i]]+=;
printf("%d ",i);
//break;
}
else if(b[i]!=c[i]&&s[b[i]]+v[b[i]]<&&s[c[i]]+v[c[i]]<)
{
vis[i]=;
all--;
s[a[i]]--;
v[b[i]]++;
v[c[i]]++;
printf("%d ",i);
//break;
}
}
}
}
printf("\n");
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}

第二次打的代码

 #include <stdio.h>
#include <cstring>
#include <iostream>
#include <iterator> using namespace std; const int maxn = ;
int a[ * maxn + ], b[ * maxn + ], c[ * maxn + ];
int ans[ * maxn + ], vis[ * maxn + ];
int cnt[maxn + ], m; void f(int n) {
m = ;
while (true) {
bool flag = true;
for (int i = ; i <= * n; ++i) {
if (vis[i]) continue;
if ((b[i] == c[i] and cnt[b[i]] + <= )
or (b[i] != c[i] and cnt[b[i]] + <= and cnt[c[i]] + <= )) {
--cnt[a[i]];
++cnt[b[i]];
++cnt[c[i]];
ans[m++] = i;
vis[i] = ;
flag = false;
}
}
if (flag)
return;
}
} int main() {
cin.tie();
ios::sync_with_stdio(false); int n;
while (scanf("%d",&n)==) {
memset(vis, , sizeof(vis));
memset(cnt, , sizeof(cnt));
for (int i = ; i <= * n; ++i) scanf("%d%d%d",a+i,b+i,c+i);
f(n); if (m != * n)
cout << "NO" << endl;
else {
cout << "YES" << endl;
copy(ans, ans + * n, ostream_iterator<int>(cout, " "));
cout << endl;
}
}
return ;
}

师兄代码

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

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

 #include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
struct node
{
int b, c, i;
node(int x = , int y = , int z = )
{
b = x;
c = y;
i = z;
}
};
vector<node>a[];
int n;
char vis[];
int main()
{
while (scanf("%d", &n) == )
{
memset(vis, , sizeof(vis));
int i, tmp, tmp1, tmp2, j,num;
for (i = ; i <= n; i++)
a[i].clear();
n *= ;
num = n;
for (i = ; i <= n; i++)
{
scanf("%d%d%d", &tmp, &tmp1, &tmp2);
a[tmp].push_back(node(tmp1, tmp2, i));
}
n /= ;
puts("YES");
int work = ;
while (work)
{
work = ;
for (j = ; j <= n; j++)
{
if (!a[j].empty())
for (vector<node>::iterator k = a[j].begin(); k != a[j].end(); k++)
{
--vis[j];
++vis[k->b];
++vis[k->c];
work = ;
if (vis[k->b] < && vis[k->c] < )
{
printf("%d", k->i);
num--;
if (num) printf(" ");
a[j].erase(k);
break;
}
else
{
++vis[j];
--vis[k->b];
--vis[k->c];
}
}
}
}
puts("");
}
return ;
}

CodeForces 566B Replicating Processes的更多相关文章

  1. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  2. Codeforces Round #321 (Div. 2) E

    终于补好了. 题目链接: http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 sec ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Hoffmann树

    数据压缩编码 先把两棵二叉树简化成叶子结点带权的二叉树,图的每个结点之间带有权值 结点的路径长度: 从根结点到该结点的路径上的连接数. 树的路径长度: 树中每个叶子结点的路径长度之和. 结点带权路径长 ...

  2. Objetive-C +load方法研究

    load方法的执行时机           Objetive-C 的runtime会在一个类的所有方法加载到内存中时调用这个类的+load() 方法,因为每个类的方法只是加载一次,所以每个+load( ...

  3. 关于Axis 1.4 环境的搭建问题

    本来很简单的一个环境搭建问题足足困扰了我一周的时间,所以思来想去还是写一篇博文记录下来,以后就不用那么四处去找资料找例子了,实在是浪费时间 废话不多说 1  首先在MyEclipse下创建WEB PR ...

  4. MySQL(3)-索引

    一.索引类型 在MySQL中,存储引擎使用索引,首先在索引中找到对应值,然后根据匹配的索引记录中找到对应的行. 无论是多么复杂的ORM工具,在精妙和复杂的索引面前都是"浮云".这里 ...

  5. HDU 1372 Knight Moves(BFS)

    题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...

  6. C#正则分组实例

    static void Main(string[] args) { string str = "大家家家家家家家明天天天天天天天天玩得得得得得得得开心"; Regex reg = ...

  7. LeetCode OJ 78. Subsets

    Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...

  8. chapter11_1 Lua数组、列表

    Lua中的table可以表示其他语言提供的数据结构:数组.记录.线性表.队列.集合等. 在Lua中很少编写搜索算法,因为table本身就提供了直接访问任意类型的功能. 数组 使用整数来索引table即 ...

  9. beginBackgroundTaskWithExpirationHandle

    [[UIApllication sharedApplication] beginBackgroundTaskWithExpirationHandle:^{}];这个方法在app进入后台时,可以做一些事 ...

  10. iis本地无法通过ip地址访问网站

    防火墙等通通检查过没有发现问题,最后发现是我安装了一款adsafe的广告过滤软件捣的鬼,此软件设置界面没有这样的设置条款,估计是默认的配置,退出后,就ok了.