2020-5-16CF反思

CF涼了是顯然的,不然也不會寫這篇反思了。

開題很快 ACACAABB

到了 CC 的時候定睛一看

Like any unknown mathematician, Yuri has favourite numbers: A,B,CA, B, C and DD, where ABCDA≤B≤C≤D. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides x,yx, y and zz exist, such that AxByCzDA≤x≤B≤y≤C≤z≤D holds?

Yuri is preparing problems for a new contest now, so he is very busy. That’s why he asked you to calculate the number of triangles with described property.

The triangle is called non-degenerate if and only if its vertices are not collinear.

這段英文還是挺好懂的,就是說一個三角形三條邊分別爲 x,y,zx,y,z,有如下限制

AxByCzDA\le x \le B \le y\le C \le z\le D

顯然等於

AxBByCCzD A \le x \leq B\\ B \le y \leq C\\ C \le z \leq D

我們知道三角形要滿足 22 邊之和大於第 33 邊的。

所以 x+y>zx +y >z

我的做法是枚舉 x+yx+y,答案顯然 == x,yx,y 取值方案數 ×\times zz 的取值方案數

對於 x,yx,y 的取值方案數

我猛然想到《組合數學》上的內容,那是不久前剛學的所以現在十分記憶猶新,這種東西,我之前隻手算過,壓根兒也沒有想過有朝一日要用程序算出來。

回到題目

x+y=kx+y=k

x+y=kAxBByC x+y=k\\ A\leq x\leq B\\ B\leq y\leq C

我們去化解

x+y=kAB0xBA0yCB x+y=k-A-B\\ 0\leq x\leq B-A\\ 0\leq y\leq C-B

直接套無限多重集的多重集合的結論

n=kAB,X=BA,Y=CBn=k-A-B,X=B-A,Y=C-B

(n+21n)+(nA1+21nA1)+(nB1+21nB1)+(nAB2+21nAB2) \begin{pmatrix} n+2-1 \\ n \end{pmatrix}+ \begin{pmatrix} n-A-1+2-1 \\ n-A-1 \end{pmatrix}+ \begin{pmatrix} n-B-1+2-1 \\ n-B-1 \end{pmatrix}+ \begin{pmatrix} n-A-B-2+2-1 \\ n-A-B-2 \end{pmatrix}
我們來捋一捋

(n+1n)+(nAnA1)+(nBnB1)+(nAB1nAB2) \begin{pmatrix} n+1 \\ n \end{pmatrix}+ \begin{pmatrix} n-A \\ n-A-1 \end{pmatrix}+ \begin{pmatrix} n-B \\ n-B-1 \end{pmatrix}+ \begin{pmatrix} n-A-B-1 \\ n-A-B-2 \end{pmatrix}

然後這個東西巨難調,好不容易過了 33 個樣例自信滿滿地去交得到的確實 WAWA 聲一片。

這個題目的數據挺好造的,於是,我自信滿滿地打了個對拍,拍了幾組發現了幾個小問題逐一化解之後又交,又 WAWA

時間就像嘩啦啦的小溪總是在不經意間悄無聲息地流走了。時間所剩無幾,但我也一直在努力。

之後突然發現這 44 個組合數可以直接求,於是有改了改代碼,還是 WAWA

最後時刻,我把暴力一交發現暴力也 WAWA 了,我絕望了。

此時的我排名已來到了 5000+5000+ 名,DDEEFF都沒有碰過,但也不敢碰了,不停的死磕 CC

帶到倒計時種那蒼白而又孤獨的 00:0000:00 的到來,無助的我也嘆了嘆氣。

窗外一片黑燈瞎火,只有房間還閃爍着些許亮光,w33z8kqrqk8zzzx33\textsf{\textbf{\textcolor{black}{w}\textcolor{red}{33z8kqrqk8zzzx33}}} 怒切 AABBCCEE,更給孤獨的我的心頭埋上了一片陰霾。

風扇還在不停地轉動,我爲什麼就不能在繼續呢?

我開始了艱難而又漫長地調題,我在靜思中梳理,在思索中奮鬥,在 May/16/2020 22:52 我 ACAC 了,我的心猶如初生的旭日般明亮,ACAC 的代碼和比賽最後一次提交的代碼僅僅有一處不同,而正是這一處讓我的分數悄然無息而又微妙地發生了變化。

回首再去看看對拍的代碼

代碼:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>inline void read(T &FF) {
	T RR = 1; FF = 0; char CH = getchar();
	for (; !isdigit(CH); CH = getchar())if (CH == '-')RR = -1;
	for (; isdigit(CH); CH = getchar())FF = (FF << 1) + (FF << 3) + (CH ^ 48);
	FF *= RR;
}
template<typename T>inline void write(T FF) {
	if (FF < 0) {
		putchar('-');
		FF *= -1;
	}
	if (FF > 9)write(FF / 10);
	putchar(FF % 10 + 48);
}
template<typename T>inline void writen(T FF) {
	write(FF);
	puts("");
}
ll C(ll m, ll n) {
	if (n == 0)return 1;
	if (m <= 0 || n <= 0)return 0;
	ll ans = 1;
	for (ll i = 0; i < n; i++)ans *= m - i;
	for (ll i = 1; i <= n; i++)ans /= i;
	return ans;
}
ll work(ll i, ll l, ll r) {
	return min(i - l + 1, r - l + 1);
}
ll xxx(ll a,ll b,ll c,ll d){
	ll ans = 0;
	for (ll i = c + 1; i <= b + c; i++) {
		ll x = b - a, y = c - b;
		ll m = i - a - b;
		ll n = m + 1 - max((m - x), (ll)0) - max((m - y), (ll)0) + max((m - x - y), (ll)0);
		ans += max(n, (ll)0) * max((ll)0, work(i - 1, c, d));
	}
	return ans;
}
ll xx(ll a,ll b,ll c,ll d){
	ll ans=0;
	for(int x=a;x<=b;x++){
		for(int y=b;y<=c;y++){
			ans+=max((ll)0,work(x+y-1,c,d));
		}
	}return ans;
}
int main() {
	srand(time(NULL));
	while(1){
		ll a=1+rand()%20,b=a+rand()%20,c=b+rand()%20,d=c+rand()%20;
		if(xx(a,b,c,d)!=xxx(a,b,c,d)){
			cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
			cout<<xx(a,b,c,d)<<" "<<xxx(a,b,c,d);
			return 0;
		}
	}
	return 0;
}

悲楚也會變得快樂。

w33z8kqrqk8zzzx33\textsf{\textbf{\textcolor{black}{w}\textcolor{red}{33z8kqrqk8zzzx33}}} 的做法比我的做法簡單的多,但我的方法就是我的方法。

hzw\textsf{\textbf{\textcolor{black}{h}\textcolor{red}{zw}}} 大佬說過:

自己選擇的路跪着也要走完

OI比賽似乎註定是無情的,在堅強的意志品質的同時,幾分理性同樣是不可或缺的,DDEEFF 我明天再調qwq

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章