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

Re:分析一下规律

Posted by ahda at 2010-09-28 15:44:27 on Problem 2309
In Reply To:分析一下规律 Posted by:Ontheline at 2009-04-10 16:12:22
楼主差矣,其实不用判断是否为奇数.
我这段代码是没有事先试过的,而是直接在提交那里直接写的.
我就是想试一下直接写能不能acepted,没想到可以.
分享一下:
#include <iostream>
using namespace std;

int Min(int value, int *min, int *max)
{
    int diff = 1;
    int p = value;
    int rank = 0;
    while(p % 2 == 0)
    {
        ++rank;
        p /= 2;
        diff *= 2;
    }
    diff -= 1;
    *min = value - diff;
    *max = value + diff;
    return 0;
}

int main()
{
    int n = 0, value, min, max;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> value;
        Min(value, &min, &max);
        cout << min << " " << max << endl;
    }
    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