#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. 轻量级的移动框架--zepto.js

    Zepto是一个轻量级的支持移动WebKit浏览器javascript移动端框架,框架支持jQuery语法,该框架的压缩包zepto.min.js 大小只有21K, 使用服务器端 gzip 压缩后大小 ...

  2. aws部署从无到有(二)windows管理aws

    1 AMI正常启动后会进入下面页面 2 远程链接点击如何连接至您的 Linux 实例进入下载页 Windows下使用 PuTTY连接到 Linux 实例 http://www.chiark.green ...

  3. mybatis 批量插入值的sql

    <insert id="insertAwardPic" useGeneratedKeys="true" parameterType="java. ...

  4. ggplot2 geom设置—散点图

    散点图也是目前R中的常用的图形之一 geom_point(mapping = NULL, data = NULL, stat = "identity", position = &q ...

  5. MongoDB数据模型(三)

    六.数据模型引用 文档 我们已经知道MongoDB以文档的形式存储数据,而文档是JSON风格的数据结构,由一系列的“字段名-值”对组成,如下所示 { "item": "p ...

  6. mysql表设计

    model表 记录网站模块:如视频,音频,调查,01发布内容时.可以指定发布到哪个模块下02可以统计每个模块的访问量设计表注意点01主键不要用id (全部使用 当前表名+id 如modelid)02n ...

  7. wpf 异步加载 只需6段代码

    private BackgroundWorker worker = null; ProgressBar probar = new ProgressBar(); private int percentV ...

  8. 使用Erlang和Yaws开发REST式的服务

    看过那张很出名的“Apache vs. Yaws”图么?是不是在考虑你也应该使用Yaws了?这些图给人的第一印象是,Yaws在可伸缩性上具有难以置信的巨大优势,它可以扩展到80000个并行的连接,而 ...

  9. zabbix 监控mysql主从

    这里记录了,每次都百度查询多次. zabbix默认包含mysql监控 其中包含 mysql的基本状态监控 MySQL主从监控需要结合自定义 1)目前项目需求 只对 Slave_IO_Running . ...

  10. E - 小晴天老师系列——我有一个数列!

    E - 小晴天老师系列——我有一个数列! Time Limit: 20000/10000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/O ...