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:Problem 1019怎么过呀~测试一百组 都是对的~ 提交就是通不过~In Reply To:Problem 1019怎么过呀~测试一百组 都是对的~ 提交就是通不过~ Posted by:iheng_scau at 2012-09-18 20:05:36 #include<iostream> #include<math.h> //This program is aimed to find the given position i in the number sequence //Sample serial sequence: //1121231234123451234561234567123456781234567891234567891012345678910111234567891011 using namespace::std; int target_i(int i){ int target; double group_n; int cast_n; group_n=sqrt(2.0)*sqrt(double(i)); cast_n=(int)(group_n); if((cast_n+1)*cast_n<2*i) cast_n=cast_n; else if((cast_n+1)*cast_n>2*i) cast_n--; int sum=(1+cast_n)*(cast_n*0.5); if(sum==i) target=cast_n; else{ target=i-sum; } return target; } int main(){ int i; int test_num; int n=0; cin>>test_num; while(n<test_num){ cin>>i; cout<<target_i(i)<<endl; //cout<<"slow: "<<target_algorithm(i)<<endl; ++n; }//while return 0; } /*Test Case: Sample Input 2 8 3 Sample Output 2 2 Special Case:2147483647 */ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator