“模拟”类型,题型容易,使用bitset库对二进制逐位操作,初始化、十进制转二进制(unsigned int)、位操作。

POJ - 3652 Persistent Bits

Time Limit: 1000MS

Memory Limit: 65536KB

64bit IO Format: %I64d & %I64u

[Submit]   [Go Back]   [Status]

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

Mid-Central USA 2007

 #include <stdio.h>
#include <string.h>
#include <bitset>
#include <iostream>
using namespace std;
bool visit[(<<)];
bitset<>save;
bitset<>cur;
bitset<>flag;
int main()
{
unsigned int A = , B = , C = , S = , i = ;
while(~scanf("%u", &A)) {
if(!A) break;
memset(visit, , sizeof(visit));
save.reset();
cur.reset();
flag.reset();
scanf("%u%u%u", &B, &C, &S);
save = S;
while(!visit[S]) {
cur = S;
for(i = ; i < ; i++) {
if(save.test(i) != cur.test(i)) {
flag.set(i);
}
}
visit[S] = true;
S = (A*S+B)%C;
}
for(int i = ; i >= ; i--) {
if(flag.test(i)) {
printf("?");
}
else {
cout<<save.test(i);
}
}
printf("\n");
}
return ;
}

POJ - 3652 Persistent Bits的更多相关文章

  1. POJ 3652 &amp; ZOJ 2934 &amp; HDU 2721 Persistent Bits(数学 元)

    主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...

  2. Persistent Bits - 题解【二进制】

    题面: WhatNext Software creates sequence generators that they hope will produce fairly random sequence ...

  3. poj 2325 Persistent Numbers

    简单的贪心和高精度运算,主要还是要读懂题. #include"iostream" #include"stdio.h" #include"string& ...

  4. poj 2325 Persistent Numbers (贪心+高精度)

    把输入数字每次从9-2除,能整除则记录该数字,最后从小到大输出. 应该算是水题,不过窝第一次写高精度除法,虽然1A,不过中间改了好多次. /****************************** ...

  5. 【HDOJ】2721 Persistent Bits

    题目有点长,但是题意说的很清楚.位操作. #include <stdio.h> ]; int main() { int a, b, c, s; int i, j, k, n, tmp, m ...

  6. POJ 2325 Persistent Numbers#贪心+高精度除法

    (- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...

  7. DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards

    题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...

  8. 【POJ】1743 Musical Theme

    http://poj.org/problem?id=1743 题意:不可重叠最长重复子串,n<=20000,具体看<后缀数组>-- 罗穗骞 #include <cstdio&g ...

  9. 线段和矩形相交 POJ 1410

    // 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...

随机推荐

  1. 李洪强iOS面试题之-iOS选择题

    1.及时聊天app不会采用的网络传输方式是 DA UDP B TCP C Http D FTP 2.下列技术不属于多线程的是 AA Block B NSThread C NSOperation D G ...

  2. 遍历Map的两种方法(有排序)

    初始化一个map Map<String, String> map = new HashMap<String, String>(); map.put("1", ...

  3. centos7 服务管理

    服务脚本位置: /usr/lib/systemd/system  (开机不登录就能够运行的服务) /usr/lib/systemd/user      (用户登录后才能运行的服务) 服务脚本示例: [ ...

  4. Unity UGUI HUD 怪物血条实现

    首先做一个血条,创建一个名为Follow3DObject的脚本添加到血条控件上. Follow3DObject.cs的代码如下: using UnityEngine; using System.Col ...

  5. HelloWorld的Sprint计划会议

    1.Sprint需求 编号 用户故事 故事价值 (点数) 1 作为一名小学生,我想要在玩电脑时玩一种 有趣的小游戏   2 作为一名不怎么爱玩大型游戏的白领(也喜欢玩迷宫游戏), 我想要玩一种可以在家 ...

  6. segement fault常见错误

    1.指针赋值前就用它引用内存,或释放后继续访问它的内容. 2.释放同一块内存两次.

  7. 数据库---MySQL练习题及答案

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  8. Ubuntu下VIM的安装及其配置——Linux篇

    一.Ubuntu系统默认内置: 实际上ubuntu默认没有安装老版本的vi,只装了vim.vi是vim.tiny(vim的最小化版本,不含 GUI,并且仅含有一小部分功能,并且默认与vi兼容.此软件包 ...

  9. C#的TreeView标记

    今天用到了TreeView控件,多次添加后发现内容是重复的,于是用到清除:this.myTreeView.Nodes.Clear(): 如果想在添加完节点后,默认全展开:this.myTreeView ...

  10. mac自定义安装nodejs步骤

    自定义安装的好处是nodejs相关的文件都在同一个文件夹下,且不与其它程序的文件混合在同一文件夹下. 1.下载node并解压缩:https://nodejs.org/dist/,选择tar.gz包下载 ...