• 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 }
  • 相关阅读:
    Maven简介,安装,配置
    Centos 安装 Tomcat 并验证
    Centos 安装 jdk 和配置环境变量
    java基本数据类型
    centos7中docker安装并启动jpress
    在docker中访问网络
    在docker中运行一个nginx
    Centos7 安装docker 及使用其简单命令
    Centos7安装dnf工具管理rpm包
    C#获取外网IP地址;C#获取所在IP城市地址
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3502764.html
Copyright © 2020-2023  润新知