题意:n表示需要连接在一起的天数,r表示每周可以有的最大天数,即每周天数可以为k(1 < k < r)。以自己定义的每周天数制成(方格表)日历,即每行只能有k个格子,且在日历上将连续的天数涂色(涂色的图形必须是一个整体),求涂色部分可以构成的不同图形个数。
题解:数学 ① n > r 显而易见,ans = 1 + 2 + … + r ② n ≤ r 那么每周天数最多就是n,再往后就是重复的了,k < n时,跟①一样;当k = n时,能构造的整体图形只有一个,ans = 1 + 2 + … + (n - 1) + 1
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<queue> #include<stack> #include<cmath> #include<vector> #include<fstream> #include<set> #include<map> #include<sstream> #include<iomanip> #define ll long long using namespace std; int t; ll n, r; int main() { scanf("%d", &t); while (t--) { scanf("%lld%lld", &n, &r); if (n > r) printf("%lld\n", (1 + r) * r / 2); else printf("%lld\n", (1 + n - 1) * (n - 1) / 2 + 1); } return 0; }