2021/10/22 北化周赛

C剪切

C题链接
题解:我们画图可以看出来,只要这个点在矩形内或者边界,就一定可以让矩形均分,一次面积就是矩形面积一半,只有这个点在矩形正中心,才有多种分割情况,其他的有且仅有一种分割情况
code:

# include <iostream>
	# include <cmath>
	# include <algorithm>
	# include <string.h>
	
	using namespace std ; 
	
	const int N = 1e5 + 10;
	
	typedef long long ll;
	
	int main (){
		double w, h, x, y;
		cin >> w >> h >> x >> y;
		printf("%06f\n",w*h/2.0);
		if (abs(x*2 - w) < 1e-7 && abs(y*2 - h) < 1e-7){
			cout << 1;
		}
		else cout << 0;
		return 0;
	}

D 数学?

D题链接
题解:类似滑动窗口,我们先定义好数组a[n],从初值开始遍历求和,当sum >= k,我们就停止这个操作,此时满足答案的数组有n-i+1个,之后我们让sum从左开始减,当sum < k,我们在进行第一步操作
code:

# include <iostream>
# include <cmath>
# include <algorithm>
# include <string.h>

using namespace std ; 

const int N = 1e5 + 10;

typedef long long ll;

int a[N];

int main (){
	ll n, k;
	cin >> n >> k;
	for (ll i = 1; i <= n; i ++)
		cin >> a[i];
	ll sum = a[1];
	ll ans = 0;
	ll l = 1;
	ll r = 1;
	while (r <= n){
		if (sum >= k){
			ans += n - r + 1;
			sum -= a[l ++];
		}
		else sum += a[++ r];
	}
	cout << ans;
	return 0;
}
posted @ 2021-10-23 17:01  Gsding  阅读(44)  评论(0)    收藏  举报