Is there a detailed analysis of the football season in CF 1244 C?

2026-04-16 23:591阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计322个文字,预计阅读时间需要2分钟。

Is there a detailed analysis of the football season in CF 1244 C?

C+ - The Football Season 首先考虑求解方程 [x + w * y + d=p],若存在一组解 [x_0, y_0],则满足:

\[\begin{cases}x_0 + y_0=kw + v \\x_0 + y_0 \times d=p\end{cases}\]

则有以下推导:

\[x_0 \times w + y_0 \times d=p \Rightarrow x_0 \times w + (kw + v) \times d=p \Rightarrow \text{}\]

C - The Football Season

先考虑求解
\[ x\times w + y\times d=p \]
若存在一组解
\[ \begin{cases} x_0\y_0 = kw + v & (0<v<w)\\end{cases} \]

\[ x_0 \times w + y_0 \times d = p\\Rightarrow x_0 \times w + (kw+v)\times d = p\\Rightarrow x_0\times w + k\times w\times d + v\times d = p\\Rightarrow (x_0+k\times d)\times w + v\times d = p ~~~~~ \]
所以一定存在一组解
\[ \begin{cases} x = x_0 + k\times d\y = v \end{cases} \]
并且由于\(w> d\)


\[ x + y = x_0 + k\times d + v < x_0 + k\times w + v \]
前者比后者更有可能成为答案

所以直接枚举所有的v即可

#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,p,w,d; int main(){ cin >> n >> p >> w >> d; for(ll v=0;v<w;v++){ if((p - v * d) % w == 0){ ll x = (p - v * d) / w; if(x >= 0 && x + v <= n){ printf("%lld %lld %lld\n",x,v,n-x-v); return 0; } } } puts("-1"); return 0; }

Is there a detailed analysis of the football season in CF 1244 C?

本文共计322个文字,预计阅读时间需要2分钟。

Is there a detailed analysis of the football season in CF 1244 C?

C+ - The Football Season 首先考虑求解方程 [x + w * y + d=p],若存在一组解 [x_0, y_0],则满足:

\[\begin{cases}x_0 + y_0=kw + v \\x_0 + y_0 \times d=p\end{cases}\]

则有以下推导:

\[x_0 \times w + y_0 \times d=p \Rightarrow x_0 \times w + (kw + v) \times d=p \Rightarrow \text{}\]

C - The Football Season

先考虑求解
\[ x\times w + y\times d=p \]
若存在一组解
\[ \begin{cases} x_0\y_0 = kw + v & (0<v<w)\\end{cases} \]

\[ x_0 \times w + y_0 \times d = p\\Rightarrow x_0 \times w + (kw+v)\times d = p\\Rightarrow x_0\times w + k\times w\times d + v\times d = p\\Rightarrow (x_0+k\times d)\times w + v\times d = p ~~~~~ \]
所以一定存在一组解
\[ \begin{cases} x = x_0 + k\times d\y = v \end{cases} \]
并且由于\(w> d\)


\[ x + y = x_0 + k\times d + v < x_0 + k\times w + v \]
前者比后者更有可能成为答案

所以直接枚举所有的v即可

#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,p,w,d; int main(){ cin >> n >> p >> w >> d; for(ll v=0;v<w;v++){ if((p - v * d) % w == 0){ ll x = (p - v * d) / w; if(x >= 0 && x + v <= n){ printf("%lld %lld %lld\n",x,v,n-x-v); return 0; } } } puts("-1"); return 0; }

Is there a detailed analysis of the football season in CF 1244 C?