ZOJ 4036 Lucky 7

xiaoxiao2021-02-28  28

Description:

BaoBao has just found a positive integer sequence a 1 , a 2 , … … , a n a_{1},a_{2},……,a_{n} a1,a2,,an 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 lucky if is divisible by 7. He now wants to select an integer a k a_{k} ak from the sequence such that ( a k + b a_{k} + b ak+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 ≤ n , b ≤ 100 1 \le n,b \le 100 1n,b100 ), 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 , … … , a n a_{1},a_{2},……,a_{n} a1,a2,,an ( 1 ≤ n ≤ 100 1 \le n \le 100 1n100 ), indicating the sequence.

Output:

For each test case output one line. If there exists an integer a k a_{k} ak such that a k ∈ { a 1 , a 2 , … … , a n } a_{k} \in \{a_{1},a_{2},……,a_{n}\} ak{a1,a2,,an} and ( a k + b ) (a_{k} + b) (ak+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

题目连接

直接枚举判断是否存在 ( a i + b ) % 7 = = 0 (a_{i}+b) \% 7 == 0 (ai+b)%7==0

AC代码:

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> #include <iomanip> #include <cctype> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdlib> #include <sstream> #include <set> #include <map> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; const int INF = 0x3f3f3f3f; const int maxn = 1e2+5; const double eps = 1e-5; const double pi = asin(1.0)*2; const double e = 2.718281828459; int t; int n, b; int a; bool flag; int main() { //fropen("in.txt", "r", stdin); scanf("%d", &t); while (t--) { flag = 0; scanf("%d %d", &n, &b); for (int i = 0; i < n; ++i) { scanf("%d", &a); if (flag) { continue; } else { if ((a + b) % 7 == 0) { flag = 1; } } } if (!flag) { printf("No\n"); } else { printf("Yes\n"); } } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2623127.html

最新回复(0)