2020牛客多校第七场B Mask Allocation

比赛题目链接
题目介绍
Nowadays, the Kingdom of Dreamgrid is suffering from a national pandemic. Fortunately, president Baobao is working effectively with the Center for Disease Control (CDC) and they are trying their best to make everything under control.

President Baobao has received n×m medical masks from his friend Reku, an extremely rich billionaire. As the chief of the CDC, you are required to allocate these masks properly. There are 2 kinds of hospitals in the Kingdom of Dreamgrid, n senior hospitals for critically ill patients and m mobile cabin hospitals for patients with mild symptoms.

Before allocating them to hospitals, you have to pack them into boxes. Please note that boxes must not be opened in order to prevent contamination and you only know these boxes will be allocated to either senior hospitals or mobile cabin hospitals. That is to say, there should be a way of dividing masks boxes into m groups of n masks, and a way of dividing into n groups of m masks.

You want the number of boxes to be minimal and please also provide a lexicographically greatest sequence of the numbers of masks in boxes. We say a sequence a is lexicographically greater than another b of the same length if there exists an integer i, such that
a j=b j, for all j < i; and ai > bi
输入
There are multiple test cases. The first line of the input contains an integer T (1≤T≤100), indicalting the number of test cases.
For each test case, the only line of the input contains two integers n,m (1≤n,m≤1e4 ), representing the numbers of senior hospitals and mobile cabin hospitals.
输出
For each test case, please output two lines. The first line should contain a single integer k in the first line, indicating the minimum number of boxes. In the second line, please output k integers, denoting the lexicographically greatest sequence.

下面是ac代码:

#include 
#define rep(i,a,b) for(int i=a;i
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
const ll mod = 1e9 + 7;
ll m , n  ;
ll a[maxn] ;
int main()
{
	T
	{
		ll s = 0 ;
		ll x = 0 ;
		scanf("%lld%lld",&n,&m) ;
		while(m!=n){
			if(n  < m)	swap(n,m) ;
			s+= m ;
			a[x] = m ;
			x++ ;
			int r = n - m ;
			n =m ;
			m = r ;
		}
		s+=m ;
		a[x] = m ;
		printf("%d\n",s);
		for(int i = 0 ; i <= x ; i++){
			if(i==x){
				for(int j=0;j<a[i]-1;j++)
					printf("%lld ",a[i]);
				printf("%lld\n",a[i]) ;
            }
            else
            {
              for(int j=0;j<a[i];j++)
					printf("%lld ",a[i]);
            }
		} 
	}
	return 0 ;
}

你可能感兴趣的:(牛客多校,基础)