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 ...
随机推荐
- iOS-KVC和KVO精炼讲解(干货)
一.KVO介绍 KVO就是观察者模式,说白了就是你关心的一个值改变了,你就会得到通知.你就可以在你想处理的地方处理这个值. 二.KVO的使用 一般分为三步: 注册监听 使用方法: /** * 添加KV ...
- 理解JavaScript设计模式与开发应用中发布-订阅模式的最终版代码
最近拜读了曾探所著的<JavaScript设计模式与开发应用>一书,在读到发布-订阅模式一章时,作者不仅给出了基本模式的通用版本的发布-订阅模式的代码,最后还做出了扩展,给该模式增加了离线 ...
- 对象属性封装到map中
import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.lang.reflect.Modi ...
- Java线程面试题 Top 50(转载)
原文链接:http://www.importnew.com/12773.html 本文由 ImportNew - 李 广 翻译自 javarevisited.欢迎加入Java小组.转载请参见文章末尾的 ...
- ABAP OO与ALV结合方式探索(2)
接上篇 一开始设计的BO 类是为了实现功能而实现功能 从类的单一职责的角度而言 先把这个BO对象拆分 这里又有一个需要考虑的点: 如何传递内表数据到ALV 如果引入一个中间变量,数据就会被do ...
- WindowsPhone8 数据库增删改查
今天第一次在博客园发表文章,如果有的地方写的不对,还请大家指出! 1.这就是一个简单wp8数据库增删改查 1.创建数据表Person [Table] public class Person : INo ...
- Java 多线程的基本概念
一.线程介绍 多线程同时运行时,单CPU系统实际上是分给每个线程固定的时间片,用这种方式使得线程“看起来像是并行的”.在多CPU系统中,每个CPU可以单独运行一个线程,实现真正意义上的并行,但是如果线 ...
- 锋利的jquery-DOM操作
1 查找节点 ① 可根据jquery选择器来完成节点查找 ② 可用.text()获取节点的文本内容 ③ 可用.attr("attr")获取属性value 2 创建节点 ① 可用jq ...
- 如何设置SecureCRT通过代理连接SSH[转]
http://blog.didu.me/article/84 公司限制了连接外网的端口和IP,只能通过proxy 连接.刚配置了一下 secureCRT 连接外网,貌似速度还是不错,写出来共享下. 如 ...
- 判断php数组维度的小例子
分享一例判断php数组维度的代码,供大家参考. 如下所示: <?php /** * 返回数组的维度 * @param [type] $arr [description] * @return [t ...