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. android viewpager 图片翻页例子

    使用ViewPager这个类可以轻松实现多个页面的滑动功能 viewpager默认在工具界面上是找不到的,需求添加android-support-v4.jar包: 如果没有找到,需要打开Android ...

  2. 关于 RTL8723BS 同时开启 STA/AP 模式

    最近接到一个调试 wifi 驱动的任务,使用的是 rtl8723bs 芯片组.要求是让无线设备工作在 station 模式的时候同时开启一个 ap 热点.简单来讲就是连接其他 wifi 的同时发出一个 ...

  3. 【转载国外好文】代工开发一个iOS应用没有那么容易

    导读:这是来自新加坡的 iOS 开发者 Kent Nguyen 发表在1月底的一篇博文.这篇吐槽文在 iOS 开发圈子里流传甚广,从原文150多个评论就可见一斑,现翻译如下. 让我们开门见山吧:做一个 ...

  4. 模版(template)

    模版(template) 在c++Template中很多地方都用到了typename与class这两个关键字,而且好像可以替换,是不是这两个关键字完全一样呢? 相信学习C++的人对class这个关键字 ...

  5. 《深入.NET平台和C# 编程》内部测试 笔试题

    1:在C#中,关于文件操作相关的类说法正确的是(AB) <选择二项> A:FileInfo类提供了用于操作文件的实例方法 B:File类提供了用于操作文件的静态方法 C:Directory ...

  6. 在JAVA中ArrayList如何保证线程安全

    [b]保证线程安全的三种方法:[/b]不要跨线程访问共享变量使共享变量是final类型的将共享变量的操作加上同步一开始就将类设计成线程安全的, 比在后期重新修复它,更容易.编写多线程程序, 首先保证它 ...

  7. 转: rapidJSON与jsoncpp语法说明

    转:  http://www.voidcn.com/blog/hudejun007/article/p-1811986.html

  8. luogu1003铺地毯[noip2011 提高组 Day1 T1]

    题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小到大的顺序平行于 ...

  9. Android之监听手机软键盘弹起与关闭

    背景: 在很多App开发过程中需要在Activity中监听Android设备的软键盘弹起与关闭,但是Android似乎没有提供相关的的监听API给我们来调用,本文提供了一个可行的办法来监听软键盘的弹起 ...

  10. 关于oracle with as用法

    with as语法–针对一个别名with tmp as (select * from tb_name) –针对多个别名with   tmp as (select * from tb_name),   ...