[FJCPC 2026] 抱歉,这没有集美 题解
AI 使用说明
- 本文的作者贡献大于AI的贡献
- AI仅润色了文章,渲染了markdown格式
- 样例验证为AI所加
题目大意
给定 个人(其中 个女生),分别报名 ACM 竞赛和天梯赛。在总队伍数最少的前提下,求两种竞赛各自最多能组成多少支“女队”。
- ACM:每队 人,全员女生即为女队。
- 天梯赛:每队 人,至少 名女生即为女队。
解题思路
核心约束
“总队伍数最少”是全局硬约束,女队最大化必须在该约束下进行,不能脱离总队伍数单独计算。
ACM 竞赛
- 最少总队伍数:。
- 男生最少占用队伍数:将 个男生尽量塞满(每队 3 人),占用 支队伍。
- 女队上界:剩余队伍全部分配给女生,即 。同时女队数不超过女生总数 (每支女队至少 1 人)。
- 公式:
天梯赛
- 最少总队伍数:。
- 女生组队上限:每支女队至少消耗 6 名女生,故上限为 。
- 公式:
代码实现
//#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define F(i,j,k,l) for(int i=(j);i<=(k);i+=(l))
#define f(i,j,k,l) for(int i=(j);i>=(k);i-=(l))
// #ifdef __unix__
// #define gc getchar_unlocked
// #define pc putchar_unlocked
// #else
// #define gc _getchar_nolock
// #define pc _putchar_nolock
// #endif
#define W(i) while(i)
#define A auto
#define ot float
#define FO(x,a) for(int x:a)
#define Fo(x,a) for(A x:a)
#define el "\n"
#define ull unsigned long long
#define ll long long
#define in __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define dle double
#define ld long double
#define imax INT_MAX
#define imin INT_MIN
#define llmax LONG_LONG_MAX
#define llmin LONG_LONG_MIN
#define debug(x) cerr<<#x<<" "<<x<<"\n";
const int N=1e6+10,M=1<<20;
char buf[M],*p1=buf,*p2=buf,out[M],*p3=out;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,M,stdin)),*p1++)
#define gc() (p1==p2?(p2=(p1=buf)+fread(buf,1,M,stdin),p1==p2?EOF:*p1++):*p1++)
//#define flush() do{fwrite(out,1,p3-out,stdout);p3=out;}while(0)
//#define pc(c) do{if(p3==(out+M)) flush();*p3++=(c);}while(0)
#define flush() (fwrite(out,1,p3-out,stdout),p3=out)
#define pc(c) (p3==(out+M)?(flush(),*p3++=(c)):*p3++=(c))
inline long long read(){
long long x=0,f=1;
char ch=gc();
W(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
W(isdigit(ch)){
x=x*10+(ch-'0');
ch=gc();
}
return x*f;
}
inline string rsline(){
string s;
char ch=gc();
W(ch!='\n'&&ch!='\r'&&ch!=EOF) s+=ch,ch=gc();
return s;
}
inline string rs(){
string s;
char ch=gc();
W(ch==' '||ch=='\n'||ch=='\r'||ch=='\t') ch=gc();
W(ch!=' '&&ch!='\n'&&ch!='\r'&&ch!='\t'&&ch!=EOF) s+=ch,ch=gc();
return s;
}
inline void write(long long x){
if(x<0){
pc('-');
x=-x;
}
if(x==0){
pc('0');
return;
}
char s[25];
int len=0;
W(x){
s[len++]=char('0'+x%10);
x/=10;
}
W(len) pc(s[--len]);
return;
}
inline void ws(string &s){
for(auto x:s) pc(x);
return;
}
int n,m;
inline void pre(){
}
inline void input(){
n=read(),m=read();
}
inline void output(){
// ACM: min(m, ceil(n/3) - ceil((n-m)/3))
int high=(n+2)/3;// ceil(n/3)
int boy=(n-m+2)/3;// ceil((n-m)/3)
int girl=(m+2)/3;// ceil(m/3),冗余安全上界
write(min(high-boy,girl));
pc(' ');
// 天梯: min(floor(m/6), ceil(n/10))
int high2=(n+9)/10;// ceil(n/10)
int girl2=m/6;// floor(m/6)
write(min(high2,girl2));
pc('\n');
}
inline void solve(){
pre();
input();
output();
return;
}
int main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);cin.tie(0);
int _=1;_=read();
while(_--) solve();
flush();
return 0;
}关键细节说明
| 表达式 | 含义 | 备注 |
|---|---|---|
(x+k-1)/k | 整数向上取整经典写法 | |
high-boy | ACM 女队理论最大值 | 已隐含 ,额外取 min 为防御性编程 |
m/6 | C++ 整数除法天然向下取整 |
复杂度分析
- 时间复杂度:
- 空间复杂度:
样例验证
| ACM 计算过程 | 天梯计算过程 | 输出 | ||
|---|---|---|---|---|
| 10 | 6 | 2 1 | ||
| 20 | 12 | 4 2 | ||
| 7 | 7 | 3 1 |
与题目样例完全一致 ✓