CodeForces 566B Replicating Processes
#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的更多相关文章
- Codeforces Round #499 (Div. 2) D. Rocket题解
		
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
 - Codeforces Round #321 (Div. 2) E
		
终于补好了. 题目链接: http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 sec ...
 - python爬虫学习(5) —— 扒一下codeforces题面
		
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
 - 【Codeforces 738D】Sea Battle(贪心)
		
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
 - 【Codeforces 738C】Road to Cinema
		
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
 - 【Codeforces 738A】Interview with Oleg
		
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
 - CodeForces - 662A Gambling Nim
		
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
 - CodeForces - 274B Zero Tree
		
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
 - CodeForces - 261B Maxim and Restaurant
		
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
 
随机推荐
- 关于cocos2dx的C++调用创建项目
			
我使用的是cocos2dx-2.1.4版本+cygwin,其实主要是为了配合公司项目,所以用了低版本的cocos2dx 假设已经配置环境成功: 按照对应的要求输入包名,项目名,以及TargetId,就 ...
 - 浏览器差异性hack
			
1 js函数 很多人误以为数组 push 方法拼接字符串会比 += 快,要知道这仅仅是 IE6-8 的浏览器下. 实测表明现代浏览器使用 += 会比数组 push 方法快,而在 v8 引擎中,使用 + ...
 - jQuery 截取double数据  重新赋值
			
$('.prioritySort').each(function(i){ $(this).text($(this).text().substring(0,$(this).text().indexOf( ...
 - WiMAX协议栈
			
1.协议栈模型 协议栈模型将 WiMAX 系统分为数据控制平面和管理平面两个平面 数据控制平面对数据的正确传输进行保证,包括封装.分片.加密.解封装等 基站与用户站之间的特定信令交互完成系统的控制功能 ...
 - 1、SpringMVC+MyBaits实现查询所有
			
1.创建如下所示项目 2.在src下的com.entity包下创建 Emp.java package com.entity; /** * * @author Holly老师 * */ public c ...
 - Delphi中,FALSE 和 nil ,true 和 nil,0的区别
			
True和False是布尔型(Boolean)的值,就是"是"或"否"的意思.nil就是空,一般用于指针或对象变量,指对针或对象对象一般初始化为nil或者释放后 ...
 - .Net Core 常见问题整理
			
1.安装时报0x80070490 找不到元素 这里应该是vs只装了web没有装c++ 下载一个 VC_redist.x64.exe 安装就行了 https://github.com/dotnet/co ...
 - Openjudge-计算概论(A)-苹果和虫子
			
描述 你买了一箱n个苹果,很不幸的是买完时箱子里混进了一条虫子.虫子每x小时能吃掉一个苹果,假设虫子在吃完一个苹果之前不会吃另一个,那么经过y小时你还有多少个完整的苹果? 输入输入仅一行,包括n,x和 ...
 - Erlang OTP gen_event
			
转自:http://www.myexception.cn/program/1569725.html Erlang OTP gen_event (0) 原英文文档:http://www.erlang.o ...
 - tableview选择的时候不要cell的高亮显示样式
			
1.若用方法: //-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)ind ...