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;
}
#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() {
std::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;
}