Single Round Match

Problem Description

Association for Couples Match (ACM) is a non-profit organization which is engaged in helping single people to find his/her other half. As November 11th is "Singles Day", on this day, ACM invites a large group of singles to the party. People round together, chatting with others, and matching partners. There are N gentlemen and M ladies in the party, each gentleman should only match with a lady and vice versa. To memorize the Singles Day, ACM decides to divide people into 11 groups, each group should have the same amount of couples and no people are left without the groups. Can ACM achieve the goal?

Input

The first line of the input is a positive integer T. T is the number of test cases followed. Each test case contains two integer N and M (0<=N, M<=101000), which are the amount of gentlemen and ladies. It is worth notice that N and M are really huge. You are suggested to input the number with string.

Output

For each test case, output “YES” if it is possible to find a way, output “NO” if not.

Sample Input

3
1 1
11 11
22 11

Sample Output

NO
YES
NO

题意:首先输入的第一个数代表数据的组数;
接下来的每一行都有两个数,数据很大,应该用字符储存;
首先输入的两个数都必须相等;然后都能被11整除;那么就输出YES,否则就输出NO;

# include<cstdio>
# include<iostream>
# include<cstring>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string n,m;
        cin>>n>>m;
        if(n!=m)
        {
            cout<<"NO"<<endl;
            continue;
        }
        else
        {
            int r=0,i;
            for(i=0;i<n.size();i++)
            {
                r=r*10+n[i]-'0';                   //每次取一位,-‘0’是转换类型;
                r%=11;
            }
            if(!r)    cout<<"YES"<<endl;
            else      cout<<"NO"<<endl;
        }
    }
    return 0;
}
### 图论算法竞赛及相关资源 图论作为计算机科学中的重要分支,在各类算法竞赛中占据着举足轻重的地位。以下是关于图论算法竞赛及其相关资源的详细介绍: #### 1. **TopCoder 中的图论问题** 在 TopCoder 的单轮比赛(Single Round Match, SRM)以及马拉松比赛中,经常会出现与图论相关的题目。这些问题可能涉及最短路径、最小生成树、网络流以及其他复杂的图结构优化问题[^1]。参赛者可以通过分析这些历史题目来提升自己对图论的理解。 #### 2. **Codeforces 和 AtCoder 上的图论专题** 除了 TopCoder 外,其他知名竞赛平台也提供了丰富的图论练习机会: - Codeforces 定期举办 Div.1 至 Div.3 不同级别的比赛,其中许多高分段题目都围绕复杂图论展开。 - AtCoder 则以其高质量的日本本土赛事闻名,尤其擅长设计基于动态规划和图论结合的问题[^2]。 #### 3. **经典图论算法学习资料** 对于希望深入研究图论的人来说,掌握一些基础理论至关重要: - Dijkstra 算法用于求解加权无向图上的单源最短路径问题; - Kruskal 和 Prim 方法分别实现贪心策略下的最小生成树构建过程; - Ford-Fulkerson 及 Edmonds-Karp 实现最大流计算功能[^3]。 ```python from collections import deque def bfs(graph, start_node): visited = set() queue = deque([start_node]) while queue: node = queue.popleft() if node not in visited: visited.add(node) neighbors = graph[node] for neighbor in neighbors: if neighbor not in visited: queue.append(neighbor) return visited ``` 上述代码展示了广度优先搜索 (BFS),这是探索连通性和距离测量的一种基本方法之一。 #### 4. **在线课程与书籍推荐** 为了更好地准备含图论成分的比赛项目,可以参考如下教育资源: - LeetCode 提供专门针对面试场景下常见数据结构操作训练营; - Coursera 平台上有由斯坦福大学开设的数据结构与算法专项系列课件; - CLRS《Introduction to Algorithms》一书详尽论述了众多核心概念和技术细节[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值