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 ...
随机推荐
- ALT+数字直接取得字符的原理
字符 字节码 utf-8编码 机器二进制码 之间的联系 byte数组与二进制码关系参考文献 例如:字符“我” byte字节码是 [-26, -120, -111] 绝对值源码 [00011010, 0 ...
- Loadrunner连接Mysql数据库
1.库文件下载地址:http://files.cnblogs.com/files/xiaoxitest/MySQL_LoadRunner_libraries.zip 分别添加到Loadrunner b ...
- jQueryEasyUi验证
多重验证: { field : 'startPort', title : "起始端口", editor: "text", width : 50, edi ...
- 怎么把MVC的Controller拆分写到别的类库
以为很难…… 其实直接继承Controller 并且按MVC_Controllser规则命名. 然后网站项目引用该项目即可.
- Delphi中uses在interfeace和implementation中的区别
use单元引入分为在interface中引入,如 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...
- 查看MYSQL中数据表占用的空间
由于数据太大了.所以MYSQL需要瘦身,那前提就是需要知道每个表占用的空间大小. 首先打开指定的数据库: use information_schema; 如果想看指定数据库中的数据表,可以用如下语句: ...
- go sample - mongodb
简单的mongodb 操作 package mainimport ( "fmt" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2 ...
- webrtc中的带宽自适应算法
转自:http://www.xuebuyuan.com/1248366.html webrtc中的带宽自适应算法分为两种: 1, 发端带宽控制, 原理是由rtcp中的丢包统计来动态的增加或减少带宽,在 ...
- RFC(请求注解)--各种协议-标准
转自:http://blog.sina.com.cn/s/blog_65d6476a0101cj8n.html RFC(Request For Comments)-意即“请求注解”,包含了关于Inte ...
- 关于三星I9305出现android.process.acore提示问题
背景:自己用百度云同步通讯录和用微信电话本删除联系人的时候总出现提示acore问题,为此上网找了许久. 网络上多说解决方案为:把Calendar.apk和CalendarProvider.apk两个文 ...