Skip to content

Commit

Permalink
Added Round 61 form CSacademy
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonber committed Dec 15, 2017
1 parent 1ed2cda commit 50b1882
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
18 changes: 18 additions & 0 deletions csacademy/Round61/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() {
#ifndef ONLINEJUDGE
ios_base::sync_with_stdio(0); cin.tie(0);
#endif

double x;
cin >> x;

cout << (int)((x * 1.8) + 32) << endl;

return 0;
}
38 changes: 38 additions & 0 deletions csacademy/Round61/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() {
#ifndef ONLINEJUDGE
ios_base::sync_with_stdio(0); cin.tie(0);
#endif

int n;
cin >> n;

n *= 2;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];

int a = 0;
bool cur = 0;
for (int i = 0; i < n; ++i) {
if (v[i] != cur) a ++;
cur = !cur;
}


a /= 2;
int b = 0;
cur = 1;
for (int i = 0; i < n; ++i) {
if (v[i] != cur) b ++;
cur = !cur;
}

b /= 2;
cout << min(a, b) << endl;
return 0;
}
51 changes: 51 additions & 0 deletions csacademy/Round61/C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() {
#ifdef ONLINEJUDGE
ios_base::sync_with_stdio(0); cin.tie(0);
#endif

int n, m;
cin >> n >> m;

int a, b;
vector<int> times(n + 1, 0);
vector<int> l(m), r(m);
for (int i = 0; i < m; ++i) {
cin >> a >> b;
l[i] = a;
r[i] = b;
a --;
times[a] ++;
times[b] --;
}

int zeros = 0;
set<int> uniq;
int acum = 0;
for (int i = 0; i < n; ++i) {
acum += times[i];
if (acum == 1) uniq.insert(i + 1);
if (acum == 0) zeros ++;
}

vector<int> ans(m, 0);
for (int i = 0; i < m && uniq.size() > 0; ++i) {
while (uniq.size() > 0) {
auto lw = uniq.lower_bound(l[i]);
if (lw != uniq.end() && *lw >= l[i] && *lw <= r[i]) {
uniq.erase(lw);
ans[i] ++;
}
else break;
}
}

for (int i = 0; i < m; ++i) cout << ans[i] + zeros << " ";cout << endl;

return 0;
}

0 comments on commit 50b1882

Please sign in to comment.