• POJ 1320 Street Numbers(佩尔方程)


    Street Numbers
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 3078   Accepted: 1725

    Description

    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

    There is no input for this program.

    Output

    Output will consist of 10 lines each containing a pair of numbers, in increasing order with the last number, each printed right justified in a field of width 10 (as shown above).

    Sample Input

    Sample Output

             6         8
            35        49
    题目意思也就是,从家里向右走走到街道尾部经过的编号之和(不包括自己家)和从家里向左走走到街头经过的编号之和(不包括自己家)相等
    设自己家的编号为m,街道共有n家,所以有

    化简整理得

    配凑得

    ,所以转化为佩尔型方程,且首项为

    #include <iostream>
    #include <cstdio>
    using namespace std;
    typedef long long ll;
    ll x,y,fx,fy,a,b;
    int main()
    {
        x=fx=3;y=fy=1;
        for(int i=0;i<10;i++)
        {
            a=fx*x+8*fy*y;
            b=fy*x+fx*y;
            printf("%10lld%10lld
    ",b,(a-1)/2);
            fx=a;
            fy=b;
        }
        return 0;
    }
    
    
  • 相关阅读:
    建模:确定服务的边界——《微服务设计》读书笔记
    linux & windows下重启oracle
    Git配置用户名与邮箱
    Git中使用amend解决提交冲突
    微服务架构师的职责——《微服务设计读书笔记》
    MAC下配置ssh让SourceTree通过秘钥访问远程仓库
    微服务的概念——《微服务设计》读书笔记
    Uva 11572 唯一的雪花
    Codeforces Round #404 (Div. 2) ABC
    tyvj 1031 热浪 最短路
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/9105232.html
Copyright © 2020-2023  润新知