标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1466
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8799 Accepted Submission(s):
3973
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 long long a[21][200]; //a[i][j]表示i条直线有j个交点,因为20条直线最多有C(20,2)=190条直线 8 //开200数组就够,下面循环也是一样。 9 10 int main () 11 { 12 memset(a, 0, sizeof(0)); 13 for (int i=1; i<=20; i++) 14 { 15 a[i][0] = 1; 16 for (int j=1; j<=i; j++) //i条直线中有j条非平行线,则有i-j条非平行线。 17 { 18 for (int k=0; k<=190; k++) //遍历0-190,若j条线有k个交点成立,则在加上i-j条平行线就有i条线(i-j)*j+k个交点成立 19 { 20 if (a[j][k]) 21 a[i][(i-j)*j+k] = 1; 22 } 23 } 24 } 25 int n; 26 while (scanf ("%d",&n)==1) 27 { 28 printf ("0"); 29 for (int i=1; i<=190; i++) 30 if (a[n][i]) 31 printf (" %d",i); 32 printf ("\n"); 33 } 34 return 0; 35 }
标签:
原文地址:http://www.cnblogs.com/qq-star/p/4622997.html