#include<iostream> #include<vector> #include <queue> #include <algorithm> #include<cstdio> #include <map> using namespace std; //还是要注意一点就是string中的每一位都是char类型,搞数字的时候要 -'0' //测试题:B1009说反话 /* char a
描述 按照指定规则对输入的字符串进行处理。 详细描述: 将输入的两个字符串合并。 对合并后的字符串进行排序,要求为:下标为奇数的字符和下标为偶数的字符分别从小到大排序。这里的下标意思是字符在字符串中的位置。 对排序后的字符串进行操作,如果字符为‘0’——‘9’或者‘A’
前缀和与哈希表 // class Solution { // public: // int subarraySum(vector<int>& nums, int k) { // // 前缀和 // // 超时 // vector<int> pre(nums.size()+1,0); // pre[0] = 0; // for(int i = 0; i < nums.s
#include<iostream> #include<cstring> using namespace std; int data[10]; void reverse(char*s,char*t){ for(int i=0;i<10;i++){ data[i] = 0; } for(int i=0;i<strlen(s);i++){ data[s[i]-'0']++; } in
cf1487 edu真不是个东西 A:arena 可以逮着一个人薅到死,所以除了最小的那个都可以。 B:cat cycle 找规律,如果n是偶数不会相遇,就是k步。 如果是奇数,第一步不考虑,然后每隔(n-3)/2跳一次,相当于多走一步 per(){ ll n,k; cin>>n>>k; if(n%2==0){ cout<<(k%n==0?
文章目录 唠嗑第三题的两种枚举方式题目建立关系后,dfs枚举(我的憨批办法枚举导师的排列组合(大佬的姿势 唠嗑 第一次参加leetcode周赛,心情有点小激动,给我的感觉是,前两题送分,第三题可能暴力枚举,也可能是dp,第四题上难度,代码量迅速上升。这次的周赛,前三题几乎送分,看了答案
https://ac.nowcoder.com/acm/contest/11254/F 一道标准的搜索题。 注意题目有坑点,其他按照搜索即可。 我的写法中包含两层搜索+精度的控制。 #include <iostream> #include <vector> #include <string> #include <cmath> #include <stack> #include <algorithm> #include <m
02-JavaScript基础 1.运算符(操作符) 运算符也叫作操作符,是用于实现赋值、比较和执行算数运算等功能的符号。 1.1分类 1.2算数运算符 用来执行两个变量或值的算术运算 运算符说明举例+加-减*乘/除%取余数(取模)9 % 4 = 1 浮点数在算数运算中有问题 浮点数值的最高精确度是17
目录前言一、单调栈?1.代码模板:2.例题LeetCode3163.单调栈经典题目二、单调队列1.模板2.滑动窗口求值总结 前言 本文介绍单调栈和单调队列的使用,并且提供模板。 一、单调栈? 栈地到栈顶是单调增加或者单调减少的。 1.代码模板: //常见模型:找出每个数左边离它最近的比它大/小的数 /
目录 一、运算符 二、包机制、JavaDoc 具体内容 一、运算符 算数运算符:+、-、*、/、%、++、-- 赋值运算符:= 关系运算符:> >= < <= == != instanceof 逻辑运算符:&&、||、! 位运算符:&、|、^、~、>>、<<、>>> 条件运算符:?、: 扩展运算符:+-
codeforces 7.22 E Permutation Shift 给出一个1到n的排列,每次可以交换两个数,问在交换最多m次(m <= n/3)之后能不能得到由1 2 3 … n循环右移所得到的的排列,输出所有能得到的排列和循环右移的次数。 数据范围:n <= 3e5 有点脑洞的一道题。 由于最多交换m次,那么最多会有2m个
A 太简单了,写完就删了 B1 #include <bits/stdc++.h> using namespace std; #define int long long signed main() { int t; cin >> t; while (t--) { int ch[33]; memset(ch, 0, sizeof(ch)); string str; cin >> str; for (int i = 0; i < str.l
添加链接描述 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e7+10; ll p[N],m,n; int main(){ p[m++]=1; for(ll k=2;k*k*k<=1e18;k++){ ll x=k,y=k*k*k; p[m++]=y; while(y<=(1e18+x)/k/k){ //y=kx y=kx
打铁了QAQ D. Journey to Un'Goro 知识点:贪心 找规律 乱搞 如果字符串全r肯定最优(将任意r换成b不会增加贡献) 问题前半部分直接计算即可 问题后半部分我通过打表寻找规律 首先打个DFS #pragma GCC optimize(3) #include<bits/stdc++.h> #define FAST ios::sync_with_stdio(fals
J. Counting Triangles 题意: (a, b, c) (a < b < c),(a, b), (b, c), (c, a) 三边同时为true or false 计数++ 复盘: a -> b -> c -> a , 形成了一个三角形,首先肯定能想到 n 三次暴力枚举,必然超时,想半天也没什么思路,经队友提醒,首先是无向图(一直拿有向图去写),然后三角形的
马拉车算法 解决回文串问题处理回文串的四种算法 暴力匹配 2种情况:1种是以某个字符为对称中心,1种是以间隙(2个字母之间)为对称中心 int b[100]; int d[100]; // i + 1 for (int i = 0; i < size(str); i++) { b[i] = 1; // i为中心的回文长度是它本身字符 while (i - b[
传送门 题意 给你一个 n ∗ m n * m n∗m矩阵,需要放若干个多米诺骨牌,要求其中水平的有 k
Parencodings 有一段时间没有接触模拟题了,之前也没怎么做过,理解题干并且用代码实现罢了,这一道题的大致思路:理解两个数值数组的含义,已经给出的表示从左到右看右括号左边的左括号的总数,需要输出的是每一对配对的括号中间会有多少个左括号(包括该括号对的左括号)(难点),然后我们根据
#include<iostream> #include<algorithm> using namespace std; const int N=1e5; int a[N]; int head=1,tail=1; struct Tree{ int father; int date; int lson=-1; int rson=-1; }tree[N]; int build(int x,int y){ if(tail%2==0){
class Solution { public: int lengthOfLIS(vector<int>& nums) { vector<int> dp(nums.size(), 1); // dp[0] = 1; // dp[i] 0~i范围内的最长递增子序列。 for(int i = 1; i < nums.size(); i++){ for(int j =
适用范围 1.有负环存在 2.有边数限制 模板 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N = 510,M = 10010; int dist[N]; //距离 int backup[N]; //备份 int n,m,k; //所有的边 struct Ed{ int a,b,w; } e[M]
class Solution { public: int findDuplicate(vector<int>& nums) { unordered_map<int, int> in_map; for(int i =0; i < nums.size(); i++){ in_map[nums[i]]++; if(in_map[nums[i]]>1)
适用范围 1.有负环存在 2.有边数限制 模板 有边数限制的最短路 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N = 510,M = 10010; int dist[N]; //距离 int backup[N]; //备份 int n,m,k; //所有的边 struct Ed{
顾名思义: 每一次大循环,将剩下的未排序集合中将最大值/最小值排到正确的位置的排序 // gcc -std=c99 sort.c 编译 #include <stdio.h> void swap1(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } void printArr(int a[], int n){ for(int i = 0; i <
变量:变量是内存中装载数据的盒子,只能用他来存数据和去数据 计算机最小的存储单元叫字节(byte) 1B(字节) = 8bit 1KB = 1024B 1MB = 1024KB 1GB = 1024MB 1TB = 1024GB 1PB = 1024TB Java中共有8中基本数据类型 Byte short int long float double char boolean 数据类型