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 ...
随机推荐
- window.open和window.showdialog区别
open打开的窗口可以点击切换到其背后的父窗口,dialog的窗口无法点击切换到其背后的父窗口, 假如用window.opener或者parent等对象时,建议用open方法,不要用dialog,否则 ...
- Objective-C 【protocol-协议 的了解使用】
------------------------------------------- protocol(协议) (1)引文:OC中的protocol和Java中的接口(interface)比较类似, ...
- 7款值得你心动的HTML5动画和游戏
1.HTML5 Canvas粒子效果文字动画特效 之前我们分享过很多超酷的文字特效,其中也有利用HTML5和CSS3的.今天我们要来分享一款基于HTML5 Canvas的文字特效,输入框中输入想要展示 ...
- Apache HTTP Server安装教程
Apache HTTP Server安装教程 Apache HTTP Server的官方网站是:http://httpd.apache.org/,可以从中下载最新版本的Apache HTTP Serv ...
- wordpress使用video.js与七牛云存储实现无广告视频分享应用
video.js是一款极受欢迎的基于HTML5的开源WEB视频播放器,其充分利用了HTML5的视频支持特性,可以实现全平台的无视频插件播放功能,对于现在流行的手机.PAD等移动智能终端有极佳的应用体验 ...
- OpenSUSE 安装并启动Tomcat
安装.用YsST2搜索tomcat安装就好了.不过版本肯定不如官网的新,笔者用的是7.0.42,最新的已经到8.X了. 启动.在服务管理器中找到tomcat,启动.
- mysql主从复制-linux版本
来自:http://www.osyunwei.com/archives/7269.html,改版 mysql主从复制本文采用的是centos6.5+mysql-5.6.23版本之前在 windows7 ...
- c# WinForm 编程总结
1.清空DataGridView /// <summary> /// 清空DataGridView /// </summary> /// <param name=&quo ...
- Silverlight 中DataGrid中全选与非全选问题
问题:当点击全选时,全选所有的复选框,但是滚动屏幕时,却复选框就会取消选中 一.解决方法(将要展示的实体数据模型添加bool属性,在数据绑定时添加click时间,盘带选中的状态,就可以了) 1. xa ...
- Android布局揭秘
前言 今天把对于布局的一些理解写下来,主要内容包括控件的属性的继承关系,控件与容器的属性的关系,以及各种类的属性的使用. 控件的属性种类 通常意义上讲,我们在对一个控件进行属性赋值的时候大体上有种类型 ...