版本比较
2021.8.10 比赛题整理
正文
增加 14 行删除 14 行
11234519 行未改动25262728292930313233333435353637383917 行未改动5758596061616263646566676869697071727349 行未改动12312412512612712712812913013121 行未改动1531541551561571571581591601611611621631641652 行未改动168169170171172172173174175175176177178179180181181182183184185123 行未改动全部展开30931031131231331331431531631765 行未改动3833843853863873873883893903915 行未改动## UPDATE 21/08/26 ## UPDATE 21/08/26
更改题面、转移链接等。
------------19 行未改动
1. 我们根据每个**时间段的结束时间的早晚**进行排序。是结束时间!!不是开始时间!
贪心是在尽量少的时间里拍尽量多的节目,所以要**最小化每次结束的时间,以让后面能拍更多节目**。
2. 这道题还有两个难点是有两台摄像机 + 代码实现(做到让代码越简单越好)。
我们在遍历排好序的时间段时, 用两个变量记录每次的结束时间,两个变量,我们要**保证一个永远要比另一个大**(swap 即可)。
因为我们对两个变量的处理顺序是一定的,所以**每次要让新时间段的开始时间和上一个的结束时间之间的差越小越好**。
````cpp#include<bits/stdc++.h>using namespace std;
17 行未改动}
bool cmp (node a, node b){ if (a.t != b.t) if (a.t != b.t) return a.t < b.t; return a.s < b.s;}
signed main (){ n = read (); for (int i = 1; i <= n; i++) for (int i = 1; i <= n; i++) { e[i].s = read (); e[i].t = read (); e[i].vis = 0;49 行未改动struct addedge{ int to, nxt;}e[maxn * 2];int hd[maxn], cnt;int fa[maxn]; int fa[maxn];int check;
int read (){21 行未改动 n = read (), m = read (); for (int i = 1; i <= n; i++) { a[i] = read (); fa[i] = i; fa[i] = i; if (a[i] < a[i - 1]) flag = 1; } for (int i = 1; i <= m; i++) inpt[i].u = read (), inpt[i].v = read (), inpt[i].w = read (); if (!flag) if (!flag) { printf ("-1\n"); return 0; }2 行未改动 { int x = find (inpt[i].u), y = find (inpt[i].v); if (x != y) fa[y] = x; int tmp = 1; while (find (tmp) == find (a[tmp])) while (find (tmp) == find (a[tmp])) { tmp++; if (tmp > n) if (tmp > n) { printf ("%lld\n", inpt[i].w); return 0; } }
} return 0;}````123 行未改动全部展开3. 最后就是**从 u 到其他节点**,都会产生对数 $n-1$。
综上,若点 u 为割点,则 u 的点数为:
$ans_u=siz_1 \times (n-siz_1)+siz_2 \times (n-siz_2)+ \cdots +siz_v \times (n-siz_v)+(n-1)+(sum+1) \times (n-sum-1)$ $ans_u=siz_1 \times (n-siz_1)+siz_2 \times (n-siz_2)+ \cdots +siz_v \times (n-siz_v)+(n-1)+(sum+1) \times (n-sum-1)$
````cpp#include<bits/stdc++.h>using namespace std;65 行未改动 { int u, v; u = read (), v = read (); add (u, v), add (v, u); } } rt = 1; tarjan (1); for (int i = 1; i <= n; i++) printf ("%lld\n", ans[i]); return 0;5 行未改动