zoukankan      html  css  js  c++  java
  • uva 1510

    题目链接:uva 1510 - Neon Sign

    题目大意:给定n个点,随意三点不共线,而且两两点之间有一条线,给定线的颜色。问说有多少个三角形三边同色。

    解题思路:对于每一个点。记录该点黑色边的数量和红色边的数量,考虑以该点为顶点的三角形,从红色边中选一条,黑色边中选一条,组成的三角形一定是不满足的。由于一个不同色三角形会有两个点满则。所以考虑了两次。

    用总的个数减掉不同色的就可以。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    typedef long long ll;
    const int maxn = 1005;
    
    ll n, r[maxn], l[maxn];
    
    void init () {
        scanf("%lld", &n);
        int x;
        memset(l, 0, sizeof(l));
        memset(r, 0, sizeof(r));
    
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                scanf("%d", &x);
                if (x) {
                    r[i]++;
                    r[j]++;
                } else {
                    l[i]++;
                    l[j]++;
                }
            }
        }
    }
    
    ll solve () {
        ll sum = (ll)n * (n-1) * (n-2) / 6;
    
        ll del = 0;
        for (int i = 0; i < n; i++)
            del += l[i] * r[i];
        return sum - del / 2;
    }
    
    int main () {
        int cas;
        scanf("%d", &cas);
        while (cas--) {
            init();
            printf("%lld
    ", solve());
        }
        return 0;
    }
  • 相关阅读:
    python day05
    python day04
    python day03
    python day02
    计算机基本了解
    流程控制
    MFC程序中创建文件夹(文件路径)
    svn移动目录并且保存历史日志
    C++单例模式的问题
    PtInRect 的详细范围
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5093294.html
Copyright © 2011-2022 走看看