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 }
  • 相关阅读:
    Vue.directive()方法创建全局自定义指令
    vue中通过ref属性来获取dom的引用
    v-cloak指令
    v-if和v-show
    vue中的v-on事件监听机制
    vue指令v-model
    vue中v-for系统指令的使用
    从零开始在虚拟机中搭建一个4个节点的CentOS集群(一)-----下载及配置CentOS
    MySQL-数据库创建与删除
    MySQL-PREPARE语句
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3502764.html
Copyright © 2011-2022 走看看