zoukankan      html  css  js  c++  java
  • 判平行四边形的个数

     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
    ", ans);
    73     return 0;
    74 }
  • 相关阅读:
    iphoneX 兼容
    app 判断网络状态
    app 版本升级
    express 安装
    app打开QQ与陌生人聊天
    app项目中几个常用的cordvoa插件
    axios请求拦截器和相应拦截器
    vue中MD5+base64加密
    想啥写啥
    react canvas圆环动态百分比
  • 原文地址:https://www.cnblogs.com/daybreaking/p/12778824.html
Copyright © 2011-2022 走看看