ural One-two, One-two 2
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Input
Output
Sample Input
| input | output |
|---|---|
5 |
Impossible |
8 |
112 |
AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#define N 5000002
using namespace std;
int n;
struct Node{
int dig,mod;
int f;//模拟指针,指向数组的下一个元素
}nod[N]; int l,r;
bool vis[N];
int ret; void BFS(){
while(l<r){
int tmod1=(nod[l].mod*+)%n;
int tmod2=(nod[l].mod*+)%n;
if(!vis[tmod1]){
vis[tmod1]=;
r++;
nod[r].mod=tmod1;
nod[r].dig=;
nod[r].f=l;
if(tmod1==){ret=r;return ;}
}
if(!vis[tmod2]){
vis[tmod2]=;
r++;
nod[r].mod=tmod2;
nod[r].dig=;
nod[r].f=l;
if(tmod2==){ret=r;return ;}
} l++; }
} void out(int x)
{
if(x>)out(nod[x].f);
else if(x==)return;
cout<<nod[x].dig;
} void first()
{
nod[].dig=;
nod[].f=;
nod[].mod=;
nod[].dig=;
nod[].f=;
nod[].mod=;
} int main()
{
while(cin>>n)
{
if(n==||n==){
cout<<n<<endl;
continue;
}
first(); l=;r=;ret=;
memset(vis,,sizeof(vis));
vis[]=vis[]=; BFS();
if(ret==){
cout<<"Impossible"<<endl;
continue;
}
out(ret);
cout<<endl;
}
return ;
}
ural One-two, One-two 2的更多相关文章
- 后缀数组 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 ...
- ural 2064. Caterpillars
2064. Caterpillars Time limit: 3.0 secondMemory limit: 64 MB Young gardener didn’t visit his garden ...
随机推荐
- python3版本安装
Python环境准备 一.下载: 1.官网下载python3.0系列(https://www.python.org/) 2.下载后图标为: 二.安装: Window下: 1.安装路径: 默认安装 ...
- 一维Poisson方程计算
package com.smartmap.algorithm.equation.differential.partial.ellipsoidal; import java.io.FileOutputS ...
- 使用PDFCreate 和 Powershell 自动保存网页为PDF
先安装PDF Creator. http://rj.baidu.com/soft/detail/10500.html?ald 把他设置为默认打印机. 在IE中设置打印页面的边距,页眉页脚等. Powe ...
- assign,copy,strong,weak,nonatomic的理解
举个例子: NSString *houseOfMM = [[NSString alloc] initWithString:'MM的三室两厅']; 上面一段代码会执行以下两个动作: 1 在堆上分配一段 ...
- sqlite API模型
 每一个数据库连接可以包括多个数据库文件,一个主数据库文件和attached的几个数据库文件. 每一个数据库文件都有自己的B-tree和pager. 数据库连接(connection)和事务(tra ...
- 折腾一天的WordPress
自从昨天开始要写博客,在网上找了找大家都比较推崇著名的WordPress,所以自己就闲来无事要坐下测试弄一个,不弄不知道,一弄折磨人啊,公司的破网直接想让我崩溃,所以这一天就在这搭建环境中度过,不过值 ...
- android加固系列—6.仿爱加密等第三方加固平台之动态加载dex防止apk被反编译
[版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5402599.html ] 此方案的目的是隐藏源码防止直接性的反编译查看源码,原理是加密编译好的 ...
- 监听SD卡状态
最近在做项目时遇到需要处理SD卡拔出时的监听,在网上找了很多资料.总结了一下, 用接收广播处理最有效率 sd卡拔插时会发送广播,具体如下(摘自一位大虾的博客 来自:http://blog. ...
- 不用画线 设置UITableView的全屏分隔线
如图 添加如下代码 sTableView.separatorInset = UIEdgeInsetsZero; sTableView.layoutMargins = UIEdgeInsetsZero ...
- Linux双机信任,适用统一安装
一.生成建立安全信任关系的证书. 在A机root用户下执行ssh-keygen命令,在需要输入的地方,直接回车, # ssh-keygen -t rsa 注:直接回车就行 二.查看生成密钥的文件 # ...