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 ...
随机推荐
- Cookie和Session简介与区别
1.Cookie和Session简介与区别 在非常多时候,我们需要跟踪浏览者在整个网站的活动,对他们身份进行自动或半自动的识别(也就是平时常说的网站登陆之类的功能),这时候,我们常采用Cookie与 ...
- Elementary os的安装
1. 使用安装文件进行数据读取 2. 进入安装界面 3. 选择语言并进行安装(可以先试用) 4. 选择继续(可以勾选两个选项,意思是 ...
- [转] 正则表达式 oracle
地址:http://www.cnblogs.com/Azhu/archive/2012/04/03/2431127.html 从oracle database 10gsql 开发指南中copy的. 正 ...
- Python深复制浅复制or深拷贝浅拷贝
1. copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象.(比深拷贝更加节省内存)2. copy.deepcopy 深拷贝 拷贝对象及其子对象 用一个简单的例子说明如下: >& ...
- 13款精彩实用的最新jQuery插件
1.jQuery特色菜单 圆形动画菜单插件 jQuery是一个非常流行的WEB前端框架,尽管HTML5非常酷,但是如果HTML5结合jQuery的话就能实现更酷更实用的插件.今天分享的这款jQuery ...
- CXF和Axis的比较【转】
在SOA领域,我们认为Web Service是SOA体系的构建单元(building block).对于服务开发人员来说,AXIS和CXF一定都不会陌生.这两个产品都是Apache孵化器下面的Web ...
- SharedSDK微信分享不成功,分享之后没有反应
对于一般来说,使用SharedSDK的时候,分享不成功不外乎下面几个原因: 1.测试没有打包2.打包的keystore跟微信开放平台上面的不一致, 导致MD5码不一致3.分享参数错误4.应用没有审核通 ...
- 13.mariadb-rhce考试解题思路
1.安装mariadb ①yum install -y mariadb mariadb-server 或者 yum groupinstall -y mariadb 2.备份和还原数据库 ①备份:mys ...
- 转载:Linux内核探索之路——关于书
转自http://blog.chinaunix.net/uid-20608849-id-3029223.html 在学习Linux内核代码的过程中,定会参考很多书籍以及网路资源,但是并不是所有的书籍和 ...
- 【转载】Powershell获取世纪互联Office365中所有用户的OWA时区
get-mailbox -resultsize unlimited | Get-MailboxRegionalConfiguration | select Identity,TimeZone | wh ...