zoukankan      html  css  js  c++  java
  • Masquerade strikes back Gym

    Quite often the jury of Saratov SU use the problem "Masquerade" in different practice sessions before the contest. This problem is quite easy — all you need is to print the product of two integers which were read from the input stream.

    As usual, the jury had prepared this problem once again. The jury had nn testcases, the ii -th testcase was a pair of positive integers aiai and bibi , both integers didn't exceed 107107 . All testcases were pairwise distinct.

    Unfortunately, something went wrong. Due to hardware issues all testcases have disappeared. All that the jury were able to restore are the number of testcases nn and the answers to these testcases, i. e. a sequence of nn numbers c1,c2,,cnc1,c2,…,cn , such that aibi=ciai⋅bi=ci .

    The jury ask you to help them. Can you provide any possible testset? Remember that all testcases were distinct and all numbers in each testcase were positive integers and didn't exceed 107107 .

    Input

    First line contains one insteger nn (1n21051≤n≤2⋅105 ) — the number of lost testcases.

    Second line contains nn space-separated integers c1,c2,,cnc1,c2,…,cn (1ci1071≤ci≤107 ) — the answers to the testcases.

    Output

    If there is no such testset, print NO.

    Otherwise, print YES in first line. Then print nn more lines, the ii -th of them should contain two space separated positive integers aiai and bibi not exceeding 107107 . All pairs (ai,bi)(ai,bi) must be distinct, and, for each i[1,n]i∈[1,n] , the condition aibi=ciai⋅bi=ci must be met.

    Examples

    Input
    4
    1 3 3 7
    Output
    YES
    1 1
    1 3
    3 1
    1 7
    Input
    5
    3 1 3 3 7
    Output
    NO
    Input
    6
    9 10 9 10 9 10
    Output
    YES
    1 9
    1 10
    3 3
    5 2
    9 1
    2 5

    Note

    In the first example one of the possible testsets is (a1=1a1=1 , b1=1b1=1 ), (a2=1a2=1 , b2=3b2=3 ), (a3=3a3=3 , b3=1b3=1 ), (a4=1a4=1 , b4=7b4=7 ).

    In the second example a testset consisting of distinct tests doesn't exist.

    题意:给出n个数,让你将每个数都表示成两个数相乘,但是不能重复,(1*3和3*1不算重复)可以就输出结果,否则输出NO

    思路:对于给出的数里,相同的数我们可以一起处理,即可以先排序,然相同的数挨在一起,我们可以统计其个数,然后在这个数开方范围内寻找因子。最后统计该数出现的个数和式子数时候满足要求,即式子是否足够多。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n;
    
    struct E
    {
        int val;
        int index;
    } e[200005];
    
    bool cmp(E a,E b)
    {
        return a.val < b.val;
    }
    
    int ll[200005];
    int rr[200005];
    int main()
    {
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&e[i].val);
            e[i].index = i;
        }
        sort(e+1,e+1+n,cmp);
        int cnt = 0;
        int flag = 0;
        for(int i=1; i<=n; i++)
        {
            int l=i,r=i;
            while(r+1<=n && e[r].val == e[r+1].val)
                r++;
            for(int j=1; j*j<=e[i].val; j++)
            {
                if(e[i].val % j == 0)
                {
                    ll[e[l].index] = j;
                    rr[e[l].index] = e[i].val / j;
                    l++;
                    if(l > r)break;
                    if(j * j != e[i].val)
                    {
                        ll[e[l].index] = e[i].val / j;
                        rr[e[l].index] = j;
                        l++;
                        if(l > r)break;
                    }
                }
            }
            if(l <= r)
            {
                flag = 1;
                break;
            }
            i = r;
        }
        if(flag)printf("NO
    ");
        else
        {
            printf("YES
    ");
            for(int i=1;i<=n;i++)
            {
                printf("%d %d
    ",ll[i],rr[i]);
            }
        }
    }
    View Code
  • 相关阅读:
    Swift中的设计模式
    ios应用view之间数据传递的方式
    关于iOS多线程,你看我就够了
    iOS开发-21UINavigationController导航控制器初始化 导航控制器栈的push和pop跳转理解
    iOS蓝牙4.0开发例子
    工作记录8:iOS 传值问题总结(7种传值完美介绍)
    iOS 各种传值方式
    iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
    Swift类与结构、存储属性、计算属性、函数与方法、附属脚本等
    源码推荐(7.17):不规则按钮类似于遥控器按钮,一个可以最大程度简化PageView与TabView切换的第三方框架
  • 原文地址:https://www.cnblogs.com/iwannabe/p/10559761.html
Copyright © 2011-2022 走看看