A

题意:O(-1)

思路:排个序搞定。

B

题意:O(-1)

思路:坑了我好久,这个框框水平垂直比例固定,分两种情况即可,不能旋转,我想多了,分了四种情况。

C

题意:一列n个位置,让你填m个数,当连续数达到k时,分数乘以2,计数清零,当不连续时,计数也清零,没到达k之前分数+1.

思路:很显然的问题是让我们处理填m个位置,并且使连续的k个数次数最少。我们先让m个数k-1每次填,填一次空一位,直到不够填了就往前面的空位填。设连续k个次数为mm,那么就是(((2*k)+k)*2……+k)*2,等比数列求和之后为k*(2^mm-2),不连续k的值为m-mm*k。注意要注意了细节很多,WA了两次。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; typedef long long lld;
const lld mod=; lld Pow(lld a, int b)
{
lld ans=;
while(b)
{
if(b&) ans=(ans*a)%mod;
b>>=;
a=(a*a)%mod;
}
return ans%mod;
} int main()
{
lld n, m, k;
while(cin >> n >> m >> k)
{
lld c1, c2, s1, num, mm, ans=;
c1=n/k, s1=n%k;
c2=m/(k-);
num=min(c1,c2);
if(c1>c2) s1+=k*(c1-c2);
mm=m-num*(k-);
mm-=min(mm,s1);
if(mm) ans=(k*((Pow(,mm+)-+mod)%mod))%mod;
ans=(ans+m-k*mm%mod+mod)%mod;
cout << ans <<endl;
}
}
/*
23888888 508125 3
*/

D

题意:有一颗n个节点的树,树中有m个恶魔,然后给你一个控制距离d,问你树中哪些节点能控制住所有恶魔(离最远恶魔距离小于等于d)。

思路:很显然的树形dp,开始没考虑清楚一点,把所有节点的最长半径以及次长半径都初始化为0,这样会存在一个小bug,因为当有一个恶魔节点存在树中(此时此节点最长半径为0),父亲节点的最长半径为此节点更新上去的,传递下来的时候此节点只能利用父亲节点的次长半径,当次长半径初始化为0时,此时更新此节点的话次长半径就要大于最长半径,所以节点最长半径和次长半径初始化为-oo,有恶魔的节点最长半径改为0即可,开始没考虑到这点。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
using namespace std; const int maxn=;
const int oo=0x3fffffff;
int fmax[maxn], smax[maxn], color[maxn], f[maxn];
vector<int>vt[maxn];
int n, m, d; void init()
{
for(int i=; i<=n; i++)
{
vt[i].clear();
fmax[i]=smax[i]=-oo;
color[i]=f[i]=;
}
} void dfs(int u, int fa)
{
for(int i=; i<vt[u].size(); i++)
{
int v=vt[u][i];
if(v==fa) continue;
dfs(v,u);
if(color[v])
{
color[u]++;
if(fmax[v]+>fmax[u]) smax[u]=fmax[u], fmax[u]=fmax[v]+;
else if(fmax[v]+>smax[u]) smax[u]=fmax[v]+;
}
}
} void DFS(int u, int fa)
{
if(u==) ;
else
{
if(fmax[fa]-==fmax[u])
{
if(smax[fa]+>fmax[u]) smax[u]=fmax[u], fmax[u]=smax[fa]+;
else if(smax[fa]+>smax[u]) smax[u]=smax[fa]+;
}
else
{
if(fmax[fa]+>fmax[u]) smax[u]=fmax[u], fmax[u]=fmax[fa]+;
else if(fmax[fa]+>smax[u]) smax[u]=fmax[fa]+;
}
}
for(int i=; i<vt[u].size(); i++)
if(vt[u][i]!=fa)DFS(vt[u][i],u);
} int bfs(int st)
{
int ans=;
queue<int>q;
q.push(st);
while(!q.empty())
{
int u=q.front();
q.pop();
if(fmax[u]<=d) ans++;
for(int i=; i<vt[u].size(); i++)
{
int v=vt[u][i];
if(v==f[u]) continue;
f[v]=u;
q.push(v);
}
}
return ans;
} int main()
{
while(cin >> n >> m >> d)
{
init();
int u, v;
for(int i=; i<=m; i++)
{
scanf("%d",&u);
color[u]=;
fmax[u]=;
}
for(int i=; i<n; i++)
{
scanf("%d%d",&u,&v);
vt[u].push_back(v);
vt[v].push_back(u);
}
dfs(,);
DFS(,);
int ans=bfs();
cout << ans <<endl;
}
return ;
}
/*
10 1 0
3
10 1
9 4
4 5
6 4
2 4
7 5
8 3
5 3
1 3 1
*/

Codeforces Round #196 (Div. 2)的更多相关文章

  1. Codeforces Round #196 (Div. 2) D. Book of Evil 树形dp

    题目链接: http://codeforces.com/problemset/problem/337/D D. Book of Evil time limit per test2 secondsmem ...

  2. Codeforces Round #196 (Div. 1) 题解

    (CF唯一不好的地方就是时差……不过还好没去考,考的话就等着滚回Div. 2了……) A - Quiz 裸的贪心,不过要用矩阵乘法优化或者直接推通式然后快速幂.不过本傻叉做的时候脑子一片混乱,导致WA ...

  3. Codeforces Round #196 (Div. 2) B. Routine Problem

    screen 尺寸为a:b video 尺寸为 c:d 如果a == c 则 面积比为 cd/ab=ad/cb (ad < cb) 如果b == d 则 面积比为 cd/ab=cb/ad  (c ...

  4. A. Puzzles CodeForces Round #196 (Div.2)

    题目的大意是,给你 m 个数字,让你从中选 n 个,使得选出的数字的极差最小. 好吧,超级大水题.因为要极差最小,所以当然想到要排个序咯,然后去连续的 n 个数字,因为数据不大,所以排完序之后直接暴力 ...

  5. Codeforces Round #196 (Div. 2) A. Puzzles 水题

    A. Puzzles Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...

  6. Codeforces Round #196 (Div. 2) 少部分题解

    A:sort以后求差值最小 ]; int main() { int n,m; cin>>n>>m; ; i < m ; i++) cin>>a[i]; sor ...

  7. Codeforces Round #196 (Div. 1 + Div. 2)

    A. Puzzles 对\(f[]\)排序,取连续的\(m\)个. B. Routine Problem 考虑\(\frac{a}{b}\)和\(\frac{c}{d}\)的大小关系,适配后就是分数的 ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. Android 弹出对话框Dialog充满屏幕宽度

    final View view = LayoutInflater.from(context).inflate(layoutId, null); final Dialog dialog = new Di ...

  2. rem单位在手机网站中的使用

    em单位是相对于父节点的font-size,会有一些组合的问题,而rem是相对于根节点(或者是html节点),也就是说你可以在html节点定义一个单独的字体大小,然后所有其他元素使用rem相对于这个字 ...

  3. 如何查看经过编码的cookie?

    方法1.去在线工具网站(http://tool.oschina.net/encode?type=2)手动复制编码的cookie,转码后查看. 方法2.用火狐浏览器打开网页,如果有历史记录(存在cook ...

  4. MySql 查询数据库中所有表名

    查询数据库中所有表名select table_name from information_schema.tables where table_schema='csdb' and table_type= ...

  5. 《Getting Started with Storm》章节一 基础

    注:括号里的字,并且是(灰色)的,是我个人的理解,如有差错,欢迎交流 Storm是一个分布式的.可靠的.容错的数据流处理系统(流式计算框架,可以和mapreduce的离线计算框架对比理解).整个任务被 ...

  6. MongoDB 入门之基础 DML

    此文章主要记录部分主要的 MongoDB Collection 的 DML 操作. 文章中的 Collection 名字为 yourColl,每一次操作包含以下两条初始数据 { "_id&q ...

  7. java基础-基本数据类型

    浏览以下内容前,请点击并阅读 声明 java有八种基本数据类型,其中包括: byte,字节型,是8位带符号的整数,即其范围在-128和127之间(包括) short,短整型,是16位带符号的整数,范围 ...

  8. 4D时间管理

    时间管理的4D原则   时间矩阵:每个人,每天要做的事情大致分为四类:一类:必须做的,不做会产生不良后果的二类:需要做的,为将来或者今后阶段做准备工作的三类:可以不做,但又不得不做的,例如通过简约形式 ...

  9. 移动端HTML5资源整理

    目录 meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 忽略将页面中的数字识别为电话号码 忽略Android平台中对邮箱地址的识别 当网站添加到主屏幕快速启动方式,可隐藏地址栏,仅 ...

  10. hdu 1097 A hard puzzle

    Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...