mirror of
https://github.com/Hizenberg469/Algorithms-snippets.git
synced 2026-04-19 22:52:23 +03:00
playground updated
This commit is contained in:
42
playground/Stress_Testing/bruteForce.cpp
Normal file
42
playground/Stress_Testing/bruteForce.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = int(2e5) + 9;
|
||||
|
||||
int n, k, h;
|
||||
int need = int(1e9);
|
||||
int cnt[N];
|
||||
|
||||
int main() {
|
||||
scanf("%d %d", &n, &k);
|
||||
for(int i = 0; i < n; ++i){
|
||||
int x;
|
||||
scanf("%d", &x);
|
||||
h = max(h, x);
|
||||
need = min(need, x);
|
||||
++cnt[x];
|
||||
}
|
||||
|
||||
int pos = N - 1;
|
||||
int res = 0;
|
||||
long long sum = 0;
|
||||
int c = 0;
|
||||
while(true){
|
||||
long long x = sum - c * 1LL * (pos - 1);
|
||||
if(x > k){
|
||||
++res;
|
||||
h = pos;
|
||||
sum = pos * 1LL * c;
|
||||
}
|
||||
|
||||
--pos;
|
||||
if(pos == need) break;
|
||||
c += cnt[pos];
|
||||
sum += cnt[pos] * 1LL * pos;
|
||||
}
|
||||
|
||||
if(h != need) ++res;
|
||||
|
||||
cout << res << endl;
|
||||
}
|
||||
31
playground/Stress_Testing/generator.cpp
Normal file
31
playground/Stress_Testing/generator.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int rnd(int a,int b){
|
||||
return a + rand() % ( b - a + 1 );
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
int seed = atoi(argv[1]);
|
||||
|
||||
srand(seed);
|
||||
|
||||
int n = rnd(1,20);
|
||||
|
||||
int k = rnd(20, 40);
|
||||
|
||||
cout << n << ' ' << k << '\n';
|
||||
|
||||
int val = 0;
|
||||
for(int i = 0 ; i < n ; i++ ){
|
||||
|
||||
val = rnd(0,50);
|
||||
|
||||
cout << val << ' ';
|
||||
}
|
||||
|
||||
cout << '\n';
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user