Skip to content

Commit fa7c787

Browse files
committed
CF Update
1 parent 257b367 commit fa7c787

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

Codeforces/1400/236-2-B.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <cmath>
5+
6+
using namespace std;
7+
8+
int main(int argc, char const *argv[])
9+
{
10+
int n, k;
11+
cin >> n >> k;
12+
vector <int> a(n);
13+
for(int i = 0 ; i < n ; ++i){
14+
cin >> a[i];
15+
}
16+
// answer depends only on the height of the first tree (a_0, a_0 + k, a_0 + 2k, ... , a_0 + (n - 1) * k)
17+
// brute force the height of the first tree [1, 1000]
18+
int best_height = -1;
19+
int minimum_operations = numeric_limits<int>::max();
20+
for(int height = 1 ; height <= 1000 ; ++height){
21+
// for each height of the first tree, find the other heights (height_j = height + j * k)
22+
// then find the number of operations
23+
int operations = 0;
24+
for(int j = 0 ; j < n ; ++j){
25+
if(height + j * k != a[j]){
26+
++operations;
27+
}
28+
}
29+
if(minimum_operations > operations){
30+
minimum_operations = operations;
31+
best_height = height;
32+
}
33+
}
34+
cout << minimum_operations << '\n';
35+
for(int i = 0 ; i < n ; ++i){
36+
int new_height = best_height + i * k;
37+
if(new_height > a[i]){
38+
cout << "+ " << i + 1 << " " << new_height - a[i] << '\n';
39+
} else if(new_height < a[i]){
40+
cout << "- " << i + 1 << " " << a[i] - new_height << '\n';
41+
}
42+
}
43+
return 0;
44+
}

Codeforces/666-2-A.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
int main(int argc, char const *argv[])
7+
{
8+
int t;
9+
cin >> t;
10+
while(t--){
11+
int n;
12+
cin >> n;
13+
vector <int> count(26, 0);
14+
for(int i = 0 ; i < n ; ++i){
15+
string s;
16+
cin >> s;
17+
for(int j = 0 ; j < s.length() ; ++j){
18+
++count[s[j] - 'a'];
19+
}
20+
}
21+
// each alphabet count must be a multiple of n
22+
bool possible = true;
23+
for(int i = 0 ; i < 26 ; ++i){
24+
if(count[i] == 0) continue;
25+
if(count[i] % n != 0){
26+
possible = false;
27+
break;
28+
}
29+
}
30+
cout << (possible ? "YES" : "NO") << '\n';
31+
}
32+
return 0;
33+
}

0 commit comments

Comments
 (0)