标签:
分数数列Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB
Total Submission: 11 Submission Accepted: 3Description一个数列的前6项为:1/2,3/5,4/7,6/10,8/13,9/15等,试求数列的第n项(n<2000)
Input输入一个整数n(0< n < 2000)
Output输出数列的第n项
Sample Input
Original Transformed 1980
Sample Output
Original Transformed 3203/5183
找规律
对于第n项
分子为前n-1项未出现的自然数中最小的一个
分母为分子+n
(真难找,感谢我瑞)
AC代码:GitHub
1 /* 2 By:OhYee 3 Github:OhYee 4 HomePage:http://www.oyohyee.com 5 Email:oyohyee@oyohyee.com 6 Blog:http://www.cnblogs.com/ohyee/ 7 8 かしこいかわいい? 9 エリーチカ! 10 要写出来Хорошо的代码哦~ 11 */ 12 13 #include <cstdio> 14 #include <algorithm> 15 #include <cstring> 16 #include <cmath> 17 #include <string> 18 #include <iostream> 19 #include <vector> 20 #include <list> 21 #include <queue> 22 #include <stack> 23 #include <map> 24 using namespace std; 25 26 //DEBUG MODE 27 #define debug 0 28 29 //循环 30 #define REP(n) for(int o=0;o<n;o++) 31 32 const int maxn = 6000; 33 bool Has[maxn]; 34 bool Do() { 35 int n; 36 if(scanf("%d",&n) == EOF) 37 return false; 38 memset(Has,false,sizeof(Has)); 39 int last = 1; 40 for(int i = 1;i <= n;i++) { 41 int j; 42 for(j = last;Has[j];j++); 43 Has[j] = true; 44 Has[j + i] = true; 45 last = j; 46 if(i == n) 47 printf("%d/%d\n",j,j + i); 48 } 49 return true; 50 } 51 52 int main() { 53 while(Do()); 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/ohyee/p/5513867.html