网易互娱笔试
第一题 模拟AC¶
![[Pasted image 20250322213000.png]]
第二题 2048 AC,大模拟¶
![[Pasted image 20250322221804.png]]![[Pasted image 20250322221816.png]]![[Pasted image 20250322221842.png]]![[Pasted image 20250322221850.png]]
第三题 计算四元一次方程¶
![[Pasted image 20250322232101.png]]
代码:暴力四循环,超时来不及做完了
int a, b, c, d, N;
vector<int> ans;
bool TwoSum(const int sum)
{
int cur = 0;
while (c * cur <= 2500)
{
int w = (N - c * cur) / d;
if(w> 2500) continue;
if ((N - c * cur) % d == 0)
{
ans.push_back(cur);
ans.push_back(w);
return true;
}
cur++;
}
return false;
}
bool ThreeSum(const int sum)
{
int cur = 0;
while (b * cur <= 2500)
{
if (TwoSum(sum - b * cur))
{
ans.push_back(cur);
return true;
}
cur++;
}
return false;
}
bool FourSum(const int sum)
{
int cur = 0;
while (a * cur <= 2500)
{
if (TwoSum(sum - a * cur))
{
ans.push_back(cur);
return true;
}
cur++;
}
return false;
}
int main() {
cin >> a >> b >> c >> d >> N;
if (N % d == 0)
{
cout << "0 0 0 " << N / d;
}
else if (TwoSum(N))
{
cout << "0 0 " << ans[0] << " " << ans[1];
}
else if (ThreeSum(N))
{
cout << "0 " << ans[2]<<" " << ans[0] << " " << ans[1];
}
else if (FourSum(N))
{
cout << ans[3]<< " " << ans[2] << " " << ans[0] << " " << ans[1];
}
}
// 64 位输出请用 printf("%lld")
看网上题解说是: - 哈希表存两重循环的值+两重循环