题解:P16242 【MX-X27-T3】Sakura
友情提示:本题不需要差分约束。
考虑每片梅花按照速度从大到小排序后,对应序列上哪些值。
对于
考虑亮亮之间如何刻画速度比较。
对于两只梅花,速度分别为
那么第一个梅花下降
我们假设
考虑第一只下降
于是我们只能得到比值,尝试得到。
还是对于上面的
如果
然而我们只知道存在一对合法
但是我们上面知道是
于是我们对所有
考虑为了
于是序列信息完全转成了每个花和
考虑
于是
算完最小公倍数
然后别的花速度确定了。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int B=10000002;
int p;
int g[1009];
int a[1000009];
int c[1000009];
struct fs{
int x,y;
bool operator<(const fs dd)const{
return x*dd.y<dd.x*y;
}
bool operator>(const fs dd)const{
return x*dd.y>dd.x*y;
}
bool operator<=(const fs dd)const{
return x*dd.y<=dd.x*y;
}
bool operator>=(const fs dd)const{
return x*dd.y>=dd.x*y;
}
}an[1009];
void _main(){
int n,h;
cin>>n>>h;
p=h;
for(int i=1;i<=n;i++){
an[i]={1,1};
}
for(int i=0;i<=h-1;i++){
g[i]=0;
}
for(int i=1;i<=n*h;i++){
cin>>a[i];
g[a[i]]++;
c[i]=g[a[i]];
if(c[i]==1){
p=a[i];
}else{
an[c[i]]=min(an[c[i]],{h-a[i],h-p});
}
}
for(int i=1;i<=n;i++){
int g;
g=__gcd(an[i].x,an[i].y);
an[i].x/=g,an[i].y/=g;
}
int cc;
cc=1;
for(int i=1;i<=n;i++){
cc=cc*an[i].y/__gcd(cc,an[i].y);
}
cc=h/cc*cc;
for(int i=1;i<=n;i++){
cout<<cc/an[i].y*an[i].x<<" ";
}
cout<<endl;
}
signed main(){
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
_main();
}
return 0;
}