Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c998ed

Browse files
added problems
1 parent 38be1ea commit 1c998ed

14 files changed

+718
-0
lines changed

‎experiment/multiset_test.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long long int lli;
6+
7+
void task() {
8+
9+
vector<int> tickets;
10+
11+
tickets.emplace_back(1);
12+
tickets.emplace_back(14);
13+
tickets.emplace_back(12);
14+
15+
sort(tickets.begin(), tickets.end(), greater<int>());
16+
17+
cout<<*lower_bound(tickets.begin(), tickets.end(), 13, greater<int>())<<'\n';
18+
19+
20+
}
21+
22+
int main() {
23+
24+
ios::sync_with_stdio(0);
25+
cin.tie(0);
26+
27+
task();
28+
29+
return 0;
30+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void task() {
6+
7+
long int n;
8+
scanf("%ld", &n);
9+
10+
long int total_sum = 0;
11+
12+
int num;
13+
14+
for(int i = 0; i < n-1; i++) {
15+
16+
scanf("%d", &num);
17+
total_sum += num;
18+
19+
20+
}
21+
22+
long int expected_sum = (n * (n+1)) / 2;
23+
24+
int missingNumber = expected_sum - total_sum;
25+
26+
printf("%d\n", missingNumber);
27+
28+
29+
}
30+
31+
int main() {
32+
33+
ios::sync_with_stdio(false);
34+
cin.tie(0);
35+
36+
task();
37+
38+
return 0;
39+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void task() {
6+
7+
long int x, y;
8+
scanf("%ld %ld", &y, &x);
9+
10+
x--;
11+
y--;
12+
13+
long int c = max(x, y);
14+
15+
long int ans;
16+
17+
if(c&1) {
18+
19+
if(x == c) {
20+
21+
ans = c*c + 1 + y;
22+
23+
} else {
24+
25+
ans = (c+1)*(c+1) - x;
26+
27+
}
28+
29+
} else {
30+
31+
if(x == c) {
32+
33+
ans = (c+1)*(c+1) - y;
34+
35+
} else {
36+
37+
ans = c*c + 1 + x;
38+
39+
}
40+
41+
}
42+
43+
printf("%ld\n", ans);
44+
45+
}
46+
47+
int main() {
48+
49+
ios::sync_with_stdio(0);
50+
cin.tie(0);
51+
52+
int test;
53+
scanf("%d", &test);
54+
while(test--) {
55+
task();
56+
}
57+
58+
return 0;
59+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void task() {
6+
7+
int num;
8+
scanf("%d", &num);
9+
10+
if(num == 3 || num == 2) {
11+
printf("NO SOLUTION\n");
12+
return;
13+
}
14+
15+
for(int i = 2; i <= num; i += 2) {
16+
printf("%d ", i);
17+
}
18+
19+
for(int i = 1; i <= num; i += 2) {
20+
printf("%d ", i);
21+
}
22+
23+
printf("\n");
24+
25+
}
26+
27+
int main() {
28+
29+
ios::sync_with_stdio(0);
30+
cin.tie(0);
31+
32+
task();
33+
34+
return 0;
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void task() {
6+
7+
string s;
8+
getline(cin, s);
9+
10+
uint longestSequenceLength = 0;
11+
uint currentSequenceLength = 1;
12+
13+
for(uint i = 1; i < s.length(); i++) {
14+
if(s[i] == s[i-1]) {
15+
currentSequenceLength++;
16+
} else {
17+
longestSequenceLength = max(longestSequenceLength, currentSequenceLength);
18+
currentSequenceLength = 1;
19+
}
20+
}
21+
22+
longestSequenceLength = max(longestSequenceLength, currentSequenceLength);
23+
24+
printf("%d\n", longestSequenceLength);
25+
26+
27+
}
28+
29+
int main() {
30+
31+
ios::sync_with_stdio(0);
32+
cin.tie(0);
33+
34+
task();
35+
36+
return 0;
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void task()
6+
{
7+
long long int num;
8+
scanf("%lld", &num);
9+
10+
while (num != 1)
11+
{
12+
printf("%lld ", num);
13+
14+
if (num & 1)
15+
{
16+
17+
// number is odd
18+
num = num * 3 + 1;
19+
}
20+
else
21+
{
22+
23+
// number is even
24+
num /= 2;
25+
}
26+
}
27+
28+
printf("%lld\n", num);
29+
30+
}
31+
32+
int main()
33+
{
34+
35+
ios::sync_with_stdio(0);
36+
cin.tie(0);
37+
38+
task();
39+
40+
return 0;
41+
}

‎sorting_and_searching/apartments.cpp‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void task()
6+
{
7+
8+
long int n, m, k;
9+
scanf("%ld %ld %ld", &n, &m, &k);
10+
11+
long int applicants[n];
12+
long int apartments[m];
13+
14+
for (int i = 0; i < n; i++)
15+
{
16+
scanf("%ld", &applicants[i]);
17+
}
18+
19+
for (int i = 0; i < m; i++)
20+
{
21+
scanf("%ld", &apartments[i]);
22+
}
23+
24+
sort(applicants, applicants + n);
25+
sort(apartments, apartments + m);
26+
27+
long int currentApplicant = 0;
28+
long int currentApartment = 0;
29+
long int allotedApplicants = 0;
30+
31+
while (currentApplicant < n && currentApartment < m)
32+
{
33+
34+
if (abs(applicants[currentApplicant] - apartments[currentApartment]) <= k)
35+
{
36+
allotedApplicants++;
37+
currentApartment++;
38+
currentApplicant++;
39+
} else {
40+
if(applicants[currentApplicant] > apartments[currentApartment]) {
41+
currentApartment++;
42+
} else {
43+
currentApplicant++;
44+
}
45+
}
46+
}
47+
48+
printf("%ld\n", allotedApplicants);
49+
}
50+
51+
int main()
52+
{
53+
54+
ios::sync_with_stdio(0);
55+
cin.tie(0);
56+
57+
task();
58+
59+
return 0;
60+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long long int lli;
6+
7+
void task()
8+
{
9+
10+
lli n, m, temp;
11+
12+
cin >> n >> m;
13+
14+
vector<lli> tickets;
15+
16+
while (n--)
17+
{
18+
cin >> temp;
19+
tickets.emplace_back(temp);
20+
}
21+
22+
sort(tickets.begin(), tickets.end());
23+
24+
for (auto price : tickets)
25+
{
26+
printf("%lld ", price);
27+
}
28+
29+
printf("\n");
30+
31+
vector<lli> ans;
32+
33+
while (m--)
34+
{
35+
cin >> temp;
36+
auto it = lower_bound(tickets.begin(), tickets.end(), temp);
37+
38+
if (it == tickets.end())
39+
{
40+
ans.emplace_back(-1);
41+
}
42+
else
43+
{
44+
ans.emplace_back(*it);
45+
tickets.erase(it);
46+
}
47+
}
48+
49+
for (auto price : ans)
50+
{
51+
printf("%lld ", price);
52+
}
53+
54+
printf("\n");
55+
}
56+
57+
int main()
58+
{
59+
60+
ios::sync_with_stdio(0);
61+
cin.tie(0);
62+
63+
task();
64+
65+
return 0;
66+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /