戴敏昊的博客
牛课多校补题(7)
一共就过了一道签到题真的难受
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 \times mn×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_jfor all j < i; and
a_i > b_i.
输入描述:
There are multiple test cases. The first line of the input contains an integer T(1≤T≤100), indica1ting the number of test cases.
For each test case, the only line of the input contains two integers n,m (1≤n,m≤10^ 4 ), 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.
示例1
输入
2
5 4
3 3
输出
8
4 4 4 4 1 1 1 1
3
3 3 3
题解
有n* m个口罩,需要要把它们装到一些箱子里面,要使箱子数尽可能少,并且满足两个条件,这些箱子可以分成m组,每组n个口罩,或者分成n组,每组m个口罩。
分配方案其实就是一个迭代的过程。为了使得箱子数最少,每个箱子就应该尽可能的多装。每次优先装min(n,m)个箱子,每个箱子装min(n,m)。装了这些之后,就还剩下(max(m,n)-min(n,m))*min(n,m)个,对于剩下的这些口罩我们可以继续重复上述操作。
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
int ans[1000001], cnt;
void gcd(int n,int m)
{if(n<m) swap(n, m);if(m==0) return;for(int i=0; i<m; i++) ans[cnt++] = m;gcd(n - m, m);
}
int main()
{int t,n,m,i;scanf("%d",&t);while(t--){memset(ans, 0, sizeof(ans));cnt = 0;scanf("%d%d", &n, &m);gcd(n, m);printf("%d\n", cnt);for(i=0; i<cnt; i++) printf("%d ", ans[i]);printf("\n");}return 0;
}
D Fake News
上题
题目描述
McDonald Thumb, the greatest president ever in the history of the Great Tokitsukaze Kingdom has held his 100th press conference about the global pandemic after making his 1000000th tweets with his smartphone. With a big smile on his face, Mr. Thumb said that nobody knows math more than he does.
‘I learn math since I was born and I am very good at it’, said Mr. Thumb. ‘People keep asking me why I know math so much and I sometimes find myself having those amazing ideas about math.’
‘For example?’, asked by a reporter.
‘Oh you, I know you! Fake news! You and your agency always produce fake news!’, replied angrily by Mr. Thumb. ‘Let me teach you something, do you know if you add up the squares of numbers from 1 to n, the sum will never be a square number?’
As another reporter in that press conference, you also wondering that given n, whether 从1到n的k^2的和is a square number. Specifically, we regard a positive number x as a square number when there exists an integer y satisfying y^2=x
输入描述:
There are multiple test cases. The first line of the input contains an integer T(1≤T≤10^ 6 ) indicating the number of test cases. For each test case, the first line contains one integers n(1≤n≤10 ^15 ).
输出描述:
If the sum is a square number, please output ‘Fake news!’ in one line. Otherwise, please output ‘Nobody knows it better than me!’ instead.
示例1
输入
5
1
2
3
4
5
输出
Fake news!
Nobody knows it better than me!
Nobody knows it better than me!
Nobody knows it better than me!
Nobody knows it better than me!
题解
唯一过得一个
判断平方数列和是否是一个平方数。看看几个数,就会发现除了1和24。其他情况都不是平方数直接暴力解决
#include<stdio.h>
#include<math.h>
int main(){int t;scanf("%d",&t);while(t--){long long n;double y;scanf("%lld",&n);y=sqrt((n+1)*(2*n+1)*n/6); if(y==floor(y)) printf("Fake news!\n");else printf("Nobody knows it better than me!\n");}
}
H题 Dividing(太难了)
上题
题目描述
The following rules define a kind of integer tuple – the Legend Tuple:
(1, k) is always a Legend Tuple, where k is an integer.
if (n, k) is a Legend Tuple, (n + k, k) is also a Legend Tuple.
if (n, k) is a Legend Tuple, (nk, k) is also a Legend Tuple.
We want to know the number of the Legend Tuples (n, k) where 1≤n≤N,1≤k≤K.
In order to avoid calculations of huge integers, report the answer modulo 10^9+7instead.
输入描述:
The input contains two integers N and K, 1≤N,K≤10 ^12 .
输出描述:
Output the answer modulo 10^9+7
示例1
输入
3 3
输出
8
示例2
输入
3 9
输出
14
题解
题目大意:
(1,k)是传奇元组,如果 (n,k)是传奇元组 那么 (nk,k)和(n+k,k)也是传奇元组给定N,K 求有多少个(n,k)是传奇元组,其中 1 <= n <= N , 1<= k <= N,答案取模1e9 + 7。
题解:
通过题目所给的条件我们可以看出,当n = 1时一定是传奇元组,(1,k)变为(n,k)时分为以下两种情况:
1:(nk,k) -> n是k的倍数。
2:(xk + 1,k)-> n-1是k的倍数。
所以就得到以下结论:n = xk 或 n-1 = xk,但是要注意,当n <= k时算到底就ok,但当k > n时就需要算到k就截断,即右端点为min(n / (n / i ), k),接下来就是套整除分块的模板。
#include <iostream>
using namespace std;
typedef long long dmh;
const dmh mod = 1e9 + 7;
dmh ans,k;
void sb(dmh n)
{for(dmh i = 2,j; i <= n && i <= k; i = j + 1){j = min(n / (n / i) , k);ans = (ans + ( j - i + 1) % mod * (n / i) % mod) % mod;}
}
int main()
{dmh n;cin >> n >> k;sb(n);sb(n - 1);ans = (ans + (n + k - 1)) % mod;cout << ans << endl;return 0;
}