Skip to content

Commit bb68fbf

Browse files
committed
Solve problems 227A, 227B and 227C from codeforces
1 parent c6ec98f commit bb68fbf

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main() {
6+
int ax, ay, bx, by, cx, cy;
7+
scanf("%d %d %d %d %d %d", &ax, &ay, &bx, &by, &cx, &cy);
8+
9+
if((1ll * (by - ay) * (cx - bx)) == (1ll * (cy - by) * (bx - ax)))
10+
puts("TOWARDS");
11+
else {
12+
long long v = (1ll * (bx - ax) * (cy - ay)) - (1ll * (cx - ax) * (by - ay));
13+
if(v > 0)
14+
puts("LEFT");
15+
else
16+
puts("RIGHT");
17+
}
18+
19+
return 0;
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 1e5 + 1;
6+
int n, q, a[N];
7+
vector<int> idx[N];
8+
9+
int main() {
10+
scanf("%d", &n);
11+
for(int i = 0; i < n; ++i) {
12+
scanf("%d", a + i);
13+
idx[a[i]].push_back(i + 1);
14+
}
15+
16+
scanf("%d", &q);
17+
int tmp;
18+
long long l = 0, r = 0;
19+
while(q-- != 0) {
20+
scanf("%d", &tmp);
21+
l += idx[tmp].front();
22+
r += n - idx[tmp].back() + 1;
23+
}
24+
25+
printf("%lld %lld\n", l, r);
26+
27+
return 0;
28+
}
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+
int n, m;
6+
7+
long long power(long long a, int p) {
8+
if(p == 0)
9+
return 1;
10+
11+
long long res = power(a, p >> 1) % m;
12+
res = (res * res) % m;
13+
14+
if(p & 1)
15+
res = (res * a) % m;
16+
17+
return res;
18+
}
19+
20+
int main() {
21+
scanf("%d %d", &n, &m);
22+
23+
long long lst = power(3, n) - 1;
24+
if(lst >= 0)
25+
printf("%lld\n", lst);
26+
else
27+
printf("%lld\n", lst + m);
28+
29+
return 0;
30+
}

CodeForces/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
- [200B. Drinks](http://codeforces.com/problemset/problem/200/B)
5656
- [208A. Dubstep](http://codeforces.com/problemset/problem/208/A)
5757
- [214A. System of Equations](http://codeforces.com/problemset/problem/214/A)
58+
- [227A. Where do I Turn?](http://codeforces.com/contest/227/problem/A)
59+
- [227B. Effective Approach](http://codeforces.com/contest/227/problem/B)
60+
- [227C. Flying Saucer Segments](http://codeforces.com/contest/227/problem/C)
5861
- [230A. Dragons](http://codeforces.com/problemset/problem/230/A)
5962
- [230B. T-primes](http://codeforces.com/problemset/problem/230/B)
6063
- [231A. Team](http://codeforces.com/problemset/problem/231/A)

0 commit comments

Comments
 (0)