zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 63 (Rated for Div. 2) C. Alarm Clocks Everywhere gcd

    题意:给出一个递增的时间序列a  给出另外一个序列b  (都是整数)      

    以b中任选一个数字作为间隔  自己从1开始任选一个时间当成开始时间

    输出选择的数字标号以及 开始时间

    思路  直接求间隔的公共gcd 然后看 给的序列b 中有没有数 b[i]|gcd 即可

    如果没有则输出-1

     1 #include<bits/stdc++.h>
     2 #define mkp make_pair
     3 #define pb push_back
     4 #define F first
     5 #define S second
     6 using namespace std;
     7 typedef long long ll;
     8 const int maxn=3e5+5;
     9 ll a[maxn],b[maxn];
    10 vector<pair<ll,ll> >v;
    11 ll gcd(ll a,ll b){
    12     return b==0?a:gcd(b,a%b);
    13 }
    14 int main(){
    15     int n,m;
    16     scanf("%d%d",&n,&m);
    17     ll tmp=1;
    18 
    19     for(int i=1;i<=n;i++)
    20     {
    21         scanf("%lld",&a[i]);
    22 
    23     }
    24     for(int i=1;i<=n-1;i++){
    25         b[i]=a[i+1]-a[i];
    26     }
    27     tmp=b[1];
    28     for(int i=2;i<=n-1;i++){
    29         tmp=gcd(b[i],tmp);
    30     }
    31     //cout<<tmp<<endl;
    32     int ok=0;
    33     for(int i=1;i<=m;i++)
    34     {
    35         ll zz;
    36 
    37         scanf("%lld",&zz);
    38         if(ok)continue;
    39         if(tmp%zz==0){
    40                 cout<<"YES\n";
    41             cout<<a[1]<<" "<<i<<endl;
    42         ok=1;
    43         }
    44         //v.pb(mkp(zz,1ll*i));
    45         //cout<<i<<endl;
    46     }
    47     if(!ok)
    48     cout<<"NO\n";
    49 
    50 
    51     /*sort(v.begin(),v.end());
    52 
    53 
    54     int p=lower_bound(v.begin(),v.end(),mkp(tmp,1ll*0))-v.begin();
    55     if(p>=v.size()){
    56         cout<<"NO\n";
    57         return 0;
    58     }
    59     else {
    60         if(v[p].F!=tmp){
    61             //    cout<<v[p].F<<endl;
    62             cout<<"NO\n";
    63             return 0;
    64         }
    65         else{
    66             cout<<"YES\n";
    67             cout<<a[1]<<" "<<v[p].S<<endl;
    68         }
    69     }*/
    70     return 0;
    71 }
    View Code
  • 相关阅读:
    Attention in Super-Resolution[阅读笔记][RCAN][SAN][HAN]
    docker安装oracle11g
    timeSetEvent
    有意思的中文转拼音用来区分26个小类用于缩小列表大小减少循环
    jsp中的out.println爆红
    记一次Jdbc的配置文件无法加载
    Java静态块
    解决Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA报错
    html5,图文混排垂直居中
    Sql server语句执行时间查看
  • 原文地址:https://www.cnblogs.com/ttttttttrx/p/10791197.html
Copyright © 2011-2022 走看看