BASIC-19 基础练习 完美的代价


/*题目题目描述回文串,是一种特殊的字符串,它从左往右读和从右往左读是一样的。小龙龙认为回文串才是完美的。现在给你一个串,它不一定是回文的,请你计算最少的交换次数使得该串变成一个完美的回文串。交换的定义是:交换两个相邻的字符例如mamad第一次交换 ad : mamda第二次交换 md : madm

输出范围内的所有质数


给定两个整数a,b,输出a,b之间的所有质数。输入样例3 10输出样例3 5 7#include <iostream>#include <cmath>using namespace std;const int N = 1e6 + 10;int primes[N]; //用于存

1551: [蓝桥杯2021初赛] 直线


#include <iostream>#include <cmath>#include <algorithm>using namespace std;const int N = 2e5 + 10;struct line // 表示直线{ double k,

1550: [蓝桥杯2021初赛] 卡片


#include<iostream>using namespace std;int a[11]; // 数字卡片的数量,0~9,共10个数字// a[0]表示数字0的卡片数量,a[1]表示数字1的卡片数量,以此类推int main(){ // 初始化数字卡片数量为2021

筛质数/素数


https://www.acwing.com/activity/content/problem/content/937/埃氏筛#include <iostream>using namespace std;const int N = 1e6 + 10;int st[N];int prime

AcWing 869. 试除法求约数


简介什么是约数:如果一个数a除以另一个数b的余数为0,即 a%b == 0, 则b是a的约数。如何求一个数x的所有约数:用 x 除以 1 到 x 的所有数,如果余数是0,则把除数加到答案中。优化如果 a / b = c···0,则一定有 a / c = b····0。所以一个数 x 的约数肯定是成对

试除法判定质数


一个数 x 分解成两个数的乘积,则这两个数中,一定有一个数大于根号 x,一个数小于根号x。所以,可以用 x 除以 2 ~ 根号x 中的每个数,如果出现了余数为 0,则这个数不是质数,如果没有出现余数为 0,则这个数是质数。#include <iostream>#include <a

dfs--acwing排列数字


#include <iostream>using namespace std;const int N = 10;bool st[N];int path[N];int n;void dfs(int u){ if(u == n){ for(int i = 0;i <

acwing每日一题-字符串删减


参考:https://www.acwing.com/solution/content/56819/#include <iostream>#include <algorithm>#include <string>using namespace std;int num

力扣回文数


力扣回文数回文串题解 也能参考这个参考回文串做法可以这么写,这种是通过左右一个一个比较来判断是不是回文数得:class Solution {public: bool isPalindrome(int x) { string s = to_string(x); int