Easy Equation
時間限制:C/C++ 2秒,其他語言4秒
空間限制:C/C++ 524288K,其他語言1048576K
64bit IO Format: %lld
題目描述
You are given four positive integers 𝑥, 𝑦, 𝑧, 𝑘, please help little M calculate the number of equations 𝑥 + 𝑦 + 𝑧 = 𝑘 when 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑
輸入描述:
Four integers 𝑎, 𝑏, 𝑐, 𝑑 (0 ≤ 𝑎, 𝑏, 𝑐, 𝑑 ≤10^610
6
)
輸出描述:
One integer the number of equations.
It is guaranteed that all the answers fit 64-bit integer.
示例1
輸入
3 3 3 3
輸出
20
示例2
輸入
300 300 300 300
輸出
4590551
示例3
輸入
0 0 0 0
輸出
1
示例4
輸入
12345 12345 12345 12345
輸出
313713415596

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d;
ll ans=0;
cin>>a>>b>>c>>d;
ll sum1=min(a+b,d);
for(int i=0;i<=sum1;i++)
{
if(i<=min(a,b))
ans+=(i+1)*(min(sum1-i,c)+1);
else if((i<max(a,b))&&(i>min(a,b)))
ans+=(min(a,b)+1)*(min(sum1-i,c)+1);
else if(i>=max(a,b)&&(i<=min(a+b,d)))
ans+=(min(a,b)+max(a,b)+1-i)*(min(sum1-i,c)+1);
}
cout<<ans<<endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/202224.html
標籤:其他
上一篇:2020ICPC亞洲網上區域賽模擬賽I題Character Wheels(模擬題)
下一篇:2.2.2 定點數的移位運算
