判平行四邊形的個數

 1 // D題 判平行四邊形的個數  忘記了數學方法
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<deque>
11 #include<map>
12 #include<iostream>
13 using namespace std;
14 typedef long long  LL;
15 const double pi=acos(-1.0);
16 const double e=exp(1);
17 //const int MAXN =2e5+10;
18 const int N =332748118;
19 
20 struct  edge
21 {
22     int to;
23     int next;
24 }edge[30009];
25 int head[30009];
26 int vis[3009];
27 int check[3009];
28 
29 int main()
30 {
31     int i,p,j,n,t;
32     int m,cnt,a,b,x;
33     scanf("%d%d",&n,&m);
34 
35     memset(head,-1,sizeof(head));
36     cnt = 0;
37     while(m--)
38     {
39         scanf("%d%d",&a,&b);
40         edge[cnt].to = b;
41         edge[cnt].next = head[a];
42         head[a] = cnt++;
43     }
44 
45     ans = 0;
46     for(i = 1; i <= n; i++)
47     {
48         memset(vis,0,sizeof(vis));
49         for(j = head[i]; j != -1; j = edge[j].next)
50         {
51             x = edge[j].to;
52             for(p = head[x]; p != -1; p = edge[p].next)
53             {
54                 if(edge[p].to != i)
55                 {
56                     vis[edge[p].to] ++;
57                 }
58             }
59         }
60 
61         for(j = 1; j <= n; j++)
62         {
63             if(i != j)
64             {
65                 ans += vis[j] * (vis[j] - 1) / 2;
66             }
67         }
68 
69     }
70 
71 
72     printf("%d\n", ans);
73     return 0;
74 }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章