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 ...
随机推荐
- mkfifo
管道是Linux的十种文件类型之一,使用管道通信本质上还是以文件作为通信的媒介 有名管道+无名管道=管道 有名管道(FIFO文件):就是 有文件名的管道, 可以用于任意两个进程间的通信 无名管道(pi ...
- x01.BitmapHelper:图像处理
“所有致我于死地的,也激发我胆魄”,姚贝娜的<心火>,是我近年来听过最好的歌,特此推荐一下. 图像处理,大概分三步:1.LockBits():2.进行处理:3.UnlockBits():这 ...
- Android控件开发之Chronometer(转)
(转自:http://blog.csdn.net/sun6255028/article/details/6688349) Chronometr是一个简单的定时器,你可以给它一个开始时间,并以此定时,或 ...
- JAVA学习网址收藏
什么是JDK?http://baike.baidu.com/subview/25214/5047948.htm?fr=aladdin Java经典入门教程(环境说明) http://wenku.bai ...
- 报表session与应用session常识普及
1. 报表session与应用session 报表集成到项目中可能会有一个疑问就是系统应用和报表应用在一个web服务器下,那系统session和报表session是不是一个session呢?如果不是那 ...
- [转]NPOI导出EXCEL 打印设置分页及打印标题
本文转自:http://www.cnblogs.com/Gyoung/p/4483475.html 在用NPOI导出EXCEL的时候设置分页,在网上有查到用sheet1.SetRowBreak(i)方 ...
- POJ3463Sightseeing[次短路计数]
Sightseeing Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8707 Accepted: 3056 Descr ...
- Ajax与jQuery、json
一.Ajax简介 Ajax(Asynchronous JavaScript and Xml)--异步刷新技术 Ajax的关键元素包括以下内容: ① JavaScript语言:Ajax技术的主要开发语言 ...
- VS使用Sublime Text 主题
VS主题需求 VS默认有三种主题Dark,Light,Blue,但你是否想寻找其它的主题呢?本文介绍两种方法来满足你的不同需求 1.微软官方扩展 微软官方推出的 Visaul Studio Color ...
- Windows 2008 R2 64位上安装wamp失败的原因
Exception Exception in module wampmanager.exe at 000F15A0... 因测试PHP程序需要,需要在windows系统上布署WAMP环境测试程序,对性 ...