Codeforces Round #358(div 2)
A:统计个数题,要注意ans+=a*b+c*d中,如果a*b>int,那么即使ans是long long也会越界,所以ans+=(long long)a*b+(long long)c*d
B:模拟一下删的过程
C:定义一个节点u是sad当且仅当u的子节点中存在一个节点v,使得dist(u,v)>a[v],给定一个树,每次操作只能删除一个叶子节点,问最少删多少次后剩下来的树没有sad点。首先明确这题最后树的形态是确定的,所以这里的求最少也就相当于模拟一遍删除过程,如果我们认定一个节点是sad的(无论是否是叶子节点),那么这个节点肯定要删除不能留下(因为是从下往上删除,所以没有后效性),所以以这个节点为根的子树全部都要删除。于是算法便出来了:从根节点开始dfs,从节点u准备向其子节点遍历的时候,如果其一个子节点v使得之前遍历完的子树中的某个节点为sad,那么v就不能要,就不遍历。最终遍历到的节点就是最后删除后的子树的所有节点。具体操作就是从root开始维护一个动态最大前缀和,与a[v]比较。
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=1e5;
struct claris
{
int to;
long long w;
};
vector<claris> g[maxn+];
long long a[maxn+];
int n,s=;
void dfs(int father,int k,long long maxs)
{
++s;
for(int i=;i<g[k].size();++i)
{
claris e=g[k][i];
if(e.to==father) continue;
long long maxss=max(e.w,e.w+maxs);
if(maxss>a[e.to]) continue;
dfs(k,e.to,maxss);
}
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%lld",&a[i]);
for(int i=;i<=n;++i)
{
int p;
long long c;
scanf("%d %lld",&p,&c);
g[i].push_back((claris){p,c});
g[p].push_back((claris){i,c});
}
dfs(,,);
printf("%d",n-s);
return ;
}
D:SB的字符串匹配DP
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
const int maxn=1e3;
char a[maxn+],b[maxn+];
int n,m,K;
int f[maxn+][maxn+][],s[maxn+][maxn+][];
int main()
{
scanf("%d %d %d\n",&n,&m,&K);
scanf("%s",a+);
scanf("%s",b+);
for(int k=;k<=K;++k)
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
{
s[i][j][k]=max(s[i][j-][k],max(s[i-][j][k],s[i-][j-][k]));
if(a[i]!=b[j]) continue;
int p=;
while(i-p>&&j-p>&&a[i-p]==b[j-p])
{
f[i][j][k]=max(s[i-p-][j-p-][k-]+p+,f[i][j][k]);
++p;
}
s[i][j][k]=max(s[i][j][k],f[i][j][k]);
}
int ans=;
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
ans=max(ans,f[i][j][K]);
printf("%d",ans);
return ;
}
E:这题有点魔性……题意是给你一些整点,围成的图形面积为S,你要找一个整点三角形把所有点围起来并且三角形的面积不超过4S
官方题解:首先肯定想到先求出这些点的凸包,考虑凸包上的点围成的最大面积三角形,它的面积<S,如果把这个整点三角形的三个点作为一个大三角形每条边的中点,那么这个大三角形也是整点三角形且面积是小三角形的4倍,所以这个大三角形面积<4S,而且可以通过反证的思路证明所有点全部在这三角形内,于是问题就转化成了在凸包上找一个面积最大的三角形。采取枚举的办法,枚举两个,剩下一个是单调的,所以O(n^2)可以完成
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=;
struct claris
{
long long x,y;
bool operator < (const claris& p) const
{
return (x<p.x)||(x==p.x&&y<p.y);
}
};
claris a[maxn+],p[maxn+];
int len=,n;
long long s;
bool cross(claris p,claris a,claris b)
{
return (double)(a.x-b.x)*(p.y-a.y)-(p.x-a.x)*(a.y-b.y)>=;
}
double gets(claris p,claris a,claris b)
{
double s=((double)(a.x-p.x)*(b.y-p.y)-(b.x-p.x)*(a.y-p.y))/;
return abs(s);
}
int main()
{
scanf("%d %lld",&n,&s);
for(int i=;i<=n;++i) scanf("%lld %lld",&a[i].x,&a[i].y);
sort(a+,a+n+);
for(int i=;i<=n;++i)
{
while(len>&&!cross(a[i],p[len],p[len-])) --len;
p[++len]=a[i];
}
int k=len;
for(int i=n-;i>=;--i)
{
while(len>k&&!cross(a[i],p[len],p[len-])) --len;
p[++len]=a[i];
}
if(n>) --len;
double ans=;
claris x,y,z;
for(int i=;i<=len;++i)
{
int last=i+;
for(int j=i+;j<=len;++j)
{
int k=last;
while(k<len&&gets(p[i],p[j],p[k+])>gets(p[k],p[i],p[j])) ++k;
last=k;
if(gets(p[k],p[i],p[j])>ans) ans=gets(p[k],p[i],p[j]),x=p[i],y=p[j],z=p[k];
}
}
printf("%lld %lld\n",-x.x+y.x+z.x,-x.y+y.y+z.y);
printf("%lld %lld\n",x.x-y.x+z.x,x.y-y.y+z.y);
printf("%lld %lld",x.x+y.x-z.x,x.y+y.y-z.y);
return ;
}
PS:浅谈long long的重要性……
Codeforces Round #358(div 2)的更多相关文章
- Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化
E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given ...
- Codeforces Round #358 (Div. 2) D. Alyona and Strings dp
D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree 水题
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- Codeforces Round #358 (Div. 2)B. Alyona and Mex
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp
题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes input ...
- Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp
A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- jstl 中<c:forEach />标签
<c:forEach>标签有如下属性: 属性 描述 是否必要 默认值 items 要被循环的信息 否 无 begin 开始的元素(0=第一个元素,1=第二个元素) 否 0 end 最后一个 ...
- 烂泥:【解决】NFS服务器使用showmount –e命令报错
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 今天在NFS服务器使用showmount –e查看NFS共享目录时,发现系统一直显示如下错误: clnt_create: RPC: Port mappe ...
- Ubuntu下安装Pyenv不成功,求指教
虚拟机:VMware12.0 操作系统:Ubuntu16.04 LTS (新安装系统) 已经按照网上的步骤: 1.安装git: $sudo apt-get install git 2.安装依赖包: $ ...
- Vim光标定位
*定位到指定行n: 输入"nG". 或输入"ngg". 或输入":n" 这里,n就是指定的行的行号.注意,有时候G=gg. *跳到屏幕顶部: ...
- 配置nginx好了,html能打开,index.php打不开?
启动这2个 #service nginx restart # service php-fpm restart
- css3选择器(一)
直接开始正文. 一.css3同级元素通用选择器[update20161228] 选择器:E~F 匹配任何在E元素之后的同级F元素 Note:E~F选择器选中的是E元素后面同级元素中的全部F元素. 例: ...
- DPM(voc-release5) Matlab模型文件 Mat转XML
(转载请注明作者和出处 楼燚(yì)航的blog :http://www.cnblogs.com/louyihang loves baiyan/ 未经允许请勿用于商业用途) 由于目前DPM模型训练的代 ...
- java变量的初始化
public class Init { private int age;//非静态初始化语句<3> private static String name; //静态初始化语句,先初始化静态 ...
- using关键字的用法
1.using 关键字可以用来导命名空间,与java中的import类似. 2.using关键字可以用来释放资源,并且被释放的资源代码是非托管代码. 既然可以释放非托管代码,那么什么是非托管代码? 我 ...
- 入门HTML的回顾,小总结
1.HTML(是一种超文本标记语言 Hypertext Markup Language),HTML不是一种编程语言,而是一种标记语言,描述网页的语言,HTML是由一套标记标签(markup tag ...