feat: new greedy problem formated
This commit is contained in:
36
inclusao-de-subintervalos/src/ac.cpp
Normal file
36
inclusao-de-subintervalos/src/ac.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool comp(pair<int, int> &a, pair<int, int> &b) {
|
||||
if (a.first != b.first) {
|
||||
return a.first < b.first;
|
||||
}
|
||||
return a.second > b.second;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
int n; cin >> n;
|
||||
|
||||
vector<pair<int, int>> intervals(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> intervals[i].first;
|
||||
cin >> intervals[i].second;
|
||||
}
|
||||
|
||||
sort(intervals.begin(), intervals.end(), comp);
|
||||
|
||||
int lastCovered = intervals[0].second;
|
||||
int count = 1;
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (lastCovered < intervals[i].second) {
|
||||
lastCovered = intervals[i].second;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
inclusao-de-subintervalos/src/checker.cpp
Normal file
17
inclusao-de-subintervalos/src/checker.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
setName("compare two signed int%d's", 8 * int(sizeof(int)));
|
||||
registerTestlibCmd(argc, argv);
|
||||
|
||||
int ja = ans.readInt();
|
||||
int pa = ouf.readInt();
|
||||
|
||||
if (ja != pa)
|
||||
quitf(_wa, "expected %d, found %d", ja, pa);
|
||||
|
||||
quitf(_ok, "all answers are correct");
|
||||
}
|
||||
94
inclusao-de-subintervalos/src/generator.cpp
Normal file
94
inclusao-de-subintervalos/src/generator.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MIN_N = 1;
|
||||
const int MAX_N = 1e5;
|
||||
const int MIN_INTERVAL = 1;
|
||||
const int MAX_INTERVAL = 1e4;
|
||||
|
||||
const int rnd_test_n = 30;
|
||||
|
||||
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
|
||||
dest.insert(dest.end(), orig.begin(), orig.end());
|
||||
}
|
||||
|
||||
string output_tc(const vector<pair<int, int>>& intervals) {
|
||||
ostringstream oss;
|
||||
oss << intervals.size() << endl;
|
||||
for (const auto [l, r] : intervals) {
|
||||
oss << l << " " << r << endl;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc({{1, 2}, {3, 4}, {5, 6}}));
|
||||
tests.push_back(output_tc({{2, 4}, {3, 7}, {1, 8}, {4, 8}}));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<string> generate_manual_tests() {
|
||||
vector<string> tests;
|
||||
// tests.push_back(output_tc(100, 0));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<pair<int, int>> generateRandomIntervals(int size) {
|
||||
vector<pair<int, int>> intervals(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
intervals[i].first = rnd.next(MIN_INTERVAL, MAX_INTERVAL - 1);
|
||||
intervals[i].second = rnd.next(intervals[i].first, MAX_INTERVAL);
|
||||
}
|
||||
return intervals;
|
||||
}
|
||||
|
||||
string rnd_test(int i){
|
||||
int min_n = MIN_N;
|
||||
int max_n = MAX_N;
|
||||
|
||||
if(i<rnd_test_n / 3){
|
||||
max_n = 5000;
|
||||
}
|
||||
else if(i<rnd_test_n / 2){
|
||||
max_n = 20000;
|
||||
}
|
||||
|
||||
int n = rnd.next(min_n, max_n);
|
||||
return(output_tc(generateRandomIntervals(n)));
|
||||
}
|
||||
|
||||
vector<string> generate_random_tests() {
|
||||
vector<string> tests;
|
||||
for (int i = 0; i < rnd_test_n; i++){
|
||||
tests.push_back(rnd_test(i));
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
|
||||
string extreme_test_1(){
|
||||
return(output_tc(generateRandomIntervals(MAX_N)));
|
||||
}
|
||||
|
||||
vector<string> generate_extreme_tests(){
|
||||
vector<string> tests;
|
||||
tests.push_back(extreme_test_1());
|
||||
return tests;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
registerGen(argc, argv, 1);
|
||||
vector<string> tests;
|
||||
size_t test = 0;
|
||||
append(tests, generate_sample_tests());
|
||||
append(tests, generate_manual_tests());
|
||||
append(tests, generate_random_tests());
|
||||
append(tests, generate_extreme_tests());
|
||||
for (const auto &t : tests) {
|
||||
startTest(++test);
|
||||
cout << t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
inclusao-de-subintervalos/src/script.sh
Normal file
1
inclusao-de-subintervalos/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
inclusao-de-subintervalos/src/testlib.h
Normal file
5963
inclusao-de-subintervalos/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
20
inclusao-de-subintervalos/src/validator.cpp
Normal file
20
inclusao-de-subintervalos/src/validator.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
int n = inf.readInt(1, 1e5, "n");
|
||||
inf.readEoln();
|
||||
for (int i = 0; i < n; i++) {
|
||||
int l = inf.readInt(1, 1e4, "li");
|
||||
inf.readSpace();
|
||||
int r = inf.readInt(1, 1e4, "ri");
|
||||
inf.readEoln();
|
||||
ensuref(l <= r, "Interval end time must be at least interval start time");
|
||||
}
|
||||
inf.readEof();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user