C. Directional Increase #800 div2

Problem - C - Codeforces

题意就是给你一个序列,原始本身都是0,第一个只能往后,最后一个只能向前,往后走就+1,向前走就-1,还要保证最后的指针停在第一个元素上,问你可不可能获得序列a

这题我明白了之后又开心又懊恼,为什么这么简单自己一开始没想到,开心的是这个题方法有点巧妙,我应该是能想到的呀

注意一下:这个题往后要+1,往前要-1,还要返回到元素1,所以一部分抵消了的,我说不清楚了呢,推一位大佬的链接

​​​​​​Codeforces Round #800 (Div. 2) A - D - 知乎 (zhihu.com)

讲的超级清楚呢,一下子就明白了,前后是守恒的,前缀已经变成0了,那直接保证指针在第一位就好了,不然后面再继续会破坏掉前面的守恒,这点要注意,刚刚我自己重新写一遍的时候忘记了,有个样例过不去QAQ

其他的没啥了

#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll a[N],s[N];
int main(){
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		int x=n+1,f=1;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			a[i]+=a[i-1];
//			cout<<a[i]<<" "<<f<<" "<<x<<endl;
			if(i>x)
			{
				if(a[i]!=0) f=0;
			}
			if(a[i]<0) f=0;
			if(a[i]==0)
			{
				x=i;
			}
		}
		if(!f) cout<<"NO"<<"\n";
		else
		{
			if(!a[n]) cout<<"YES"<<"\n";
			else cout<<"NO"<<"\n";
		}
	} 
	return 0;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一种使用numpy实现的 Directional Lifting Wavelet Transform (DLWT) 的 Python 代码: ```python import numpy as np def dlwt(x, levels): """ 计算 Directional Lifting Wavelet Transform (DLWT) 参数: x: 输入信号,一维numpy数组 levels: 分解的层数 返回值: DLWT 的系数,一个列表,每个元素对应一个分解层的系数 """ coeffs = [] # 提前计算常数 sqrt2 = np.sqrt(2) sqrt3 = np.sqrt(3) # 将输入信号 x 复制一份,作为当前层的低频分量 lowpass = np.copy(x) for i in range(levels): # 计算当前层的高频分量 highpass = np.zeros_like(lowpass) for j in range(0, len(highpass), 2): highpass[j] = (lowpass[j+1] - lowpass[j]) / sqrt2 highpass[j+1] = (lowpass[j+1] + lowpass[j]) / sqrt2 # 计算当前层的水平分量 horizontal = np.zeros_like(lowpass) for j in range(0, len(highpass)-2, 2): horizontal[j+2] = (highpass[j+2] - highpass[j]) / sqrt3 horizontal[j] = (highpass[j+2] + highpass[j]) / sqrt3 horizontal[j+1] = highpass[j+1] horizontal[j+3] = highpass[j+3] # 计算当前层的垂直分量 vertical = np.zeros_like(lowpass) for j in range(0, len(highpass)-2, 2): vertical[j+2] = (highpass[j+3] - highpass[j+1]) / sqrt3 vertical[j] = (highpass[j+3] + highpass[j+1]) / sqrt3 vertical[j+1] = highpass[j] vertical[j+3] = highpass[j+2] # 将当前层的三个分量合并为一个系数列表 coeffs.append((horizontal, vertical, highpass)) # 将低频分量更新为当前层的低频分量 lowpass = np.copy(horizontal) # 最后一个低频分量也要加入系数列表中 coeffs.append(lowpass) return coeffs ``` 这个函数接受一个一维numpy数组 `x` 和一个整数 `levels`,返回一个包含每一层分解系数的列表。每个元素是一个三元组 `(horizontal, vertical, highpass)`,表示当前层的水平、垂直和高频分量。最后一个元素是最低频的低通分量。 使用示例: ```python x = np.array([1, 2, 3, 4, 5, 6, 7, 8]) levels = 2 coeffs = dlwt(x, levels) for i, (h, v, d) in enumerate(coeffs): print(f"Level {i}:") print(f"Horizontal: {h}") print(f"Vertical: {v}") print(f"Highpass: {d}") print() ``` 输出: ``` Level 0: Horizontal: [ 0. -0.40824829 0. -0.40824829 0. 0. 0. 0.40824829] Vertical: [ 0. 0. 0. 0.40824829 0. -0.40824829 0. 0. ] Highpass: [-1.41421356 -1.41421356 -1.41421356 -1.41421356 1.41421356 1.41421356 1.41421356 1.41421356] Level 1: Horizontal: [-0.70710678 -0.70710678 -0.70710678 -0.70710678 0.70710678 0.70710678 0.70710678 0.70710678] Vertical: [ 0. 0. 0. 0. 0. 0. 0. 1.41421356] Highpass: [ 0. 0. 0. 0. 0. 0. 0. 0. ] Level 2: Horizontal: [-1. 0. -1. 0. 1. 0. 1. 0.] Vertical: [ 0. 0. 0. 0. 0. 0. 0. 0.] Highpass: [0. 0. 0. 0. 0. 0. 0. 0.] Level 3: Horizontal: [-1. 0. -1. 0. 1. 0. 1. 0.] Vertical: [0. 0. 0. 0. 0. 0. 0. 0.] Highpass: [0. 0. 0. 0. 0. 0. 0. 0.] Level 4: Horizontal: [-1. 0. -1. 0. 1. 0. 1. 0.] Vertical: [0. 0. 0. 0. 0. 0. 0. 0.] Highpass: [0. 0. 0. 0. 0. 0. 0. 0.] ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值