Uva11572-Unique Snowflakes

统计最长无公共元素子串:map 搞定
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <map>
using namespace std;
int n;
vector<int> st;
map<int,int> visit;
void LNRS_dp_hash_impro(vector<int> &arr, int size){
    //memset(visit, -1, sizeof visit);
    
    int maxlen = 1;
    visit[arr[0]] = 1;
    int curlen = 1;
    int last_start = 0;
 
    for(int i = 1; i < size; ++i){
        if(visit[arr[i]] == 0){
            ++curlen;
            //cout<<curlen<<"@@@@"<<endl;
            visit[arr[i]] = i+1;
           // cout<<visit[arr[i]]<<endl;
        }else{
            if(last_start <= visit[arr[i]]){
                curlen = i - visit[arr[i]]+1;
                //cout<<curlen<<"@@@!!!"<<endl;
                last_start = visit[arr[i]] + 1;
                visit[arr[i]] = i+1; // 更新最近重复位置 
            }else{
                ++curlen;
               // cout<<curlen<<"####"<<endl;
                visit[arr[i]] = i+1; // 更新最近重复位置 
            }
        }
      //  cout<<curlen<<endl;
        if(curlen > maxlen){
            maxlen = curlen;
        }
    }
    cout<<maxlen<<endl;
}
int main(){
	int ncase;
	cin >> ncase;
	while(ncase--){
		visit.clear();
		st.clear();
		scanf("%d",&n);
		for(int i = 0; i < n; i++){
			int tmp;
			scanf("%d",&tmp);
			st.push_back(tmp);
		}
		LNRS_dp_hash_impro(st,n);
	    
		
		
	}
	
	return 0;
}

实现雪花飘落特效可以使用opencv-python库。下面是一个简单的实现方法: 1. 导入所需的库: ```python import cv2 import numpy as np ``` 2. 创建一个空白图像作为背景: ```python width, height = 800, 600 # 设置背景尺寸 background = np.zeros((height, width, 3), dtype=np.uint8) # 创建一个黑色背景图像 ``` 3. 创建一组雪花图像: ```python num_snowflakes = 100 # 雪花数量 snowflakes = [] for _ in range(num_snowflakes): center = (np.random.randint(0, width), np.random.randint(0, height)) # 随机设置雪花中心点 radius = np.random.randint(3, 8) # 随机设置雪花半径 snowflake = cv2.circle(np.zeros_like(background), center, radius, (255, 255, 255), -1) # 创建雪花图像 snowflakes.append(snowflake) ``` 4. 开始雪花飘落效果循环: ```python while True: for snowflake in snowflakes: # 随机设置雪花的飘落速度和方向 x_speed = np.random.randint(-5, 5) y_speed = np.random.randint(1, 5) # 更新雪花的位置 x, y = np.where(snowflake[:, :, 0] == 255) # 获得雪花的位置 snowflake[y, x] = [0, 0, 0] # 清空之前的位置 snowflake[y + y_speed, x + x_speed] = [255, 255, 255] # 更新位置 # 将雪花放置在背景上 background = cv2.bitwise_or(background, snowflake) # 显示背景图像 cv2.imshow("Snowfall Effect", background) if cv2.waitKey(30) == ord('q'): break cv2.destroyAllWindows() ``` 通过以上代码,我们可以实现一个简单的雪花飘落特效。需要注意的是,以上代码只是一种简单实现方法,你可以根据自己的需求进行修改和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值