date: 2024-06-25
title: Algorithm
status: DONE
author:
- AllenYGY
tags:
- NOTE
- Algorithm
- Template
publish: True
Algorithm
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), x.end()
#define endl '\n'
#define inf32 0x3f3f3f3f
#define inf64 1LL << 60
#define max32 INT_MAX
#define max64 LONG_LONG_MAX
// 类型别名
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using pii = std::pair<int, int>;
int read(){
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
void write(int x){
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
void solve(){
}
signed main() {
return 0;
}
// >=
int index = lower_bound(X.begin(),X.end(),x)-X.begin();
// >
int index = lower_bound(X.begin(),X.end(),x+1)-X.begin();
// <
int index = max(0,lower_bound(X.begin(),X.end(),x)-1-X.begin());
//<=
int index = max(0,lower_bound(X.begin(),X.end(),x+1)-1-X.begin());
int fastpow(int a,int n){
int ans=1;
while(n){
if(n&1) ans*=a;
a*=a;
n>>=1;
}
return ans;
}
int fastpowmod(int a,int n,int mod){
int ans=1;
a%=mod;
while(n){
if(n&1) ans = (ans*a)%mod;
a = (a*a)%mod;
n>>=1;
}
return ans;
}
vector<vector<int>> matrixMultiply(const vector<vector<int>>& A, const vector<vector<int>>& B) {
int rowsA = A.size();
int colsA = A[0].size();
int colsB = B[0].size();
vector<vector<int>> C(rowsA, vector<int>(colsB, 0));
for (int i = 0; i < rowsA; ++i) {
for (int j = 0; j < colsB; ++j) {
for (int k = 0; k < colsA; ++k) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
return C;
}
vector<vector<int>> matrixPow(vector<vector<int>>& M, int n ){
int matrixSize = M.size();
vector<vector<int>> ans(matrixSize, vector<int>(matrixSize, 0));
for(int i=0;i<matrixSize;i++){
ans[i][i]=1;
}
for(;n!=0;n>>=1){
if(n&1) ans = matrixMultiply(ans,M);
M = matrixMultiply(M,M);
}
return ans;
}
#include<bits/stdc++.h>
using namespace std;
struct Person {
std::string name;
int age;
};
bool compareByName(const Person& a, const Person& b) {
return a.name < b.name; // 按名称升序排序
}
bool compareByAge(const Person&a,const Person&b){
return a.age<b.age;
}
int main() {
vector<Person> people = {{"Alice", 25}, {"Bob", 20}, {"Charlie", 30}};
sort(people.begin(), people.end(), compareByName);
for (const auto& person : people) {
std::cout << person.name << " - " << person.age << std::endl;
}
return 0;
}