Neiborhood Search(2021_0919_ICPC网络赛第一场I题)

We have a set S of one-dimensional points.

Given a target point A, we would like to find the neighboring points of A in S. We consider two points are neighbors, if and only if they are within a distance of r.

Input

The first line lists all the coordinates of the points in S. Each coordinate (including the last one) is followed by a single space.

The second line is the coordinate of point A.

And the third line is the value of distance r.

You can assume that all the points in S have different coordinates, ∣S∣≤100,000, and all the values above are 16-bit integers.

Output

A single line prints the coordinates of A’s neighbors in S. The coordinates should be sorted in descending order, and each coordinate (including the last one) should be followed by a single space.

If the neighbourhood is empty, print an empty line.

Sample Input
4 2 6 8
5
1

Sample Output
6 4

题意

输入一行数,以换行结尾,每个数后面都跟一个空格(最后一个数也有)
输入a,b,判断距离a小于等于b有哪些点,从大到小输出这些邻居点即可

思路

主要注意输入就可以,题目很简单,因为我没读出来输入的最后一个也有空格,所以一直WA

代码

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long b[500010],s[500010];
bool cmp(long long x,long long y)
{
    return x>y;
}
int main()
{
    int j=0;
    char a;
    int f1=0;
    long long ans=0;
    while(~scanf("%c",&a))
    {
        if(a=='\n')
        {
           /* if(f1)
                b[++j]=-ans;
            else
                b[++j]=ans;*/
            break;
        }
        if(a!=' ')
        {
            if(a=='-')
                f1=1;
            else
                ans=ans*10+(a-'0');
        }
        else if(a==' ')
        {
            if(f1==0)
                b[++j]=ans;
            else
                b[++j]=-ans;
            ans=0;
            f1=0;
        }

    }
    long long c,d;
    scanf("%lld",&c);
    scanf("%lld",&d);
    long long e,f;
    e=c-d;
    f=c+d;
    int k=0;
    for(int i=1; i<=j; i++)
    {
        if(b[i]>=e&&b[i]<=f)
            s[++k]=b[i];
    }
    if(k==0)
        printf("\n");
    else
    {
        sort(s+1,s+1+k,cmp);
        for(int i=1; i<=k; i++)
            printf("%lld ",s[i]);
    }
    return 0;
}
好的,以下是根据您的要求,使用 OpenCV 库实现手指静脉图像区域生长算法并进行后续处理的 Python 代码: ```python import cv2 import numpy as np # 读取图像 img = cv2.imread("finger_vein.jpg", cv2.IMREAD_GRAYSCALE) # 预处理,使用高斯滤波器去除噪声 img = cv2.GaussianBlur(img, (5, 5), 0) # 图像分割,使用区域生长算法 def criterion(pixel, seed, threshold): diff = abs(int(pixel) - int(seed)) if diff < threshold: return True else: return False def region_growing(img, seed, threshold): h, w = img.shape[:2] mask = np.zeros((h, w), np.uint8) mask[seed[0], seed[1]] = 255 neiborhood = np.array([[0, -1], [0, 1], [-1, 0], [1, 0]]) while True: border = [] for i in range(len(border)): for j in range(4): cur_point = np.array([border[i][0], border[i][1]]) neibor = cur_point + neiborhood[j] if (neibor[0] >= 0 and neibor[0] < h and neibor[1] >= 0 and neibor[1] < w and mask[neibor[0], neibor[1]] == 0): if criterion(img[neibor[0], neibor[1]], img[seed[0], seed[1]], threshold): mask[neibor[0], neibor[1]] = 255 border.append(neibor) if not border: break return mask seed = [100, 100] threshold = 10 mask = region_growing(img, seed, threshold) # 二值化 ret, binary = cv2.threshold(mask, 0, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) # 去除小的区域,只保留静脉纹路 kernel = np.ones((3, 3), np.uint8) opening = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel, iterations=2) sure_bg = cv2.dilate(opening, kernel, iterations=3) dist_transform = cv2.distanceTransform(opening, cv2.DIST_L2, 5) ret, sure_fg = cv2.threshold(dist_transform, 0.7*dist_transform.max(), 255, 0) sure_fg = np.uint8(sure_fg) unknown = cv2.subtract(sure_bg, sure_fg) ret, markers = cv2.connectedComponents(sure_fg) markers = markers + 1 markers[unknown==255] = 0 markers = cv2.watershed(img, markers) img[markers==-1] = [255, 0, 0] # 显示结果 cv2.imshow("Origin Image", img) cv2.imshow("Region Growing Result", mask) cv2.imshow("Binary Image", binary) cv2.imshow("Keep Vein Only", markers) cv2.waitKey(0) cv2.destroyAllWindows() ``` 以上代码实现了对静脉图片的滤波、图像分割及二值化,然后使用形态学操作和分水岭算法去除小的区域,只保留静脉纹路。如果您需要使用模板匹配或特征提取进行静脉识别,请在最后的 "Keep Vein Only" 图像上进行处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值