2020-11-01

链接:https://ac.nowcoder.com/acm/contest/8688/A
来源:牛客网

题目描述
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<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll ans[N];
ll a[5];
int main() {
	ll d,ansp=0;
	cin>>a[0]>>a[1]>>a[2]>>d;
	sort(a,a+3);
	for(int i=0; i<=d; i++) {
		if(a[1]>=i)
			ans[i]=i+1;
		else {
			if(a[2]>=i)
				ans[i]=a[1]+1;
			else if(a[2]+a[1]>=i)
				ans[i]=a[1]-(i-a[2])+1;
		}
	}
	for(int i=0; i<=d; i++) {
		ll p=min(a[0]+1,d-i+1);
		ansp+=p*ans[i];
	}
	cout<<ansp<<endl;
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值