ural 1339. Babies
1339. Babies
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
3 |
3 2 1 |
Problem Source: USU Championship 2004
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n, Boy[N], Girl[N];
int Fa[N * ], Next[N * ];
int Ans[N * ]; inline void Input()
{
scanf("%d", &n);
For(i, , n) scanf("%d", &Boy[i]);
For(i, , n) scanf("%d", &Girl[i]);
} inline void Solve()
{
For(i, , n)
{
if(Boy[i])
{
Next[i] = Boy[i] + n;
Fa[Boy[i] + n] = i;
}
if(Girl[i])
{
Next[i + n] = Girl[i];
Fa[Girl[i]] = i + n;
}
} For(i, , * n)
if(!Fa[i])
{
int x = i;
while(Next[x] && !Ans[x])
{
Ans[x] = Next[x];
Ans[Next[x]] = x;
x = Next[x];
x = Next[x];
}
} For(i, , * n)
if(!Ans[i])
{
int x = i;
while(Next[x] && !Ans[x] && !Ans[Next[x]])
{
Ans[x] = Next[x];
Ans[Next[x]] = x;
x = Next[x];
x = Next[x];
}
} int x = n + ;
For(i, , n)
if(!Ans[i])
{
while(Ans[x]) x++;
Ans[i] = x;
Ans[x] = i;
} For(i, , n - ) printf("%d ", Ans[i] - n);
printf("%d\n", Ans[n] - n);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("B");
#endif
Input();
Solve();
return ;
}
ural 1339. Babies的更多相关文章
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
- ural 2065. Different Sums
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...
随机推荐
- 内核中用于数据接收的结构体struct msghdr(转)
内核中用于数据接收的结构体struct msghdr(转) 我们从一个实际的数据包发送的例子入手,来看看其发送的具体流程,以及过程中涉及到的相关数据结构.在我们的虚拟机上发送icmp回显请求包,pin ...
- web页面记住密码存在安全问题 - 处理方式
现在一般安全网站都不会做记住密码功能,因为记住密码存在安全缺陷. 不考虑网络拦截问题,如果是登录页面记住密码,第二次登录,直接进入开发者模式修改类型为text即可看到密码. 处理方式: 1.把auto ...
- Loadrunner上传与下载文件脚本
一. 上传脚本 Action() { int uploadImgStatus = 0; //获取上传产品图ID web_reg_save_param_ex("ParamName=imgRan ...
- AlwaysOn的认识与相关理解
AlwaysOn技术的简要说明: SQL Server2012所支持的AlwaysOn技术集中了故障转移群集.数据库镜像和日志传送三者的优点,但又不相同.故障转移群集的单位是SQL实例,数据库镜像和日 ...
- ASP.NET MVC中Controller返回值类型ActionResult
1.返回ViewResult视图结果,将视图呈现给网页 public class TestController : Controller { //必须存在Controller\Test\Index.c ...
- 重温WCF之数据契约中使用枚举(转载)(十一)
转载地址:http://www.zhuli8.com/wcf/EnumMember.html 枚举类型的定义总是支持序列化的.当我们定义一个新的枚举时,不必应用DataContract特性,就可以在数 ...
- tomcat安装服务和内存参数设置
第一:安装服务 在dos窗口进入到tomcat的bin目录下,通过如下命令即可将tomcat安装成服务 service.bat install Tomcat2 其中Tomcat2是服务的名称 如果启动 ...
- angularjs实战
1.指令 transclude 保留原来的内容 replace 去掉<my-directive>指令 <script src="http://apps.bdimg.com ...
- webrtc中的带宽自适应算法
转自:http://www.xuebuyuan.com/1248366.html webrtc中的带宽自适应算法分为两种: 1, 发端带宽控制, 原理是由rtcp中的丢包统计来动态的增加或减少带宽,在 ...
- [荐]使用jQuery清空file文件域
file是文本域,我们一般都会使用它来上传文件,在上传文件时我们需要验证,验证完成后,如果存在错误,为了防止将错误信息也上传上去,我们总是希望能够将其清空.但是在IE中,为了安全起见它是不允许我们改变 ...