POJ 3652 & ZOJ 2934 & HDU 2721 Persistent Bits(数学 元)
主题链接:
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 A, B, C, and S, where 1
≤ A < 32768, 0 ≤ B < 65536, 2 ≤ C < 65536, and 0 ≤ S < C. S 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;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ 3652 & ZOJ 2934 & HDU 2721 Persistent Bits(数学 元)的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...
- POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem Description As we all know, machine scheduling is a very classical problem in computer scien ...
- 【HDOJ】2721 Persistent Bits
题目有点长,但是题意说的很清楚.位操作. #include <stdio.h> ]; int main() { int a, b, c, s; int i, j, k, n, tmp, m ...
- POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)
POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...
- POJ - 3652 Persistent Bits
“模拟”类型,题型容易,使用bitset库对二进制逐位操作,初始化.十进制转二进制(unsigned int).位操作. POJ - 3652 Persistent Bits Time Limit: ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
随机推荐
- Mongodb 上传图片
mongdb 上传图片: [root@hy-mrz01 ~]# mongofiles put -u "pics" -p "jh7yxx" --host 127. ...
- HTTP协议结构
HTTP报文=从客户机到服务器的请求+从服务器到客户机的响应 1.请求报文的格式如下: 请求头 通用信息头 请求头 实体头 报文主体 请求行的格式为: Method[分隔符]Re ...
- ZYNQ-7000 Unable to connect to ps7_cortexa9 解决方案
图1 开发工具:Xilinx SDk 14.4(基于Eclipse,ISE suite 14.4组件之一) 开发板:Xilinx ZYNQ-7000 zc702 rev 1.0(注意:这个板子的版本说 ...
- Android插件化开发---执行未安装apk中的Service
欢迎各位增加我的Android开发群[257053751] 假设你还不知道什么叫插件化开发.那么你应该先读一读之前写的这篇博客:Android插件化开发,初入殿堂 上一篇博客主要从总体角度分析了一下 ...
- Mac必备软件推荐
阅读原文http://littlewhite.us/archives/245 随着IOS的流行.Mac电脑也越来越多的进入人们的视野,和iPhone系列一样,苹果的Mac产品线也是软硬件完美结合.有着 ...
- 使用gdb调试游戏服务器
前言 谈论gdb重要性 一般来说.提gdb,命令用于调试."命令",用户是几乎相同的复杂话.而事实确实如此,实际的开发调试必须用到gdb. 如今.大多数Linux系统是存在于ser ...
- sqlserver 操作技巧
1.将不同库中的一张表数据导入到另外一张表中去 ① 两张表多存在实体,两表的字段相同,字段的顺序相同的话. insert into 表B select * from 表A ② 两张表多存在实体,两表的 ...
- 14.4.3.5 Configuring InnoDB Buffer Pool Flushing 配置InnoDB Buffer Pool 刷新:
14.4.3.5 Configuring InnoDB Buffer Pool Flushing 配置InnoDB Buffer Pool 刷新: InnoDB执行某些任务在后台, 包括flush 脏 ...
- 对struts2的OGNL的理解
OGNL:Object-Graph Navigation Language.对象图形化导航语言 OGNL是集成进struts2框架中比較强大的技术有助于传输数据和类型转换,OGNL由表达式语言和类型装 ...
- 腾讯測试project师笔试面试记录
从3月29日參加腾讯笔试開始,開始了为期1周的腾讯之旅,尽管最后还是跪在了二面上,可是感觉收获非常多,至少明确了自己与向往的BAT公司的差距,明确了自己还是路漫漫其修远兮. 腾讯非常注 ...