#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. Webpack入门——使用Webpack打包Angular项目的一个例子

    2016.1.22,对大多数人来说,这是一个非常平常的日子,但这却是我决定在博客园写博客的日子.虽然注册博客园的博客已有4年8个月,却一直没有动手写过一篇博客,原因是觉得自己水平不行,写不出好东西,所 ...

  2. 驱动力—— 通信引擎(上)—— ESFramework 4.0 进阶(03)

    在ESFramework 4.0 进阶(02)-- 核心:消息处理的骨架流程一文中我们详细介绍了ESFramework中消息处理的骨架流程,并且我们已经知道,ESFramework中的所有通信引擎使用 ...

  3. .Net Core 中使用AutoMapper

    1.新建一个类 using AutoMapper; using YourModels; using YourViewModels; namespace YourNamespace { public c ...

  4. Openjudge-计算概论(A)-统计字符数

    描述: 判断一个由a-z这26个字符组成的字符串中哪个字符出现的次数最多输入第1行是测试数据的组数n,每组测试数据占1行,是一个由a-z这26个字符组成的字符串每组测试数据之间有一个空行,每行数据不超 ...

  5. Unlocker(强力删除文件工具) 1.9.2 汉化绿色版

    软件名称: Unlocker(强力删除文件工具) 1.9.2 汉化绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 5 ...

  6. php 模拟浏览器get和post提交处理

    文件夹test下index.php <?phpheader("Content-Type: text/html;charset=gb2312"); function cUrlG ...

  7. C++中##(两个井号)和#(一个井号)用法

    C(和C++)中的宏(Macro)属于编译器预处理的范畴,属于编译期概念(而非运行期概念).下面对常遇到的宏的使用问题做了简单总结.关 于#和##在C语言的宏中,#的功能是将其后面的宏参数进行字符串化 ...

  8. 一些常见warning的原因和解决方法

    在入职三周后,终于赶齐了接手项目落下两个月的项目,有了一些自己的空闲时间对项目进行整理.主要整理包括类目的整合,从原来一个系统文件夹下几百个文件整改为以MVC设计思想为原则的分文件夹整理类目,井然有序 ...

  9. 在VS中生成后拷贝文件

    环境:win7_64旗舰版,VS2013 工作项目中,一般会使用第三方库,当修改并重新编译第三方库后,需要将DLL文件拷贝到工作项目下的生成目录中,每次手动拷贝比较繁琐,VS提供自定义生成事件,允许我 ...

  10. 完美版cookie设置/得到/删除2016/423

    function setCookie(key, value, t) { var oDate = new Date(); oDate.setDate( oDate.getDate() + t ); do ...