赛时四题,不解释,自己看
A:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int cnt[10];
void solve(){
memset(cnt, 0, sizeof cnt);
int n; cin >> n;
vector<int> a(n+1);
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++){
cnt[a[i]]++;
//cout << a[i] << " "<< cnt[a[i]] << '\n';
if(cnt[0] >= 3 && cnt[1] >= 1 && cnt[2] >= 2 && cnt[3] >= 1 && cnt[5] >= 1){
cout << i << '\n';
return;
}
}
cout << 0 << '\n';
}
int main(){
int t; cin >> t; while(t--)
solve();return 0;
}
B:
/*
就是没有技术的贪心模拟
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
int a[N];
bool cmp(int x, int y){
return x > y;
}
void solve(){
memset(a, 0, sizeof a);
int n, x, j; cin >> n >> x;
for(int i = 1; i <= n; i++) cin >> a[i];
// max(len * min >= x)
sort(a + 1, a + n + 1, cmp);
int ans = 0, len = 1, last = 0;
for(int i = 1; i <= n; i++){
if(len * a[i] >= x){
ans++;
len = 0;
}
len++;
}
cout << ans << '\n';
}
int main(){
int t; cin >> t; while(t--)
solve();return 0;
}
C:
/*
7
1 2 3 4 5 6 7
6 1 3 5 7 2 4
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
void solve(){
int n; cin >> n;
if(n % 2 == 0){
cout << -1 << '\n';
return;
}
vector<int> num;
for(int i = 3; i <= n; i++){
if(i % 2) num.push_back(i);
}
for(int i = 2; i < n - 1; i++){
if(i % 2 == 0) num.push_back(i);
}
if(n == 1){
cout << 1 << '\n';
}
else if(n < 5){
cout << "1 3 2" << '\n';
}else{
cout << n - 1 << ' ' << 1 << ' ';
for(auto x : num){
cout << x << ' ';
}
cout << '\n';
}
}
int main(){
int t; cin >> t; while(t--)
solve();return 0;
}
D
/*
最大值最小化
ll
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, k;
bool check(ll x){
ll len = x + 1;
ll num = m/len;
ll le = m % len;
ll tot = (num * x + le) * n;
return tot >= k;
}
void solve(){
cin >> n >> m >> k;
ll l = 0, r = m;
while(l < r){
ll mid = (r + l) >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
cout << l << '\n';
}
int main(){
int t; cin >> t; while(t--)
solve();return 0;
}