zoukankan      html  css  js  c++  java
  • HDU 5166 Missing number 简单数论

    Missing number

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

    【Problem Description】
    There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.
     
    【Input】
    There is a number T shows there are T test cases below. (T10)
    For each test case , the first line contains a integers n , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.(1n1,000)
     
    【Output】
    For each case output two numbers , small number first.
     
    【Sample Input】
    2 
    3 
    3 4 5 
    1 
    1

    【Sample Output】

    1 2 
    2 3


    【题意】

    找出一个数列中缺的两个数。

    【分析】

    本来没啥好说的,记录完了之后O(n)扫描一遍即可,启发就是一种简单的O(1)的算法也要多多注意下。

    Sum(n)    =n*(n+1)/2
    Sum(n^2)  =n*(n+1)*(2n+1)/6
  • 相关阅读:
    MyString
    Django疑难问题
    mysql 疑难问题-django
    python时间转换 ticks-FYI
    django建议入门-FYI
    Python风格规范-FYI
    scrum敏捷开发☞
    git基本命令
    centos下的安装mysql,jdk
    memcached for .net on windows
  • 原文地址:https://www.cnblogs.com/jcf94/p/4277095.html
Copyright © 2011-2022 走看看