Judgement subgroup SDUT discrete mathematics OJ4172

Judgement subgroup Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description Given a finite group s and one of its subsets S1,...
Judgement subgroup

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

Given a finite group s and one of its subsets S1, the binary operation * on S is defined as the modular M addition operation to determine whether the subset is a subgroup of S. (definition of subgroup: let H be a non empty subset of group G. If h constitutes a group under the operation of G, then h is a subgroup of G)

Input

For multiple input groups, the first behavior is the number of elements of finite group S, n (0 < = n < 100), m (0 < = m < 100), and the number of elements of its subset, m (0 < = m < 100) (elements may be repeated)
The number of n in the second row is the element X (0 < = x < 100) contained in the finite group, and the number of m in the third row is the element Y (0 < = y < 100) contained in the subset.
output
If the subset is a subgroup of S, output "YES", otherwise output "NO" (without quotation marks)

Output

If the subset is a subgroup of S, output "YES", otherwise output "NO" (without quotation marks)

Sample Input

8 7 7 0 1 2 3 4 5 6 6 0 1 2 3 4 5 6 10 7 7 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 9

Sample Output

YES NO
#include<stdio.h> #include <string.h> #define ll long long int arr[110]; int vis[110]; int num[110]; int b[110]; int main() { int n, m, q; while(~scanf("%d %d %d", &n, &m, &q)) { int flag = 1; memset(b,0,sizeof(b)); memset(vis,0,sizeof(vis)); memset(num,-1,sizeof(num)); memset(arr,-1,sizeof(arr)); for(int i = 1; i <= n; i++) { scanf("%d", &arr[i]); } for(int i = 1; i <= q; i++) { scanf("%d", &b[i]); vis[b[i]] = 1; } if(vis[0]==0) { flag = 0; } num[0] = 0; for(int i = 1; i <= n; i++) { for(int j = i+1; j <= n; j++) { if(vis[(b[i] + b[j]) % m] && (b[i] + b[j]) % m == 0) { num[b[i]] = b[j]; num[b[j]] = b[i]; break; } } } for(int i = 1; i <= n; i++) { if(num[b[i]] == -1) { flag = 0; } } if(!flag) { printf("NO\n"); } else { printf("YES\n"); } } return 0; }

7 November 2019, 11:29 | Views: 9475

Add new comment

For adding a comment, please log in
or create account

0 comments