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)的更多相关文章

  1. Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化

    E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. itextpd f生成 pdf 文件

    一.简介 itextpdf 是一个开源的允许你去创建和操作PDF文档的库.它使的开发者可以提高web和其他应用来动态地生成或操作PDF文档.通过iText 中的Document和PdfWriter类, ...

  2. CSS3之让背景图片全部显示

    起初是在处理一个图片显示的问题, 图片没有有一部分没有显示出来, 之后用到了background-size, 发现有必要总结一下. background-size 首先声明 background-si ...

  3. Android中在sdcard上创建文件夹

    //在SD卡上创建一个文件夹    public void createSDCardDir(){     if(Environment.MEDIA_MOUNTED.equals(Environment ...

  4. Linux rm 删除文件

    rm 删除文件rm -f 强制删除-i 提示-r 删除目录的时候-v 可实话 rm -rfv 多目录 不提示 [root@wang whp]# touch .txt [root@wang whp]# ...

  5. CentOS 6.3下配置软RAID(Software RAID)

    一.RAID 简介 RAID 是英文Redundant Array of Independent Disks 的缩写,翻译成中文意思是“独立磁盘冗余阵列”,有时也简称磁盘阵列(Disk Array). ...

  6. SpringMVC从入门到精通之第一章

    第一节 简介:SpringMVC是Spring框架的一个模块,Spring和SpringMVC无需通过中间整合层进行整合.SpringMVC是基于MVC的WEB框架.MVC设计模式在B/S下的应用: ...

  7. 以最简单的登录为例,诠释JS面向对象的简单实例

    JavaScript,是前端开发人员必须会的一门技术,从JS演变出来的有很多框架,先说说几个热门的框架吧: JQuery:这个技术必须会,如果不会,那一定要会查api,知道怎么写,要看得懂英文文档,这 ...

  8. u-boot移植初步尝试-tiny4412

    获取u-boot源代码 在u-boot官方网站下载uboot源码.ftp://ftp.denx.de/pub/u-boot/ 因为是第一次移植uboot,所以这里选的版本是 u-boot-2013.0 ...

  9. CocoaPods 哪些事

    一.CocoaPods的介绍 什么是CocoaPods CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为“Pods”的依赖库(这些类库必 ...

  10. iOS本地化

    本地化与相机中显示英文  工程PROJECT -> info ->Localizations 添加相应的国际化语言  一.当你发现相机中显示英文,可以通过它设置 添加一项“Localize ...