2023 day 6
This commit is contained in:
parent
a814a54c34
commit
c9a11ef440
39
2023/6/main-1.cpp
Normal file
39
2023/6/main-1.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
inline int solve(int time, int distance) {
|
||||
int ways = 0;
|
||||
for (int i = 0; i <= time; i++) {
|
||||
if (i * (time - i) > distance) {
|
||||
ways++;
|
||||
}
|
||||
}
|
||||
|
||||
return ways;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
vector<int> times, distances;
|
||||
string line, line2;
|
||||
getline(cin, line);
|
||||
getline(cin, line2);
|
||||
istringstream s1s(line), s2s(line2);
|
||||
s1s.ignore(500, ':');
|
||||
s2s.ignore(500, ':');
|
||||
while (!s1s.eof()) {
|
||||
int n;
|
||||
s1s >> n;
|
||||
times.push_back(n);
|
||||
s2s >> n;
|
||||
distances.push_back(n);
|
||||
}
|
||||
|
||||
int ret = 1;
|
||||
for (int i = 0; i < distances.size(); i++) {
|
||||
ret *= solve(times[i], distances[i]);
|
||||
}
|
||||
cout << ret << '\n';
|
||||
}
|
32
2023/6/main-2.cpp
Normal file
32
2023/6/main-2.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
inline long solve(long time, long distance) {
|
||||
long ways = 0;
|
||||
for (long i = 0; i <= time; i++) {
|
||||
if (i * (time - i) > distance) {
|
||||
ways++;
|
||||
}
|
||||
}
|
||||
|
||||
return ways;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
long time, distance;
|
||||
string line, line2;
|
||||
getline(cin, line);
|
||||
line.erase(remove(line.begin(), line.end(), ' '), line.end());
|
||||
istringstream s1s(line);
|
||||
s1s.ignore(500, ':');
|
||||
s1s >> time;
|
||||
getline(cin, line);
|
||||
line.erase(remove(line.begin(), line.end(), ' '), line.end());
|
||||
istringstream s2s(line);
|
||||
s2s.ignore(500, ':');
|
||||
s2s >> distance;
|
||||
cout << solve(time, distance) << '\n';
|
||||
}
|
Loading…
Reference in a new issue