zoukankan      html  css  js  c++  java
  • uva 138 Street Numbers

    感觉就是求1~ n 然后家在中间的k位置,求1~ k-1 的和等于k+1~n

    题目:

     Street Numbers 

    A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the street and back. One night she adds up the street numbers of the houses she passes (excluding her own). The next time she walks the other way she repeats this and finds, to her astonishment, that the two sums are the same. Although this is determined in part by her house number and in part by the number of houses in the street, she nevertheless feels that this is a desirable property for her house to have and decides that all her subsequent houses should exhibit it.

    Write a program to find pairs of numbers that satisfy this condition. To start your list the first two pairs are: (house number, last number):

             6         8
            35        49

    Input and Output

    There is no input for this program. Output will consist of 10 lines each containing a pair of numbers, each printed right justified in a field of width 10 (as shown above).

    代码:

     1 //Thu Jan  2 22:20:48 2014
     2 //Author:Minshik
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <string>
     8 #include <vector>
     9 #include <set>
    10 #include <stack>
    11 #include <queue>
    12 #include <deque>
    13 #include <memory.h>
    14 #include <cctype>
    15 #include <iomanip>
    16 #include <cmath>
    17 using namespace std;
    18 
    19 // k^2 = (n+n^2)/2
    20 int main()
    21 {
    22 
    23     int cnt = 0;
    24     long long n=2;
    25     while(cnt<10)
    26     {
    27         long long d = (n+pow(n,2))/2;
    28         long long c = sqrt(d);
    29         if(  c*c == d  )
    30         {
    31             cout<<setw(10)<<c << setw(10)<<n<<endl;
    32             cnt++;
    33         }
    34         n++;
    35     }
    36 
    37     return 0;
    38 }
  • 相关阅读:
    Web大文件上传断点续传解决方案
    STL 源代码剖析 算法 stl_algo.h -- rotate
    BZOJ 1260 CQOI2007 涂色paint 动态规划
    Shiro学习(总结)
    数组与指针
    Doing Homework again(杭电1789)
    leetCode 75.Sort Colors (颜色排序) 解题思路和方法
    hdu 4786 Fibonacci Tree(最小生成树)
    Havel--Hakimi定理推断可图化 python
    最近小感——一个残疾人写的操作系统
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3502764.html
Copyright © 2011-2022 走看看