zoukankan      html  css  js  c++  java
  • Good Bye 2020 A

    Good Bye 2020 A

    大意

    (OXY) 二维平面上,有一个点 ((0,1)) ,现在给定 (N) 个值 (x_1,x_2,...,x_n) 代表了 (N) 个点,坐标为 ((x_1,0), (x_2,0),..., (x_n,0))

    问,有多少种三角形面积可以被构成。

    思路

    因为给定点的坐标都在 (X) 轴上,仅有一个初始点在 ((0,1)) 所以三角形面积的种类数就是底边长的种类数。

    (Theta(n^2)) 暴力跑一边。

    代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    using namespace std;
    
    #define ll long long
    #define ull unsigned long long
    #define cint const int&
    #define Pi acos(-1)
    
    const int mod = 998244353;
    const int inf_int = 0x7fffffff;
    const ll inf_ll = 0x7fffffffffffffff;
    const double ept = 1e-9;
    
    int t;
    int n;
    int a[51];
    bool dp[101];
    
    int main() {
        cin >> t;
        while(t--) {
            memset(dp, 0, sizeof dp);
            dp[0] = 1;
            int ans=0;
            cin >> n;
            for(int i=1; i<=n; i++) cin >> a[i];
            sort(a+1, a+1+n);
            for(int i=1; i<=n; i++)
                for(int j=i-1; j; j--)
                    if(!dp[a[i]-a[j]]) {
                        dp[a[i]-a[j]] = 1;
                        ++ans;
                    }
            cout << ans << endl;
        }
        return 0;
    }
    

    7min,-0

  • 相关阅读:
    MySQL主从复制
    高可用系列之Nginx
    02.PHP7.x编译详解
    01.PHP5.x编译详解
    月薪2500到年薪20+我经历了些什么?
    更换gitlab公网IP,引发的故障。
    博客资料汇总
    Nginx编译参数
    Zabbix3.0部署最佳实践
    SharePoint 2013让页面显示错误
  • 原文地址:https://www.cnblogs.com/ullio/p/14215885.html
Copyright © 2011-2022 走看看