2018.5.31 Weird Requirements

题意:

It is hard to find teams for students to participate in ACM contests, most students have weird requirements for their team mates. For example, Ziad wants the GCD of all his team mate's ratings on all famous websites to be exactly   X  and the LCM of his ratings to be exactly   Y.

There are N famous competitive programming websites. Ramzi's rating on the ith website is Ai. Ramzi is very experienced, in one contest, he can change his rating on one website to any other value. What is the minimum number of contests that Ramzi must participate in, so that Ziad accepts him as his team mate?

Input

The first line contains one integer T, the number of test cases.

Each test case starts with one line containing three space-separated integers NX, and Y, the number of famous websites, the required GCD value, and the required LCM value respectively. (1 ≤ N ≤ 105) (1 ≤ X, Y ≤ 109)

The next line contains N space-separated integers Ai, Ramzi's rating on all websites. (1 ≤ Ai ≤ 109)

Output

For each test case print one line containing one integer, the minimum number of contests Ramzi must participate in so that he can become Ziad's team mate.

If it is impossible for Ziad to accept him as his team mate , print -1.


感想:

这是跟着下个周要去邀请赛的大佬一起打的比赛,一个人VS人家一个队,凉凉。。
这算是个思维题,就用了GCD,题意也比较难以理解,还因为 漏掉了一个特别情况,一直WA在第二组。。。一个半小时终于调通。。感觉还是可以的。
代码:
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 7901
int T,k,N,X,Y,pos[100005];
int ans,anss,tt,wt;
int GCD(int x,int y)
{
    if(x%y==0) return y;
    return GCD(y,x%y);
}
int main()
{
    cin>>T;
    wt=-1;
    while(T--)
    {
        k=0;
        ans=-1;
        tt=0;
        anss=-1;
        scanf("%d%d%d",&N,&X,&Y);
        if(Y%X!=0||(N==1&&(X!=Y))) {
            for(int i=1;i<=N;i++)
            scanf("%d",&pos[i]);
        printf("-1\n");

        }
        else
        {
            for(int i=1;i<=N;i++)
           {
               scanf("%d",&pos[i]);
               if((pos[i]%X!=0)||(Y%pos[i]!=0)) {k++;}
               else
               {
                   if(ans==-1) ans=Y/pos[i];
                   else ans=GCD(ans,Y/pos[i]);
                   if(anss==-1) anss=pos[i];
                   else
                   {
                       anss=GCD(anss,pos[i]);
                   }
               }
           }
           if(ans!=1) tt++;
           if(anss!=X) tt++;
           if(N==1&&X==Y&&k==1) printf("1\n");
           else if(k>=tt) printf("%d\n",k);
           else
           {
               printf("%d\n",tt<=N?tt:wt);
           }

        }

    }
}

News 26.03.2015 Knowledge base file for Delphi XE3 freely available. 23.03.2015 Knowledge base file for Delphi XE and Delphi XE2 freely available. 16.03.2015 Latest version is available for download. What is IDR? IDR (Interactive Delphi Reconstructor) – a decompiler of executable files (EXE) and dynamic libraries (DLL), written in Delphi and executed in Windows32 environment. The program firstly is intended for the companies, engaged by development of anti-virus software. It can also help programmers to recover lost source code of programs appreciably. The current version of the program can process files (GUI and console applications), compiled by Delphi compilers of versions Delphi2 – Delphi XE3. Final project goal is development of the program capable to restore the most part of initial Delphi source codes from the compiled file but IDR, as well as others Delphi decompilers, cannot do it yet. Nevertheless, IDR is in a status considerably to facilitate such process. In comparison with other well known Delphi decompilers the result of IDR analysis has the greatest completeness and reliability. Moreover interactivity does work with the program comfortable and (we shall not be afraid of this word) pleasant. IDR make static analysis (analyzed file is not loaded to memory and executed) that allows to safely investigate viruses, trojans and other malware applications, those which executing is dangerous or is not desirable. The program does not require any installation activity and does not do any records in Windows registry. Below screenshot of IDR main window is shown. You can find examples of IDR working results on separate page. For detailed acquaintance with opportunities IDR there is a help file in format CHM which can be downloaded on page of download or directly from this link.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值