计算直线的交点数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8727 Accepted Submission(s): 3933
Problem Description
平面上有n条直线,且无三线共点,问这些直线能有多少种不同交点数。
比如,如果n=2,则可能的交点数量为0(平行)或者1(不平行)。
比如,如果n=2,则可能的交点数量为0(平行)或者1(不平行)。
Input
输入数据包含多个测试实例,每个测试实例占一行,每行包含一个正整数n(n<=20),n表示直线的数量.
Output
每个测试实例对应一行输出,从小到大列出所有相交方案,其中每个数为可能的交点数,每行的整数之间用一个空格隔开。
Sample Input
2 3
Sample Output
0 1 0 2 3链接:http://acm.hdu.edu.cn/showproblem.php?pid=1466#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; long long a[21][201]; int main () { memset(a, 0, sizeof(0)); for (int i=1; i<=20; i++) { a[i][0] = 1; for (int j=1; j<=i; j++) { for (int k=0; k<=200; k++) { if (a[j][k]) a[i][(i-j)*j+k] = 1; } } } int n; while (scanf ("%d",&n)==1) { printf ("0"); for (int i=1; i<=200; i++) if (a[n][i]) printf (" %d",i); printf ("\n"); } return 0; }