POJ 1680 Fork() Makes Trouble
原题链接:http://poj.org/problem?id=1680
对这道题,我只能说:我不知道题目是什么意思,但是AC还是没有问题的。
看来题目半天没明白fork()怎么个工作,但是看样例(根据Loop)自己推出来是一个完全二叉树的前序遍历,而且PID非常的有规律,自己画图看看就知道了。
#include <stdio.h>
#include <string.h>
#define lson cur << 1
#define rson cur << 1 | 1 const int maxn = ; struct node
{
int pid;
int loop;
int tag;
}tree[maxn]; int n, i, k;
void build(int cur, int d)
{
if(d == n)
return;
tree[lson].loop = d;
tree[lson].pid = k;
tree[lson].tag = ++k;
build(lson, d+);
tree[rson].loop = d;
tree[rson].tag = ++k;
tree[rson].pid = tree[cur].pid;
build(rson, d+);
} void dfs(int cur, int d, int flag)
{
if(cur >= maxn) return;
if(d+ == tree[cur].tag)
{
if(flag)
printf("Loop %d: Process ID=%d\n", tree[cur].loop, tree[cur].pid);
else
printf("Process ID=%d, A=%d\n", tree[cur].tag, (tree[cur].loop + ) * );
return ;
}
dfs(lson, d, flag);
dfs(rson, d, flag);
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
memset(tree, , sizeof tree);
k = ;
scanf("%d%d", &n, &i);
tree[].loop = , tree[].pid = k, tree[].tag = ++k;
build(, );
dfs(, (i+) >> , i & );
}
return ;
}
POJ 1680 Fork() Makes Trouble的更多相关文章
- poj 3321:Apple Tree(树状数组,提高题)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18623 Accepted: 5629 Descr ...
- POJ 3321 树状数组(+dfs+重新建树)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 27092 Accepted: 8033 Descr ...
- poj 3321 Apple Tree dfs序+线段树
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Description There is an apple tree outsid ...
- POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25904 Accepted: 7682 Descr ...
- poj 3321 单点更新 区间求和
Apple Tree Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java c ...
- POJ 3321 DFS序
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30636 Accepted: 9162 Descr ...
- POJ 3321 Apple Tree 【树状数组+建树】
题目链接:http://poj.org/problem?id=3321 Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- POJ - 3321 Apple Tree (线段树 + 建树 + 思维转换)
id=10486" target="_blank" style="color:blue; text-decoration:none">POJ - ...
- POJ 题目3321 Apple Tree(线段树)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21566 Accepted: 6548 Descr ...
随机推荐
- ubuntu启动失败the system is running in low graphics mode
ubuntu启动失败the system is running in lowg raphics mode 起因 ubuntu重新设置selinux的模式 修改配置文件/etc/selinux/conf ...
- 9 款赏心悦目的 HTML5/CSS3 特效
1.HTML5 WebGL实验,超酷的HTML5 Canvas波浪墙 这是一款HTML5 Canvas实验项目,也是波浪特效,只是这不是真正的水波,而是利用柱体高度的变化实现的波浪墙效果. 在线演示 ...
- hibernate 一对多映射关系
1. 单项多对一映射 custom(顾客)与order(订单) :一个顾客可以有多个订单,一个订单只能有一个顾客 配置方法:在多的一端配置<many -to one& ...
- JSP_EL使用
JSP中EL表达式的简单介绍和使用 参考资料: http://www.java3z.com/cwbwebhome/article/article8/8124.html?id=2453 http ...
- C++ Bitsets
C++ Bitsets给程序员提供一种位集合的数据结构.Bitsets使用许多二元操作符,比如逻辑和,或等. Constructors 创建新bitsets Operators 比较和赋值bitset ...
- DataGrid1
2013-09-2512:26:31 1.DataGrid页面 <asp:DataGrid ID="msgInfo1" PageSize="8" Auto ...
- git使用小结
本篇文章主要介绍自己在平时工作中使用git的一些常用命令,之前都是记录在本子上面,现在把他们记录在博客上,便于保存和回顾. 1. 建立自己的git仓库 1.1 在一个新建的repo文件夹里面,执行gi ...
- Windows下OpenCV的环境配置
首先去官网下载所需版本的OpenCV(我这里下载的是OpenCV2.4.9),然后安装(也就是解压缩)到某个地方(个人推荐解压到硬盘的根目录).解压完成后,可以得到如下的目录结构(版本不同,可能会有一 ...
- some windowsphone templates
http://inspirationfeed.com/freebies/20-free-windows-phone-7-mockup-and-wireframing-resources/
- 为一个有数据没有主键id的数据表添加主键字段
ALTER TABLE `photo_feedbacks` ADD COLUMN `id` int(11) NOT NULL AUTO_INCREMENT FIRST ,ADD PRIMARY KE ...