A. The Child and Homework

注意仔细读题,WA了好多次,=_=

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = ; char s[][maxn];
int l[], r[]; bool cmp(int a, int b) { return l[a] < l[b]; } int main()
{
//freopen("in.txt", "r", stdin); for(int i = ; i < ; i++) r[i] = i;
for(int i = ; i < ; i++) scanf("%s", s[i]);
for(int i = ; i < ; i++) { l[i] = strlen(s[i]); l[i] -= ; }
sort(r, r + , cmp); int ans = -;
if(l[r[]] * <= l[r[]]) ans = r[];
if(l[r[]] >= l[r[]] * ) { if(ans == -) ans = r[]; else ans = ; }
if(ans == -) ans = ; printf("%c\n", 'A' + ans); return ;
}

代码君

B. The Child and Set (贪心)

把那些lowbit都算出来,然后从大到小排个序,依次往里面填就好了。

 #include <cstdio>
#include <algorithm>
using std::sort;
const int maxn = + ;
int lowbit[maxn], r[maxn], ans[maxn], cnt; bool cmp(int a, int b) { return lowbit[a] > lowbit[b]; } int main()
{
int s, n;
scanf("%d%d", &s, &n); for(int i = ; i <= n; i++) { r[i] = i; lowbit[i] = i & (-i); }
sort(r + , r + + n, cmp);
int t = ;
for(int i = ; i <= n; i++)
{
if(t == s) break;
if(lowbit[r[i]] + t <= s) { t += lowbit[r[i]]; ans[cnt++] = r[i]; }
} if(t != s) { puts("-1"); return ; }
printf("%d\n%d", cnt, ans[]);
for(int i = ; i < cnt; i++) printf(" %d", ans[i]);
puts(""); return ;
}

代码君

C. The Child and Toy (贪心)

最优的删点方式就是从最大的点开始删起。

不妨从边的角度考虑更为方便,最终没有任意两个点事连通的,所以每条边都会被删去。考虑边(u, v),它被删去的时候贡献的一定是uv中较小的权值。

所以算法就是,读进每条边累加它权值较小的那个端点的权值即可。

 #include <cstdio>
#include <algorithm>
using std::min; const int maxn = + ;
const int maxm = + ; int a[maxn], u[maxm], v[maxm]; int main()
{
int n, m, ans = ;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i < m; i++) { scanf("%d%d", &u[i], &v[i]); ans += min(a[u[i]], a[v[i]]); }
printf("%d\n", ans); return ;
}

代码君

D. The Child and Zoo (贪心 含秩并查集 最大生成树)

  给每条边赋一个权值,为两端顶点权值较小的那个,然后将这些边从大到小排序。

  一开始图是空的,每加进一条权值为w的边可能会将两个连通分量连通起来,那么对于分别位于这两个连通分量中的(u, v),f(u, v) = w,而这样的f(u, v)一共有 p * q个,其中pq分别为这两个连通分量的秩。

 #include <cstdio>
#include <algorithm>
using namespace std; const int maxn = + ;
int a[maxn], u[maxn], v[maxn], w[maxn], r[maxn], cnt[maxn]; int pa[maxn];
int findset(int x) { return x == pa[x] ? x : pa[x] = findset(pa[x]); } bool cmp(int a, int b) { return w[a] > w[b]; } int main()
{
//freopen("in.txt", "r", stdin); int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i <= m; i++) { scanf("%d%d", &u[i], &v[i]); w[i] = min(a[u[i]], a[v[i]]); } for(int i = ; i <= n; i++) { pa[i] = i; cnt[i] = ; }
for(int i = ; i <= m; i++) r[i] = i;
sort(r + , r + + m, cmp); double ans = 0.0;
int c = n;
for(int i = ; i <= m && c > ; i++)
{
int px = findset(u[r[i]]);
int py = findset(v[r[i]]);
if(px != py)
{
ans += (double) cnt[px] * cnt[py] * w[r[i]];
pa[px] = py; cnt[py] += cnt[px];
c--;
}
} printf("%.6f\n", ans * / (n * 1.0 * (n - ))); return ;
}

代码君

E. The Child and Polygon (区间DP 叉积)

不妨将这些点按照逆时针顺序编号0 ~ n-1。d(i, j)表示多边形 i, i+1 ,..., j, i 的三角剖分的方法数。

则有状态转移方程 d(i, j) = sum{ d(i, k) * d(k, j) | i < k < j 且 线段ik在多边形内部 }

可以通过叉积来判断线段是否在多边形内部,具体就是判断 ji × jk 是否为正。

总时间复杂度为O(n3)

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long LL;
const LL MOD = ; const int maxn = + ;
int n; struct Point
{
LL x, y;
Point(LL x = , LL y = ):x(x), y(y) {}
}p[maxn]; Point operator - (const Point& A, const Point& B)
{ return Point(A.x - B.x, A.y - B.y); } LL Cross(const Point& A, const Point& B)
{ return A.x * B.y - A.y * B.x; } LL d[maxn][maxn]; LL dp(int L, int R)
{
if(d[L][R] != -) return d[L][R];
LL& ans = d[L][R];
if(R - L == ) return ans = ;
ans = ;
for(int i = L + ; i < R; i++)
if(Cross(p[L] - p[R], p[i] - p[R]) > )
ans = (ans + dp(L, i) * dp(i, R)) % MOD;
return ans;
} int main()
{
//freopen("in.txt", "r", stdin); scanf("%d", &n);
LL x, y;
for(int i = ; i < n; i++)
{
scanf("%I64d%I64d", &x, &y);
p[i] = Point(x, y);
} LL area = ;
for(int i = ; i + < n; i++)
area += Cross(p[i] - p[], p[i+] - p[]);
if(area < ) reverse(p, p + n); memset(d, -, sizeof(d));
printf("%I64d\n", dp(, n - )); return ;
}

代码君

最后看了下Div1的两道题:

D. The Child and Sequence (线段树 单点修改)

动态询问连续子序列的和。操作有 单点修改 和 将 连续区间的每个数都模上x

重点说一下取模的操作,可以维护一个区间的最大值,当区间的最大值小于x的时候,那么便不用取模了。

而且每个数每次取模以后的值至少要减半,所以每个数取模的次数不会太多。

balabala...

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL; const int maxn = + ;
int n, m, qL, qR, p, op;
LL v;
LL sumv[maxn << ], maxv[maxn << ]; void pushup(int o)
{
sumv[o] = sumv[o<<] + sumv[o<<|];
maxv[o] = max(maxv[o<<], maxv[o<<|]);
} void build(int o, int L, int R)
{
if(L == R) { scanf("%I64d", &sumv[o]); maxv[o] = sumv[o]; return; }
int M = (L + R) / ;
build(o<<, L, M);
build(o<<|, M+, R);
pushup(o);
} void update1(int o, int L, int R)
{
if(L == R) { sumv[o] = maxv[o] = v; return; }
int M = (L + R) / ;
if(p <= M) update1(o<<, L, M);
else update1(o<<|, M+, R);
pushup(o);
} void update2(int o, int L, int R)
{
if(maxv[o] < v) return;
if(L == R) { sumv[o] %= v; maxv[o] %= v; return; }
int M = (L + R) / ;
if(qL <= M) update2(o<<, L, M);
if(qR > M) update2(o<<|, M+, R);
pushup(o);
} LL query(int o, int L, int R)
{
if(qL <= L && qR >= R) return sumv[o];
int M = (L + R) / ;
LL ans = ;
if(qL <= M) ans += query(o<<, L, M);
if(qR > M) ans += query(o<<|, M+, R);
return ans;
} int main()
{
//freopen("in.txt", "r", stdin); cin >> n >> m;
build(, , n);
while( m-- )
{
scanf("%d", &op);
if(op == )
{
scanf("%d%d", &qL, &qR);
printf("%I64d\n", query(, , n));
}
else if(op == )
{
scanf("%d%d%I64d", &qL, &qR, &v);
update2(, , n);
}
else
{
scanf("%d%I64d", &p, &v);
update1(, , n);
}
} return ;
}

代码君

E题看到用什么母函数,多项式求根,FFT,就打算把这道题放一放了,毕竟太弱Q_Q

CodeForces Round #250 Div2的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. BZOJ 3625: [Codeforces Round #250]小朋友和二叉树

    3625: [Codeforces Round #250]小朋友和二叉树 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 304  Solved: 13 ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  7. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforces Round#250 D. The Child and Zoo(并差集)

    题目链接:http://codeforces.com/problemset/problem/437/D 思路:并差集应用,先对所有的边从大到小排序,然后枚举边的时候,如果某条边的两个顶点不在同一个集合 ...

随机推荐

  1. JS对象类型的确定

    JS是松散类型的语言,这一点JS的对象表现得尤为突出.那么如何来确定JS对象的具体类型呢? 首先,我们可以使用typeof运算符确定其基本类型(number,object,function,undef ...

  2. jQuery1.9.1源码分析--Events模块

    var rformElems = /^(?:input|select|textarea)$/i, rkeyEvent = /^key/, rmouseEvent = /^(?:mouse|contex ...

  3. Sqli-labs less 15

    Less-15 本关没有错误提示,那么我们只能靠猜测进行注入.这里我直接从源代码中看到了sql语句 @$sql="SELECT username, password FROM users W ...

  4. 当你碰到一个网络中有多个PXE Server 肿么办?

    今天在用PXE 安装Openstack Compute节点时,郁闷得发现同一网段中还有一个PXE Server,而我的Compute 启动起来总会先找到它,但那个设置不受我控制,子网也不归我管,那个s ...

  5. 机器学习在 IT 运维管理中的必要性!

    机器学习技术在监控工具中的应用已经成为 IT 运维与 DevOps 团队的一大热点话题.尽管相关的使用案例很多,对 IT 团队而已真正的「杀手级应用」是机器学习如何提高实时事件管理能力,从而帮助较大规 ...

  6. CSS Animatie是一款在线制作CSS3动画的工具,可以在线直接制作CSS3动画效果,生成代码

    CSS Animatie是一款在线制作CSS3动画的工具,可以在线直接制作CSS3动画效果,生成代码 CSS Animatie 彩蛋爆料直击现场 CSS Animatie是一款在线制作CSS3动画的工 ...

  7. HDU 1385 Minimum Transport Cost (Dijstra 最短路)

    Minimum Transport Cost http://acm.hdu.edu.cn/showproblem.php?pid=1385 Problem Description These are ...

  8. kafka配置

    官网:http://kafka.apache.org/ 主要有3种安装方式: 1. 单机单broker 2. 单机多broker 3. 多机多broker 1. wget http://mirror. ...

  9. 如何理解 MySQL 中的 <=> 操作符?

    问题 : 我在看以前的一个开发者的代码时看到 WHERE p.name <=> NULL 在这个查询语句中 <=>符号是什么意思啊?是不是和 =号是一样啊?还是一个语法错误啊? ...

  10. 2016网易实习生编程题:n个骰子的和等于m

    题目 骰子的点数是1 到 6,当有n个骰子的时候,其点数和等于m的数量 如当n = 4 m = 23时候 有下面四种: 5666656666566665 解题 深度优先,开始第一感觉很复杂,然后就没有 ...