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 |
一点思路其实就是一个数组比如: 3步最多走4个位置 4步最多走6个位置 5步最多走9个位置 。。。。。 用一个数组保存下来,然后用二分进行搜索就行了。 赋代码(和别人的代码比起来还有太大差距,仅供参考): #include <iostream> using namespace std; int d[100000]; int num; void loading() { d[3] = 4; for(num = 4;d[num-1] < 1000000000;num ++) d[num] = d[num-1] + (num+1)/2; } int find(int t) { int left = 0,right = num,mid = num/2; while(left <= right) { if(d[mid] > t) right = mid -1; else if(d[mid] <t) left = mid +1; else return mid; mid = (left +right)/2; } return left; } int main() { int n,a,b; loading(); scanf("%d",&n); while(n --) { scanf("%d%d",&a,&b); if(b - a <= 3) { printf("%d\n",b - a); continue; } int t = b - a; printf("%d\n",find(t)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator