SSL_2415 连通块

题意

给出一个n×nn×n的矩阵,有m次操作,可以在第(x,y)格放上颜色为z的方块,与它上左下右相连的方块与它是同一块,求每次操作时,在这个矩阵里共有多少块方块(颜色0代表白,1代表黑)。

思路

每次插入时先让答案+1,利用并查集,判断与这个方块相连的方块是否和它为同一个集合,如果为同一个集合我们就让它们合并并且让答案-1,如果它们已经为同一个集合我们就不用让答案-1了,防止掉坑。

代码

#include<cstdio>
int n,m,f,ans,father[250010],map[501][501];
short dx[5]={0,0,0,1,-1},dy[5]={0,1,-1,0,0};
int find(int x)
{
    return x==father[x]?x:find(father[x]);
}
void unio(int x,int y) 
{
    x=find(x);y=find(y);
    if (x==y) return;//如果已经同一个集合了就不让ans-了
    if (x>y) father[x]=y;
    else father[y]=x;
    ans--;
}
int main()
{
    scanf("%d%d",&n,&m);
    int x,y,z;
    for (int i=1;i<=n*n;i++) father[i]=i;
    for (int i=1;i<=m;i++)
    {
        ans++;
        scanf("%d%d%d",&z,&x,&y);
        z++;//因为颜色一开始都初始化为0,所以要让z++
        map[x][y]=z;//map记录这些方块
        for (int j=1;j<=4;j++)
        {
            if (x+dx[j]>0&&x+dx[j]<=n&&y+dy[j]>0&&y+dy[j]<=n//如果满足范围
                 &&map[x+dx[j]][y+dy[j]]==z)//相连的方块颜色相同 
            unio((x-1)*n+y,(x+dx[j]-1)*n+y+dy[j]);//判断并合并
        }
        printf("%d\n",ans);
    }
}
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream 127.0.1:80 { server 127.0.0.1:80; } server { listen 80; server_name localhost; #前端打的dist资源存放目录 root G:\JEECG\JeecgBoot\jeecgboot-vue3\dist; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; # 用于配合 browserHistory使用 try_files $uri $uri/ /index.html; } location /jeecgboot/ { #后台接口地址(我们部署去掉了/jeecg-boot项目名,如果你有请加上) proxy_pass http://127.0.0.1:8080/; proxy_redirect off; #真实IP获取 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; set $my_proxy_add_x_forwarded_for $proxy_add_x_forwarded_for; if ($proxy_add_x_forwarded_for ~* "127.0.0.1"){ set $my_proxy_add_x_forwarded_for $remote_addr; } proxy_set_header X-Forwarded-For $my_proxy_add_x_forwarded_for; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } 帮我看一下这个nginx配置有没有什么问题为什么我访问http://localhost:3100/这个地址不行,我应该正常访问的是哪个地址?
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值