主题链接:

PKU:http://poj.org/problem?id=3652

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?

problemId=1933

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2721

Description

WhatNext Software creates sequence generators that they hope will produce fairly random sequences of 16-bit unsigned integers in the range 0–65535. In general a sequence is specified by integers ABC, and S, where 1
≤ A < 32768, 0 ≤ B < 65536, 2 ≤ C < 65536, and 0 ≤ S < CS is the first element (the seed) of the sequence, and each later element is generated from the previous element. If X is an
element of the sequence, then the next element is

(A * X + B) % C

where '%' is the remainder or modulus operation. Although every element of the sequence will be a 16-bit unsigned integer less than 65536, the intermediate result A * X + B may be larger, so calculations should be done with a 32-bit int rather
than a 16-bit short to ensure accurate results.

Some values of the parameters produce better sequences than others. The most embarrassing sequences to WhatNext Software are ones that never change one or more bits. A bit that never changes throughout the sequence is persistent. Ideally, a sequence
will have no persistent bits. Your job is to test a sequence and determine which bits are persistent.

For example, a particularly bad choice is A = 2, B = 5, C = 18, and S = 3. It produces the sequence 3, (2*3+5)%18 = 11, (2*11+5)%18 = 9, (2*9+5)%18 = 5, (2*5+5)%18 = 15, (2*15+5)%18 = 17, then (2*17+5)%18 = 3 again, and
we're back at the beginning. So the sequence repeats the the same six values over and over:

Decimal 16-Bit Binary
3 0000000000000011
11 0000000000001011
9 0000000000001001
5 0000000000000101
15 0000000000001111
17 0000000000010001
overall 00000000000?

???

1

The last line of the table indicates which bit positions are always 0, always 1, or take on both values in the sequence. Note that 12 of the 16 bits are persistent. (Good random sequences will have no persistent bits, but the converse is not necessarily
true. For example, the sequence defined by A = 1, B = 1, C = 64000, and S = 0 has no persistent bits, but it's also not random: it just counts from 0 to 63999 before repeating.)  Note that a sequence does not need to return to the
seed: with A = 2, B = 0, C = 16, and S = 2, the sequence goes 2, 4, 8, 0, 0, 0, ....

Input

There are from one to sixteen datasets followed by a line containing only 0. Each dataset is a line containing decimal integer values for A, B, C, and S, separated by single blanks.

Output

There is one line of output for each data set, each containing 16 characters, either '1', '0', or '?' for each of the 16 bits in order, with the most significant bit first, with '1' indicating the corresponding bit is always 1, '0' meaning the corresponding
bit is always 0, and '?

' indicating the bit takes on values of both 0 and 1 in the sequence.

Sample Input

2 5 18 3
1 1 64000 0
2 0 16 2
256 85 32768 21845
1 4097 32776 248
0

Sample Output

00000000000???

?

1
? ?? ????? ?? ??? ? ??
000000000000???0
0101010101010101
0?? ?000011111?? ?

Source

题意:

给出a、b、c、s。

s是初值,每次变化有s = (a*s+b)%c。

如此直到反复。

这些数都表示成二进制,假设某位在全部数都是0则输出0。是1则输出1。假设都有可能输出问号。

代码例如以下:

#include <cstdio>
#include <cstring>
int vis[1000000];
int main()
{
int str[47]; int a, b, c, s;
while(scanf("%d",&a))
{
if(a == 0)
break;
scanf("%d%d%d",&b,&c,&s);
memset(vis,0,sizeof(vis));
int tt = s;
int l = 0;
while(tt)
{
str[l++] = tt%2;
tt/=2;
}
for(int i = l; l < 16; l++)
{
str[i++] = 0;
}
/*for(int i = 0; i < 16; i++)
{
printf("%d ",str[i]);
}*/
tt = s;
while(!vis[tt])
{
l = 0;
vis[tt] = 1;
int tm = tt;
while(tm)
{
if(str[l] != tm%2)
{
str[l] = 3;
}
tm/=2;
l++;
}
tt = (((a*tt)%c) + (b%c))%c ;
}
for(int i = 15; i >= 0; i--)
{
if(str[i]!=3)
printf("%d",str[i]);
else
printf("?");
}
printf("\n");
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

最新文章

  1. Java数据结构——字典树TRIE
  2. 安装ssh服务
  3. 隐藏Nginx/Apache版本号的安全性与方法
  4. Web自动化框架LazyUI使用手册(1)--框架简介
  5. BZOJ 4557 侦查守卫
  6. Eclipse中设置在创建新类时自动生成注释
  7. ADO.NET 快速入门(十一):连接池
  8. JQUERY 插件开发——LAZYLOADIMG(预加载和延迟加载图片)
  9. Android(java)学习笔记214:开源框架的文件上传(只能使用Post)
  10. CSS阻止文本选择
  11. SQL Server Insert操作中的锁
  12. C#用WebClient下载File时操作超时的问题
  13. C#函数以及应用
  14. 转:【Java并发编程】之二十三:并发新特性—信号量Semaphore(含代码)
  15. JavaScript奇技淫巧
  16. BI基础知识
  17. vivado源文件和仿真文件的建立
  18. SVN:linux下搭建svn服务器
  19. delphi TreeView 从数据库添加节点的四种方法
  20. spring启动component-scan类扫描加载,以及@Resource,postConstruct等等注解的解析生效源码

热门文章

  1. 通过Jexus 部署 dotnetcore
  2. 中国还是和AMD走到一起了 但美国会高兴吗(网易科技 卢鑫)
  3. 11586 - Train Tracks
  4. scrum经验
  5. Java 实现观察者(Observer)模式
  6. ASP.NET - 多级分类
  7. Python WxPython 的安装以及使用
  8. Appium Server 传递的基本参数
  9. Fedora Linux 下安装配置C开发环境Code::Blocks
  10. Ural 1073 Square Country (DP)