Persistent Bits
问题描述 :
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 |<PHONE_NUMBER>000011 |
| 11 |<PHONE_NUMBER>001011 |
| 9 |<PHONE_NUMBER>001001 |
| 5 |<PHONE_NUMBER>000101 |
| 15 |<PHONE_NUMBER>001111 |
| 17 |<PHONE_NUMBER>010001 |
| overall |<PHONE_NUMBER>0????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, ….
输入:
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.
输出:
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.
样例输入:
2 5 18 3 1 1 64000 0 2 0 16 2 256 85 32768 21845 1 4097 32776 248 0
样例输出:
00000000000????1 ????????????????<PHONE_NUMBER>00???0<PHONE_NUMBER>010101 0???000011111???
解题代码:
import java.util.Arrays; import java.util.Scanner; public class Main { int a; int b; int c; int s; int x; char[] result; int flg; boolean[] dup; public Main() { Scanner scan = new Scanner(System.in); while ((a = scan.nextInt()) != 0) { b = scan.nextInt(); c = scan.nextInt(); s = scan.nextInt(); result = new char[16]; Arrays.fill(result, '0'); initFlg(Integer.toBinaryString(s)); dup = new boolean[c]; dup[s] = true; x = (a * s + b) % c; while (!dup[x]) { dup[x] = true; if (setFlg(Integer.toBinaryString(x))) { break; } x = (a * x + b) % c; } System.out.println(result); } } public void initFlg(String str) { for (int i = 15, k = str.length() - 1; k >= 0; i--, k--) { if (str.charAt(k) == '1') { result[i] = '1'; } } } public boolean setFlg(String str) { flg = 0; for (int i = 15, k = str.length() - 1; k >= 0; i--, k--) { if (result[i] == '?') { flg++; if (flg == 16) { return true; } continue; } else { if (str.charAt(k) != result[i]) { result[i] = '?'; } } } return false; } public static void main(String[] args) { new Main(); } }
第二种解法如果数组有重复元素 就不正确
Java真是解决大数的利器
不错，值得借鉴
第23行：
hash = -1是否应该改成hash[s ] = -1
因为是要把从字符串s的start位到当前位在hash中重置
修改提交后能accept，但是不修改居然也能accept
第一句可以忽略不计了吧。从第二句开始分析，说明这个花色下的所有牌都会在其它里面出现，那么还剩下♠和♦。第三句，可以排除2和7，因为在两种花色里有。现在是第四句，因为♠还剩下多个，只有是♦B才能知道答案。
总结的很全面，学习了！
学习了！！
很有用，收藏了
在方法1里面：
//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;
for (j = adj .begin(); j != adj .end(); ++j)
{
degree[*j]++;
}
}
为什么每遍历一条链表，要首先将每个链表头的顶点的入度置为0呢？
比如顶点5，若在顶点1、2、3、4的链表中出现过顶点5，那么要增加顶点5的入度，但是在遍历顶点5的链表时，又将顶点5的入度置为0了，那之前的从顶点1234到顶点5的边不是都没了吗？
怎么输入两个0程序还没退出
Java真是解决大数的利器


{% extends "layout.html" %} {% block style %} {% endblock %} {% block title %} Homepage {% endblock %} {% block main %}
The Platform provides you with automated approaches to:
1. Prepare receptor ligand complexes and generate required topology files for Molecular Dynamics Simulations
2. Prepare Peptides and Proteins and generate required topology files for Molecular Dynamics Simulations
3. Perform a test run or full scale Molecular Dynamics Simulations using generated solvated structures and topology files in Gromacs
Please Note that while the generated structures and topology files may be useful in other systems, they are here generated to be compatible with Gromacs
Please click the "QGuides" tab to get a Quick Guide on using the platform
For comments and supports, contact me via the address on the footer


1: <?php
2: /**
3: * This file contains the implementation of the class DBWorkerException. It extends the DBWorkerException
4: * exception to distingusih the database related errors in catches.
5: *
6: * @package Database
7: *
8: * @author Oleg Schildt
9: */
10:
11: namespace SmartFactory\DatabaseWorkers;
12:
13: use SmartFactory\SmartException;
14:
15: /**
16: * Class for DBWorkerException in the smarFactory library.
17: *
18: * @author Oleg Schildt
19: */
20: class DBWorkerException extends SmartException
21: {
22: /**
23: * Constructor.
24: *
25: * @param string $message
26: * Error message.
27: *
28: * @param string $error_code
29: * Error code.
30: *
31: * Since the error texts can be localized, the unique code of the error might be important fo using
32: * in comparison.
33: *
34: * @param string $error_element
35: * Error element.
36: *
37: * @param array $error_details
38: * The details might be useful if the message translations are provided on the client, not
39: * on the server, and the message should contain some details that may vary from case to case.
40: * In that case, the servers return the message id instead of final text and the details, the client
41: * uses the message id, gets the final translated text and substitutes the parameters through the details.
42: *
43: * @param string $technical_info
44: * Additional technical infromation. It can be used if it is a programming error and displayed only if the debug mode is active.
45: *
46: * @author Oleg Schildt
47: */
48: public function __construct($message, $error_code, $error_element = "", $error_details = [], $technical_info = "")
49: {
50: parent::__construct($message, $error_code, $error_element, $error_details, $technical_info);
51: }
52: } // DBWorkerException