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

看不懂的代码……

Posted by rayafjyblue at 2012-06-05 12:25:21 on Problem 3185
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MASK (0xfffff << 1)
using namespace std;

int count(int bowl, int n, int nflips) {
    if ((bowl & MASK) == 0) return nflips;
    if (n == 1) return 99999;
    if (bowl & (1 << n)) return count(bowl ^ (7 << (n - 2)), n - 1, nflips + 1);
    return count(bowl, n - 1, nflips);
}

int main() {
    int i, bit, bowl = 0;
    for (i = 0; i < 20; i++) {
        scanf("%d", &bit);
        bowl = (bowl << 1) | bit;
    }
    bowl = bowl << 1;
    printf("%d\n", min(count(bowl ^ (3 << 19), 20, 1), count(bowl, 20, 0)));
    return 0;
}

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