Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴代码,一定要判断循环次数<65536啊,坑死了.

Posted by 20101289 at 2015-04-21 14:21:42 on Problem 3652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a,b,c,s,s1,s2;
        while(true) {
            a = sc.nextInt();
            if(a == 0)
                return;
            b = sc.nextInt();
            c = sc.nextInt();
            s = sc.nextInt();
            s1 = s;
            int and1=s;
            int or1=s;
            int i = 0;
            while(true){
                i ++;

                s1 = (a*s1+b)%c;
                and1 = and1&s1;
                or1 = or1|s1;
                if(s1 == s||i>65537) {
                    int not = and1^or1;
                    String ret =Integer.toBinaryString(not);
                    replaceOne(s,ret);
                    break;
                }
                s2 = s1;
                s2 = (a*s2+b)%c;
                if(s1==s2 || i>65537){
                    int not = and1^or1;
                    String ret =Integer.toBinaryString(not);
                    replaceOne(s,ret);
                    break;
                }
            }
        }
    }



    private static void replaceOne(int src,String rep){
        String str = Integer.toBinaryString(src);
        str = appendZ(str.length())+str;
        char[] array = str.toCharArray();
        int length = array.length - rep.length();
        for (int i = rep.length()-1; i >=0 ; i--) {
            if(rep.charAt(i)=='1')
                array[length+i]='?';
        }
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
        }
        System.out.println();
    }

    private static String appendZ(int length){
        length = 16-length;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append("0");
        }
        return sb.toString();
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator