Skip to content

Commit

Permalink
Solve CCC and CCO problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaclasher committed Feb 11, 2019
1 parent db47a79 commit 345a2ab
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
44 changes: 44 additions & 0 deletions CCC/ccc04s4.cpp
@@ -0,0 +1,44 @@
#include <bits/stdc++.h>

using namespace std;

int main()
{
long long sx, sy, sz, tx, ty, tz;
int d;
char t;
scanf("%lli%lli%lli%lli%lli%lli", &sx, &sy, &sz, &tx, &ty, &tz);
tx -= sx;
ty -= sy;
tz -= sz;
long long ans = tx * tx + ty * ty + tz * tz;
while (1)
{
scanf("%i %c", &d, &t);
if ((tx - d < 0 && tx > 0) || (tx - d > 0 && tx < 0))
ans = min(ans, ty * ty + tz * tz);
tx -= d;
ans = min(ans, tx * tx + ty * ty + tz * tz);
if (t == 'E')
return 0 * printf("%.2lf\n", sqrt(ans));
switch(t)
{
case 'R':
swap(tx, ty);
tx = -tx;
break;
case 'L':
swap(tx, ty);
ty = -ty;
break;
case 'U':
swap(tx, tz);
tz = -tz;
break;
case 'D':
swap(tx, tz);
tx = -tx;
break;
}
}
}
74 changes: 74 additions & 0 deletions CCO/cco16p2.cpp
@@ -0,0 +1,74 @@
#include <bits/stdc++.h>

using namespace std;

const long double PI = acos(-1);

struct point
{
int x, y;
};

struct bunny : point
{
int w;
};

static inline long double ang(point a, point o)
{
int yy = a.y-o.y;
int xx = a.x-o.x;
int g = abs(__gcd(xx, yy));
return atan2(yy/g, xx/g);
}

static inline bool eq(long double a, long double b)
{
return abs(a-b) < 1e-9;
}

int main()
{
int n;
scanf("%i", &n);
vector<bunny> arr(n);
for (auto &x : arr)
scanf("%i%i%i", &x.x, &x.y, &x.w);
int ans = 0;
for (int z = 0; z < n; z++)
{
map<long double, int> mp;
int sum = 0;
for (int y = 0; y < n; y++)
{
if (z == y)
continue;
sum += arr[y].w;
mp[ang(arr[y], arr[z])] += arr[y].w;
}
vector<pair<long double,int>> cur(mp.size()*2);
int cc = 0;
for (auto &x : mp)
cur[cc++] = x;
for (auto &x : mp)
{
cur[cc] = x;
cur[cc].first += 2*PI;
cc++;
}
int sz = mp.size();
int curs = 0;
for (int x = 0, y = 0; x < sz; x++)
{
long double VV = cur[x].first + PI;
while (y < cur.size() && cur[y].first < VV)
{
curs += cur[y].second;
y++;
}
ans = max(ans, max(sum-curs + arr[z].w, arr[z].w + curs + eq(cur[y].first, VV)*cur[y].second));
curs -= cur[x].second;
}
}
printf("%i\n", ans);
}

0 comments on commit 345a2ab

Please sign in to comment.