zoukankan      html  css  js  c++  java
  • poj 1320

    Street Numbers
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 2806   Accepted: 1565

    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
    

    Source

    先介绍一下什么事佩尔方程
    定义:形如x^2 - dy^2 = 1(d>1且d不为完全平方数)的不定方程称为佩尔方程
    若佩尔方程x^2 - dy^2 = 1的最小特解是(x1,y1)那么可以有迭代公式
    xn = xn-1*x1 + d*yn-1*y1;
    yn = xn-1*y1 + yn-1*x1;
    上面题目将等式两边化简得到(2*m+1)^2 - 8n^2 = 1然后套用迭代公式就好了
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <stack>
     5 #include <queue>
     6 #include <map>
     7 #include <algorithm>
     8 #include <vector>
     9 
    10 using namespace std;
    11 
    12 const int maxn = 1000005;
    13 
    14 int main()
    15 {
    16     int x,y,x1,y1,px,py,d;
    17     x1 = 3;
    18     y1 = 1;
    19     px = 3;
    20     py = 1;
    21     d = 8;
    22     for(int i=1;i<=10;i++){
    23         x = px*x1 + d*py*y1;
    24         y = px*y1 + py*x1;
    25         printf("%10d%10d
    ",y,(x-1)/2);
    26         px = x;
    27         py = y;
    28     }
    29     return 0;
    30 }
    View Code
  • 相关阅读:
    requests实现接口自动化(三)
    api 25 PopupWindow会占据整个屏幕
    INSTALL_FAILED_USER_RESTRICTED
    事件分发_水平滑动和垂直冲突解决
    MPAndroidChart market右边显示不全问题
    SimpleDateFormat 取当前周的周一和周日的日期,当前月第一个和最后一天的日期
    Callable,Runnable比较及用法
    Android系统启动流程
    debug-stripped.ap_' specified for property 'resourceFile' does not exist
    Theme.AppCompat.Light的解决方法
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4937781.html
Copyright © 2011-2022 走看看