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 }
  • 相关阅读:
    spring boot 集成activeMq
    spring boot配置跨域
    spring boot中使用mybatis逆向工程
    Cookie/Session/Token
    Spring Boot自定义Starter
    linux防火墙命令
    imx6ull+debian10 构建静态qt交叉编译环境
    Arm Qt编译Qt例程出错 GLES3/gl3.h: No such file or directory 解决方法
    QtCreator设置野火iMx6开发板提供的qt交叉编译套件
    联想ideapad-330C 在Ubuntu18.04 上安装Realtek 8821CE无线网卡驱动
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3502764.html
Copyright © 2011-2022 走看看