训练时间:2019-04-05

一场读错三个题,队友恨不得手刃了我这个坑B。

A I J 简单,不写了。

C - Cleaning Pipes (Gym - 101485C)

对于有公共点的管道建边,然后染色判是否是二分图。

注意线段判相交的时候,除了两个线段交于起点之外,都要视为相交。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = + ;
const double eps = 1e-; int dcmp(double x)
{
if (x > eps) return ;
return x < -eps ? - : ;
} struct Point
{
double x, y;
Point() {}
Point(double _x, double _y) { x = _x, y = _y; }
Point operator - (const Point &b) const
{
return Point(x-b.x, y-b.y);
} bool operator == (const Point& b) const
{
return dcmp(x - b.x) == && dcmp(y - b.y) == ;
}
};
typedef Point Vector;
struct Seg
{
Point st, ed;
Seg() {};
Seg(Point a, Point b) { st = a, ed = b; }
}; double Cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }
double Dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; } bool OnSegment(Point p, Point a1, Point a2)
{
return dcmp(Cross(a1-p, a2-p)) == && dcmp(Dot(a1-p, a2-p)) < ;
} bool SegmentIntersection(Point a1, Point a2, Point b1, Point b2)
{
if (a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2) return true; if (OnSegment(a1, b1, b2) || OnSegment(a2, b1, b2)
|| OnSegment(b1, a1, a2) || OnSegment(b2, a1, a2)) return true; double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1),
c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1);
return dcmp(c1) * dcmp(c2) < && dcmp(c3) * dcmp(c4) < ;
} vector<int> v[maxn];
int vis[maxn]; void build(int x, int y)
{
v[x].push_back(y); v[y].push_back(x);
} bool dfs(int x)
{
for (int y : v[x])
{
if (vis[y] == vis[x]) return false;
if (vis[y] == -)
{
vis[y] = !vis[x];
if (!dfs(y)) return false;
}
}
return true;
} Point st[maxn];
Seg s[maxn];
int n, p;
int main()
{
scanf("%d%d", &n, &p);
for (int i = ; i <= n; i++) scanf("%lf%lf", &st[i].x, &st[i].y);
for (int i = ; i <= p; i++)
{
double x, y;
int id;
scanf("%d%lf%lf", &id, &x, &y);
s[i] = Seg(st[id], Point(x, y));
} for (int i = ; i <= p; i++)
for (int j = i+; j <= p; j++)
{
if (s[i].st == s[j].st) continue;
if (SegmentIntersection(s[i].st, s[i].ed, s[j].st, s[j].ed)) build(i, j);
} memset(vis, -, sizeof(vis)); for (int i = ; i <= p; i++)
if (vis[i] == -)
{
vis[i] = ;
if (!dfs(i)) return printf("impossible\n"), ;
} printf("possible\n");
}

D - Debugging (Gym - 101485D)

对于任何一个n行的代码块,可以由长度为n/2 n/3 n/4 ... n/n的代码块的答案更新。所以可以用dp做。

然而这个题没找到很好的递推顺序,窃以为递推为O(n^2)的。

如有合理递推方式,欢迎并感激指出!

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + ;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-; LL dp[maxn]; int n, r, p; LL d(int n)
{
if (n == ) return ;
if (dp[n] != INF) return dp[n];
for (int i = ; i < n; i++)
dp[n] = min(dp[n], d( (int)ceil(1.0*n/(i+)) )+1ll*p*i+r);
return dp[n];
} int main()
{
scanf("%d%d%d", &n, &r, &p);
for (int i = ; i <= n; i++) dp[i] = INF;
printf("%lld\n", d(n));
}

E - Elementary Math (Gym - 101485E)

把每组数字三种运算的结果计算出来,然后把结果和每组数字做一下二分图匹配。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = * + ;
const int maxm = * + ; int n;
map<LL, int> M;
LL x[maxn], y[maxn];
LL tmp[maxn];
int v[maxm], last[maxm], nxt[maxm];
int lnk[maxn], vis[maxn], ans[maxn];
int cnt, tot; void build(int x, int y)
{
++tot;
v[tot] = y;
nxt[tot] = last[x];
last[x] = tot;
} bool dfs(int x)
{
for (int i = last[x]; i; i = nxt[i])
{
int y = v[i];
if (!vis[y])
{
vis[y] = ;
if (lnk[y] == - || dfs(lnk[y]))
{
lnk[y] = x;
ans[x] = y;
return true;
}
}
}
return false;
} int hungary()
{
int res = ;
memset(lnk, -, sizeof(lnk));
for (int i = ; i <= n; i++)
{
memset(vis, , sizeof(vis));
if (dfs(i)) res++;
}
return res;
} char get(LL sum, int id)
{
if (sum == x[id] + y[id]) return '+';
if (sum == x[id] - y[id]) return '-';
if (sum == x[id] * y[id]) return '*';
} int main()
{
scanf("%d", &n);
cnt = n;
for (int i = ; i <= n; i++)
{
scanf("%lld%lld", &x[i], &y[i]);
LL a = x[i] + y[i], b = x[i] - y[i], c = x[i] * y[i]; if (!M.count(a)) M[a] = ++cnt;
build(i, M[a]); tmp[M[a]] = a; if (!M.count(b)) M[b] = ++cnt;
build(i, M[b]); tmp[M[b]] = b; if (!M.count(c)) M[c] = ++cnt;
build(i, M[c]); tmp[M[c]] = c;
} if (hungary() != n) return printf("impossible\n"), ; for (int i = ; i <= n; i++)
printf("%lld %c %lld = %lld\n", x[i], get(tmp[ans[i]], i), y[i], tmp[ans[i]]);
}

G - Guessing Camels (Gym - 101485G)

求一个三位偏序。

CDQ分治裸题,然而我不会。

看题解发现可以两两求二维偏序求出不合法的数目来,然后用总数目减去不合法数目。

二维偏序可以把一个序列的先后顺序映射到另一个中,然后求逆序对。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + ; int n;
int a[maxn], b[maxn], c[maxn];
int T[maxn], A[maxn];
LL cnt = ; void merge_sort(int x, int y)
{
if (y-x > )
{
int m = x + (y-x)/;
int p = x, q = m, i = x;
merge_sort(x, m);
merge_sort(m, y);
while(p < m || q < y)
{
if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];
else T[i++] = A[q++], cnt += m-p;
}
for (i = x; i < y; i++) A[i] = T[i];
}
} void mapping(int a[], int b[])
{
int m[maxn];
for (int i = ; i <= n; i++) m[a[i]] = i;
for (int i = ; i <= n; i++) A[i] = m[b[i]];
merge_sort(, n+);
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
for (int i = ; i <= n; i++) scanf("%d", &b[i]);
for (int i = ; i <= n; i++) scanf("%d", &c[i]); mapping(a, b);
mapping(a, c);
mapping(b, c); printf("%lld\n", (1ll * n * (n-) - cnt) / );
}

2015-2016 Northwestern European Regional Contest (NWERC 2015)的更多相关文章

  1. codeforces Gym - 101485 D Debugging (2015-2016 Northwestern European Regional Contest (NWERC 2015))

    题目描述: 点击打开链接 这题题意其实很不好理解,你有一个n行的程序,现在程序运行了r时间之后停止了运行,证明此处有一个bug,现在你需要在程序中加printf来调试找到bug所在的位置,你每次加一个 ...

  2. 2017-2018 Northwestern European Regional Contest (NWERC 2017)

    A. Ascending Photo 贪心增广. #include<bits/stdc++.h> using namespace std; const int MAXN = 1000000 ...

  3. 2012-2013 Northwestern European Regional Contest (NWERC 2012)

    B - Beer Pressure \(dp(t, p_1, p_2, p_3, p_4)\)表示总人数为\(t\),\(p_i\)对应酒吧投票人数的概率. 使用滚动数组优化掉一维空间. 总的时间复杂 ...

  4. Northwestern European Regional Contest 2016 NWERC ,F题Free Weights(优先队列+Map标记+模拟)

    传送门: Vjudge:https://vjudge.net/problem/Gym-101170F CF: http://codeforces.com/gym/101170 The city of ...

  5. Northwestern European Regional Contest 2017-I题- Installing Apps题解

    一.题意 有一个手机,容量为$C$,网上有$N$个app,每个app有个安装包大小$d_i$,有个安装后的占用空间大小$s_i$,安装app是瞬间完成的,即app的占用空间可以瞬间由$d_i$变成$s ...

  6. Northwestern European Regional Contest 2014 Gym - 101482

    Gym 101482C Cent Savings 简单的dp #include<bits/stdc++.h> #define inf 0x3f3f3f3f #define inf64 0x ...

  7. 2006 ACM Northwestern European Programming Contest C题(二分求最大)

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numberN o ...

  8. ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010

    ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbil ...

  9. 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)

    2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) A 题意:有 n 个时刻 ...

随机推荐

  1. java字符串与二进制的相互转化

    public class StrBinaryTurn { // 将Unicode字符串转换成bool型数组 public boolean[] StrToBool(String input) { boo ...

  2. 查看Apache信息以用户htdoc位置

    查看Apache的相关信息:httpd -V 再从基本信息中取得DocumentRoot位置 less /etc/httpd/httpd.conf中查找DocumentRoot,即有静态文件存放的位置 ...

  3. [Java][Liferay] 解决Liferay ext项目deploy的问题

    Liferay ext project在install war包之后需要重启服务器,重启服务器中会执行ExtHotDeployListener中的逻辑,这里有一个坑,如果是第二次以后install e ...

  4. Intellij IDEA 最头大的问题,如何自定义注释模板?

    想栈长我当初从 Eclipse 转用 IDEA 真是纠结,放弃然后尝试了N次,不过现在已经算是转型成功了,可以完全脱离 Eclipse 撸码了,虽然说我现在真的撸得非常少了.. 说到 IDEA 的痛点 ...

  5. 金三银四面试季节之Java 核心面试技术点 - JVM 小结

    原文:https://github.com/linsheng9731/notebook/blob/master/java/JVM.md 描述一下 JVM 的内存区域 程序计数器(PC,Program ...

  6. Nginx 安装(CentOS )非yum安装

    Nginx 安装(CentOS ) 一.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-d ...

  7. It's the loneliest feeling not to know who you are.

    It's the loneliest feeling not to know who you are.最孤独的感觉莫过于不知道自己是谁.

  8. OpenFirewall

    1.写一份json文件:将要添加防火墙例外的应用程序和端口写入到json文件中 2.打开防火墙,读取json文件添加例外 /// <summary> /// Firewall.xaml 的 ...

  9. JS修改地址栏参数实例代码

    function changeURLPar(destiny, par, par_value) { var pattern = par+'=([^&]*)'; var replaceText = ...

  10. 【HDU1542】Atlantis (扫描线的经典运用)

    点此看题面 大致题意: 给你\(N\)个矩形,请你求出它们覆盖的面积(重叠的面积只算一次). 扫描线 这道题是一道典型的求矩形面积并问题,是扫描线的一个经典运用.这里就不赘述了. 代码 #includ ...