#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. 浏览器差异性hack

    1 js函数 很多人误以为数组 push 方法拼接字符串会比 += 快,要知道这仅仅是 IE6-8 的浏览器下. 实测表明现代浏览器使用 += 会比数组 push 方法快,而在 v8 引擎中,使用 + ...

  2. 使用SQL 从表中取记录

    SQL 的主要功能之一是实现数据库查询. 你使用查询来取得满足特定条件的信息. 一个简单的表查询实例 SQL 查询的句法非常简单.假设有一个名为email_table 的表,包含名字和地址两个字段,要 ...

  3. LeetCode OJ 31. Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  4. chapter 14_1 环境

    Lua将其所有的全局变量保存在一个常规的table中,称为“global environment”. Lua将环境table自身保存在一个全局变量_G中,_G._G等于 _G . 比如下面的代码打印出 ...

  5. lucene索引的创建与搜索

    package com.cs.multi; import java.io.File;import java.io.IOException; import org.apache.lucene.analy ...

  6. 华为配置SSH登陆详细步骤

    理解下SSH登录的过程: 1.建立目的端口为22的TCP连接 2.协商SSH版本 3.协商密钥和算法 4.会话建立 下面为server端的详细配置步骤: 1.创建本地RSA密钥对 rsa local- ...

  7. 查看Android下生成的.db数据库

    1.在cmd中找到sdk中的platform-tools文件夹. 2.输入adb shell命令. 3.再输入sqlite3 /data/data/com.svs.db/databases/svs.d ...

  8. iOS UIScrollview代理方法

    方法&&属性: // 监控目前滚动的位置(默认CGPointZero) CGPoint contentOffset; - (void)setContentOffset:(CGPoint ...

  9. redis的主从复制与哨兵

    主从复制的关键字是slaveof,有三种方法可以让一个redis数据库变成另一个redis数据库的从数据库: 1.修改redis的配置文件,添加#slaveof <masterip> &l ...

  10. hadoop性能测试命令

    1.测试hadoop写的速度向HDFS文件系统中写入数据,10个文件,每个文件10MB,文件存放到/benchmarks/TestDFSIO/io_data中hadoop  jar share/had ...