| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:分析一下规律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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator