zoukankan      html  css  js  c++  java
  • ZOJ18th省赛 Lucky 7

    [线上网址](http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=378)

    BaoBao has just found a positive integer sequence $a_1, a_2, dots, a_n$ of length $n$ from his left pocket and another positive integer $b$ from his right pocket. As number 7 is BaoBao's favorite number, he considers a positive integer $x$ lucky if $x$ is divisible by 7. He now wants to select an integer $a_k$ from the sequence such that $(a_k+b)$ is lucky. Please tell him if it is possible.

    Input
    There are multiple test cases. The first line of the input is an integer (T) (about 100), indicating the number of test cases. For each test case:

    The first line contains two integers (n) and (b) ((1 le n, b le 100)), indicating the length of the sequence and the positive integer in BaoBao's right pocket.

    The second line contains (n) positive integers (a_1, a_2, dots, a_n) ((1 le a_i le 100)), indicating the sequence.

    Output
    For each test case output one line. If there exists an integer (a_k) such that (a_k in {a_1, a_2, dots, a_n}) and ((a_k + b)) is lucky, output "Yes" (without quotes), otherwise output "No" (without quotes).

    Sample Input
    4
    3 7
    4 5 6
    3 7
    4 7 6
    5 2
    2 5 2 5 2
    4 26
    100 1 2 4
    Sample Output
    No
    Yes
    Yes
    Yes
    Hint
    For the first sample test case, as 4 + 7 = 11, 5 + 7 = 12 and 6 + 7 = 13 are all not divisible by 7, the answer is "No".

    For the second sample test case, BaoBao can select a 7 from the sequence to get 7 + 7 = 14. As 14 is divisible by 7, the answer is "Yes".

    For the third sample test case, BaoBao can select a 5 from the sequence to get 5 + 2 = 7. As 7 is divisible by 7, the answer is "Yes".

    For the fourth sample test case, BaoBao can select a 100 from the sequence to get 100 + 26 = 126. As 126 is divisible by 7, the answer is "Yes".

    #include<bits/stdc++.h>
    
    using namespace std;
    int a[1005];
    int main()
    {
        int t;;
        cin>>t;
        while(t--){
            int f=0;
            int n,k;
            cin>>n>>k;
            for(int i=0;i<n;i++){
                cin>>a[i];
                if((a[i]+k)%7==0) f=1;
            }
            f?puts("Yes"):puts("No");
        }
    }
    
  • 相关阅读:
    Leetcode题库——7.反转整数
    (tomcat)tomcat启动过慢
    (tomcat)查看tomcat安装路径
    (JDK)cmd中只能执行java不能执行javac命令
    (课)学习进度报告二
    (数据导入)csv文件数据导入数据库
    (编码转换)转换文件编码
    (python开发)用cmd下载Python的第三方库所遇问题及解决方法
    (课)学习进度报告一
    (课)淘宝网质量属性场景
  • 原文地址:https://www.cnblogs.com/Roni-i/p/8970899.html
Copyright © 2011-2022 走看看