IDEA快速构建SpringBoot项目
IDEA快速构建SpringBoot项目
IDEA快速构建SpringBoot项目概述:本文讲解IDEA如何快速构建SpringBoot项目。进入Spring Initializr创建controller文件
代码:代码语言:javascript代码运行次数:0运行复制package com.example.springbootstudy;
import org.springframework
IDEA快速构建SpringBoot项目
概述:本文讲解IDEA如何快速构建SpringBoot项目。
进入Spring Initializr
创建controller文件
代码:
代码语言:javascript代码运行次数:0运行复制package springbootstudy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "Hello World";
}
}
访问网址
一共有 n 个数,编号是 1∼n,最开始每个数各自在一个集合中。
现在要进行 m 个操作,操作共有两种:
M a b,将编号为 a 和 b 的两个数所在的集合合并,如果两个数已经在同一个集合中,则忽略这个操作; Q a b,询问编号为 a 和 b 的两个数是否在同一个集合中; 输入格式 第一行输入整数 n 和 m。
接下来 m 行,每行包含一个操作指令,指令为 M a b 或 Q a b 中的一种。
输出格式 对于每个询问指令 Q a b,都要输出一个结果,如果 a 和 b 在同一集合内,则输出 Yes,否则输出 o。
每个结果占一行。
数据范围 1≤n,m≤105 输入样例: 4 5 M 1 2 M 4 Q 1 2 Q 1 Q 4 输出样例: Yes o Yes
提交代码
代码语言:javascript代码运行次数:0运行复制#include<iostream>
using namespace std;
ct int = 100010;
int n, m;
int p[];
int find(int x) // 到x的祖先节点
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main()
{
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) p[i] = i;
while (m--)
{
char op;
int a, b;
scanf (" %c%d%d", &op, &a, &b);
if (op == 'M') p[p[find(a)]] = find(b); // 让a的祖先节点指向b的祖先节点
else
{
if (find(a) == find(b)) puts("Yes");
else puts("o");
}
}
return 0;
}
代码语言:javascript代码运行次数:0运行复制import java.io.*;
public class Main
{
static int = 100010;
static int n, m;
static int [] p = new int [];
static int find(int x)
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader (System.in));
String [] str = reader.readLine().split(" ");
n = Integer.parseInt(str[0]);
m = Integer.parseInt(str[1]);
for (int i = 1; i <= n; ++ i) p[i] = i;
while (m -- > 0)
{
String op;
int a, b;
str = reader.readLine().split(" ");
op = str[0];
a = Integer.parseInt(str[1]);
b = Integer.parseInt(str[2]);
if (("M")) p[find(a)] = find(b);
else
{
if (find(a) == find(b)) println("Yes");
else println("o");
}
}
}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2022-12-29,如有侵权请联系 cloudcommunity@tencent 删除数据intstaticstring集合 #感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
上传时间: 2025-07-19 22:23:46
下一篇:常用的用户类与数据库表
推荐阅读
留言与评论(共有 17 条评论) |
本站网友 崇明二手房网 | 5分钟前 发表 |
如果两个数已经在同一个集合中 | |
本站网友 我在这儿等着你回来 | 3分钟前 发表 |
m; int p[]; int find(int x) // 到x的祖先节点 { if (p[x] != x) p[x] = find(p[x]); return p[x]; } int main() { scanf("%d %d" | |
本站网友 陈纳 | 1分钟前 发表 |
&a | |
本站网友 27144 | 3分钟前 发表 |
则输出 Yes | |
本站网友 张弼士 | 11分钟前 发表 |
每个结果占一行 | |
本站网友 龟板的功效与作用 | 7分钟前 发表 |
原始发表:2022-12-29 | |
本站网友 广园路租房 | 19分钟前 发表 |
则输出 Yes | |
本站网友 清除痘印 | 28分钟前 发表 |
询问编号为 a 和 b 的两个数是否在同一个集合中; 输入格式 第一行输入整数 n 和 m | |
本站网友 要我怎么忘了他 | 22分钟前 发表 |
m; static int [] p = new int []; static int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x]; } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader (System.in)); String [] str = reader.readLine().split(" "); n = Integer.parseInt(str[0]); m = Integer.parseInt(str[1]); for (int i = 1; i <= n; ++ i) p[i] = i; while (m -- > 0) { String op; int a | |
本站网友 中华通 | 13分钟前 发表 |
每个结果占一行 | |
本站网友 路特斯车队 | 10分钟前 发表 |
&b); if (op == 'M') p[p[find(a)]] = find(b); // 让a的祖先节点指向b的祖先节点 else { if (find(a) == find(b)) puts("Yes"); else puts("o"); } } return 0; }代码语言:javascript代码运行次数:0运行复制import java.io.*; public class Main { static int = 100010; static int n | |
本站网友 五山二手房 | 19分钟前 发表 |
原始发表:2022-12-29 | |
本站网友 马腾化 | 9分钟前 发表 |
输出格式 对于每个询问指令 Q a b | |
本站网友 宁杭高速 | 11分钟前 发表 |
输出格式 对于每个询问指令 Q a b | |
本站网友 公交车骚扰 | 9分钟前 发表 |
则忽略这个操作; Q a b | |
本站网友 蓝天算法 | 23分钟前 发表 |
b; scanf (" %c%d%d" |