zoukankan      html  css  js  c++  java
  • UVa11401 Triangle Counting

    数学问题 递推

    设三角形三边长分别为x,y,z,满足x>y>z

    可以得出x-y<z<x

    当x=n时:

      当y=1时无解;当y=2时有一个解;当y=3时有2个解....当y=n-1时有n-2个解。

      总共有 (n-1)(n-2)/2个解。

      减去其中的 (x-1) div 2 个等腰三角形,剩下的三角形每个都被算了两遍(因为计算时y和z大小关系未定)

    那么,x=n时,方案数f[x]=f[x-1](//最长边为x-1的方案数) + ((n-1)(n-2)/2-(x-1)/2)/2  (//最长边为x的方案数)

    递推出解。

     1 /*by SilverN*/
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 #define LL long long
     8 using namespace std;
     9 const int mxn=1000010;
    10 LL s[mxn];
    11 int main(){
    12     LL i,j;
    13     for(i=3;i<mxn;i++)
    14         s[i]=s[i-1]+((i-1)*(i-2)/2-(i-1)/2)/2;
    15     int n;
    16     while(scanf("%d",&n) && n>=3){
    17         printf("%lld
    ",s[n]);
    18     }
    19     return 0;
    20 }
  • 相关阅读:
    nodejs获取服务器数据到页面
    Struts 2
    JQuery
    JDBC
    Hiberbate
    EasyUi
    JavaScript
    利用 HashSet 去过滤元素是否重复
    HTML
    MySQL
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6275725.html
Copyright © 2011-2022 走看看