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 ...
随机推荐
- 理解C#系列 / 核心C# / 判断&循环&跳转
判断&循环&跳转 说明 本节写的是C#语言的控制程序流的语句,“控制程序流”就是控制程序运行流程的意思. 判断 很容易理解:如果……就…… if语句:测试特定条件是否满足,如果满足就执 ...
- UI5_HomeWorkCompanyViewController
// // ItemCompany.h // UI5_HomeWork // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 ...
- C# 中有关 using 关键字
关于 C# 中的 using 关键字 我们往往只在代码的开头使用 using 关键字来引入名称空间,这是 using 的一个最常见的使用. 但是,using 关键字是否只有这么一处用武之地吗? 下面, ...
- [GeekBand] C++ 高级编程技术 (1)
一.类型转换 class Fraction { public: explicit Fraction(int num, int den=1) : m_numerator(num), m_denomina ...
- 控制反转 (inversion of control)
The inversion of control (IoC) pattern is abstract; it says that one should move dependency creation ...
- 【转】使用Memcached提高.NET应用程序的性能
在应用程序运行的过程中总会有一些经常需要访问并且变化不频繁的数据,如果每次获取这些数据都需要从数据库或者外部文件系统中去读取,性能肯定会受到影响,所以通常的做法就是将这部分数据缓存起来,只要数据没有发 ...
- Nginx +keepalived
Nginx +keepalived 配置高可用的Nginx 准备环境: 节点node17,node18 lftp 172.16.0.1:/pub/Sources/6.x86_64/nginx ...
- winform Config文件操作
using System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Config ...
- web前端--知识点,笔记叠加(javascript,jquery,html5+css3.0,ajax)
函数传参列表,获取方法arguments的使用 function arg(){ var str = '总共传了'+arguments.length+'个参数\n'; for(var i=0;i< ...
- Android:WebView中对图片注册上下文菜单
前言 今天一朋友问我一个问题,就是如何在WebView控件中的图片增加上下文菜单,以便增加保存图片等功能.今天就给他简单做了一个演示Demo,现写下来,给有相同问题的朋友提供些许思路吧. 概要实现 其 ...