zoukankan      html  css  js  c++  java
  • 10.30日补题

    B

    Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.

    Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.

    Input

    The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.

    Output

    First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.

    Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.

    Example

    Input
    0 0
    1 0
    0 1
    Output
    3
    1 -1
    -1 1
    1 1
    题意:给定3个点,求另一个可能的点构成平行四边形。
    解题思路:可能的点必为3个,根据两边平行且边长相等可计算得这3个点的具体位置。
    ac代码:
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
        long long int n,k,i,m,mm;
        cin>>n>>k;
        m=pow(2,n)-1;
        if(k==m/2+1){
            cout<<n<<endl;
        }
        else{
            mm=m/2+1;
            for(i=n-1;i>0;i--){
                if(k>mm){
                    k=k-mm;
                }
                mm=mm/2+1;
                if(mm=k){
                    cout<<i<<endl;
                    break;
                }
            }
        }
        return 0;
    }
    View Code

    E

    Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.

    Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n - 1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1, 2, 1] after the first step, the sequence [1, 2, 1, 3, 1, 2, 1] after the second step.

    The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i. e. after (n - 1) steps.

    Please help Chloe to solve the problem!

    Input

    The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n - 1).

    Output

    Print single integer — the integer at the k-th position in the obtained sequence.

    Examples

    Input
    3 2
    Output
    2
    Input
    4 8
    Output
    4

    Note

    In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.

    In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.

    题意:给定一组自定义的数列,让求第k个位置的数是多少。

    解题思路:可以发现,1 + 2x 的位置值都是 1,2 + 4x 的位置的值都是 2,4 + 8x 的位置的数都是 3,8 + 16x 的位置的数都是 4……,所以只要质因数中2的个数加1即可。

    ac代码:

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
        int n,sum=0;
        long long int k;
        cin>>n>>k;
        while(1){
            if(k%2==0){
                sum++;
                k=k/2;
            }
            else{
                break;
            }
        }
        cout<<sum+1<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    Git
    Entropy, relative entropy and mutual information
    2021.5.3 团队冲刺第六天
    2021.5.2 团队冲刺第五天
    2021.5.1 团队冲刺第四天
    2021.4.30 团队冲刺第三天
    2021.4.29 团队冲刺第二天
    2021.4.28 团队冲刺第一天
    2021.4.27
    2021.4.26
  • 原文地址:https://www.cnblogs.com/nanan/p/13945560.html
Copyright © 2011-2022 走看看