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 ...
随机推荐
- Vue数据绑定隐藏的神坑....
今天被Vue的一个坑给折磨了一天,终于发现是什么问题,我们先来模拟一个场景: 代码如下: <!DOCTYPE html> <html lang="en"> ...
- arcengine 常用方法
http://www.cnblogs.com/myparamita/archive/2012/02/15/2352182.html
- SrsDataConnector The SQL Server Reporting Services account is a local user and is not supported.
这次使用OS+SQL的镜像还原系统后安装了CRM 2015,主要流程是 安装IIS/AD,SSRS ,CRM2015.自带的SQL中SSRS没有安装完全,需配置一下. 这一切都满顺利的,最后在安装 S ...
- C# 操作PPt,去掉文本框的边框
using System; using System.Collections.Generic; using System.Linq; using System.Text; using OFFICECO ...
- 获取在线APP的素材图片
1.打开iTunes,搜索并下载APP 2.打开下载的APP的路径 4.对ipa包进行解压 5.找到app,右键"显示包内容"进行查看 6.结果
- GCD应用及其他方法
1.GCD应用 单例模式 static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ ...
- OC NSSet
OC NSSet 数组的特点: 有序的 Set的特点: 无序的,存储元素无重复(例:set中有两个元素'a' 输出时只输出一个a) NSSet初始化 NSSet * set = [[NSSet all ...
- rabbitmq_management 安装失败
安装rabbitmq_management的时候出现错误 不能连接rabbit,所以查看状态 看意思感觉好像是rabbit没有运行,但是安装的时候都是默认安装的,所以安装完以后服务的名字就是Rabbi ...
- 新版微耕软件(N3000)与旧版2000的实体功能区别
更多细节请参阅其软件操作说明书. 建议:基于安全的应用始终变化不断,软件投入一直无法满足客户的定制化要求.不如提供基本的SDK,接口,允许第三方以插件的形式开发控制界面.报表. 软件只提供核心的界面. ...
- 软工_个人项目反(shai)思(zhao)
这次作业成绩还算不错,但是也收获了很多的经验与教训,在这里总结一下. 需要继续改进的地方 作业提交方面仍旧有些问题.如助教所说,在GitHub中并没有保存已经编译好的exe文件,导致助教在检查作业的时 ...