P2789 直线交点数

P2789 直线交点数
分成两种情况,一种是平行直线,一种是自由直线,在自由直线中可以存在平行直线,但是不能和第一组的直线平行。自由直线和平行直线的交点是i*(n-i)。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<set>
 8 #include<cstring>
 9 #define inf INT_MAX
10 #define For(i,a,b) for(register int i=a;i<=b;i++)
11 #define p(a) putchar(a)
12 #define g() getchar()
13 //by war
14 //2017.10.26
15 using namespace std;
16 int n;
17 int tot;
18 bool f[30][900];
19 
20 void in(int &x)
21 {
22     int y=1;
23     char c=g();x=0;
24     while(c<'0'||c>'9')
25     {
26     if(c=='-')
27     y=-1;
28     c=g();
29     }
30     while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
31     x*=y;
32 }
33 void o(int x)
34 {
35     if(x<0)
36     {
37         p('-');
38         x=-x;
39     }
40     if(x>9)o(x/10);
41     p(x%10+'0');
42 }
43 int main()
44 {
45     in(n);
46     For(i,0,n)
47     f[i][0]=true;
48     For(i,1,n)
49       For(fr,1,i-1)
50         For(j,0,(i-1)*i/2)
51           if(f[fr][j])
52           f[i][fr*(i-fr)+j]=true;
53     For(i,0,800)
54     if(f[n][i])
55     tot++;
56     o(tot);      
57      return 0;
58 }

 

posted @ 2017-10-26 21:15  WeiAR  阅读(326)  评论(0编辑  收藏  举报