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 ...
随机推荐
- C#读取XML文件
--硬盘Xml文件存储路径:d:\xmlFile\Testxml.xml xml文件内容: <Root> <Tab> <ID>245575913</ID> ...
- 关于InnoDB的Next-Key lock
最近一段时间在准备新员工培训的材料,本来打算介绍介绍概念就OK的,但是既然写了事务的章节,就特别想介绍一下锁,介绍了锁,就忍不住想介绍一下Next-Key Lock. 大家知道,标准的事务隔离级别有R ...
- MySQL字符集的修改和查看
1.关于MySQL字符集 MySQL的字符集支持(Character Set Support)有两个方面: 字符集(Character set)和排序方式(Collation). MySQL对于字符集 ...
- IO的多路复用和信号驱动
Linux为多路复用IO提供了较多的接口,有select(),pselect(),poll()的方式,继承自BSD和System V 两大派系. select模型比较简单,“轮询”检测fd_set的状 ...
- 【转帖】4412ARM开发板学习笔记(一)
本文转自迅为论坛:http://www.topeetboard.com 新手在进行开发学习前,建议先看01-迅为电子开发板入门视频.对开发板和开发环境有一定的了解后,不要盲目接线开机.以下是个人的一点 ...
- 查看centos系统版本
1.查看系统版本 [root@yl-web yl]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) 2.查看内核版本 [ro ...
- Hacker communities collection
Copy from E安全 Hack Forums: Hack Forums是目前最为理想的黑客技术学习根据地.该论坛不仅在设计上面向黑客群体,同时也适用于开发人员.博主.游戏开发者.程序员.图形设计 ...
- 自学一个月的java了
不知道这篇博文有不有朋友看到.先自我介绍一下,硕士一年级下学期. 对编程感兴趣,硕士一年级下学期转学计算机专业,目前刚好一个月的时间.接触计算机也是刚好一个月的时间. 学习了java,javaweb. ...
- Vijos1680距离/openjudge2988计算字符串的距离[DP]
描述 设有字符串X,我们称在X的头尾及中间插入任意多个空格后构成的新字符串为X的扩展串,如字符串X为”abcbcd”,则字符串“abcb_c_”,“_a_bcbcd_”和“abcb_c_”都是X的扩展 ...
- swfdump——从内存中提取swf的工具
刚刚整理代码时发现以前写的从进程的内存镜像中提取swf文件的工具,现在分享出来,希望能帮到有需要的朋友.这个小工具是命令行使用,没有界面,可以很方便的从指定进程中(比如浏览器,swf播放器等等),按s ...