I Neiborhood(The 2021 ICPC Asia Regionals Online Contest (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.

input

4 2 6 8 
5
1

output

6 4 

恶心的输入:需要用EOF才能截至输入
自身也需要输出

#include<stdio.h>
#include<vector>
#include<map>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
vector<ll >s;
vector<ll >s11;

int main()
{
    ll a;
    while(EOF!=scanf("%lld",&a))
    {
        s.push_back(a);
    }
    for(int i=0;i<=s.size()-3;i++)
        s11.push_back(s[i]);
    ll s1=s[s.size()-2];
    ll s2=s[s.size()-1];
    sort(s11.begin(),s11.end());
    ll flag=0;
    for(ll i=s11.size()-1; i>=0; i--)
        if(abs(s11[i]-s1)<=s2)
        {
            cout<<s11[i]<<" ";
            flag=1;
        }
    if(flag==0)
        cout<<endl;


}

做法二:map

#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#define ll long long
using namespace std;
map<ll,ll > p;
vector<ll > s;
int main()
{
    ll a;

    while(EOF!=scanf("%lld",&a))
    {
        s.push_back(a);
    }
    for(ll i=0;i<=s.size()-3;i++)
    {
        p[s[i]]=1;
    }
    ll mid=s[s.size()-2];
    ll qq=1;
    a=s[s.size()-1];
    for(ll i=mid+a;i>=mid-a;i--)
    {
        if(p[i]==1)
        {
            qq=0;
            printf("%lld ",i);
        }
    }
    if(qq==1)
        cout<<endl;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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) # 显示结果 cv2.imshow("Origin Image", img) cv2.imshow("Region Growing Result", mask) cv2.waitKey(0) cv2.destroyAllWindows() ``` 以上就是使用 OpenCV 库实现手指静脉图像区域生长算法的 Python 代码。希望能够对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Prime me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值