2023-11-29
排序
#include<bits/stdc++.h>
using namespace std;
void solve()
{
vector<int> a(3);
for(auto &x : a) cin >> x;
sort(a.begin,a.end());
if(a[0] == a[1] && a[1] == 5 && a[2] == 7) cout << "YES\n";
else cout << "NO\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--)
solve();
return 0;
}
排序
#include<bits/stdc++.h>
using namespace std;
void solve()
{
vector<string> s(100);
int n, l;
cin >> n >> l;
for(int i = 0; i < n; i++) cin >>s[i];
sort(s.begin(),s.end());
for(auto x : s) cout << s;
cout << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--)
solve();
return 0;
}
模拟
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n, k;
cin >> n >> k;
map<int, int> mp;
for(int i = 0; i < k; i++)
{
int x;
cin >> x;
mp[x] = 1;
}
for(int i = n; ; i++)
{
bool flag = true;
int j = i;
while(j)
{
int k = j % 10;
j /= 10;
if(mp[k]) flag = false;
}
if(flag)
{
cout << i << "\n";
return;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--)
solve();
return 0;
}
组合数学
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 10, mod = 1e9 + 7;
int fac[N], invfac[N];
int qmi(int x, int p = mod - 2)
{
int res = 1;
while(p)
{
if(p & 1) res = res * (x) % mod;
x = x * x % mod;
p >>=1;
}
return res;
}
void init()
{
fac[0] = 1;
for(int i = 1; i < N; i++)
{
fac[i] = (fac[i - 1] * i ) % mod;
}
invfac[N - 1] = qmi(fac[N - 1]);
for(int i = N - 2; i >= 0; i--)
{
invfac[i] = (invfac[i + 1] * (i + 1)) % mod;
}
}
int C(int n, int m)
{
if(n < m || m < 0)
{
return 0;
}
return fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
void solve()
{
init();
int h, w, a, b;
cin >> h >> w >> a >> b;
int ans = 0;
for(int j = b + 1; j <= w; j++)
{
ans += C(h - a + j - 2, j - 1) * C(a + w - j - 1, w - j) % mod;
ans %= mod;
}
cout << ans << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--)
solve();
return 0;
}