来自FallDream的博客,未经允许,请勿转载,谢谢。


有毒的一场div2 找了个1300的小号,结果B题题目看错没交  D题题目剧毒 E题差了10秒钟没交上去。

233

-------

A.Sagheer and Crossroads

有一个十字路口,分别给出每个方向左右转和直行以及行人的红绿灯的状态,求有没有可能有行人会被车撞

大判断。  附上大佬@ACMLCZH的代码

#include <cstdio>
#include <cstring>
int a[][]; inline int read()
{
int n=,f=; char c=getchar();
while (c<'' || c>'') {if(c=='-')f=-; c=getchar();}
while (c>='' && c<='') {n=n*+c-''; c=getchar();}
return n*f;
} int main()
{
register int i,j,x,y;
for (i=;i<;++i)
for (j=;j<;++j) a[i][j]=read();
for (i=;i<;++i)
for (j=;j<;++j) if (a[i][j]&&a[i][]) return *printf("YES");
if (a[][]) if (a[][]||a[][]||a[][]) return *printf("YES");
if (a[][]) if (a[][]||a[][]||a[][]) return *printf("YES");
if (a[][]) if (a[][]||a[][]||a[][]) return *printf("YES");
if (a[][]) if (a[][]||a[][]||a[][]) return *printf("YES");
printf("NO");
}

B Sagheer, the Hausmeister

给定一个宿舍,两边是楼梯,中间是房间,有些房间有灯亮着,你要从1楼向上走,把一层的灯关完之后才能上楼,问把所有的灯关完至少要走多少步。

直接dp,f[i][0/1]表示关完前i层在左/右边的最小步数。

#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
int x = , f = ; char ch = getchar();
while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x * f;
} int n,m,r[],l[],f[][];
char st[][]; int main()
{
n=read();m=read()+;
for(int i=;i<=n;++i) scanf("%s",st[i]+);
for(int i=;i<=n;++i)
{
for(int j=m;j;--j)
if(st[i][j]=='') {r[i]=j;break;}
for(int j=;j<=m;++j)
if(st[i][j]=='') {l[i]=j;break;}
}
int i=;
for(;i<=n&&!r[i];++i);
if(i>n) return *puts("");
f[i][]=r[i]-,f[i][]=m-l[i];
for(++i;i<=n;++i)
{
if(!r[i]) f[i][]=f[i-][]+,f[i][]=f[i-][]+;
else
{
f[i][]=min(f[i-][]+*(r[i]-)+,f[i-][]+m);
f[i][]=min(f[i-][]+*(m-l[i])+,f[i-][]+m);
}
}
printf("%d\n",min(f[n][],f[n][]+m-));
return ;
}

C. Sagheer and Nubian Market

有n个物品,基础价格是ci,买k个物品的话价格会变成ci+k*i,求最多能买几个

二分答案,然后排序一下就好了

#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
int x;char c;
while((c=getchar())<''||c>'');
for(x=c-'';(c=getchar())>=''&&c<='';)x=(x<<)+(x<<)+c-'';
return x;
}
#define MN 100000
int a[MN+];
long long v[MN+];
int main()
{
int n,m,i,j,l,r,mid,ans,c;
n=read();m=read();
for(i=;i<=n;++i)a[i]=read();
for(l=,r=n;l<=r;)
{
mid=l+r>>;
for(i=;i<=n;++i)v[i]=a[i]+1LL*i*mid;
sort(v+,v+n+);
for(i=,j=m;i<=mid;++i)if(j>=v[i])j-=v[i];else break;
if(i>mid)l=mid+,ans=mid,c=m-j;else r=mid-;
}
printf("%d %d",ans,c);
}

D.毒题

好好写题面不好吗?考验读题能力????

E.Sagheer and Apple Tree

给你一棵树,每个点有一些苹果。两个人博弈。

每次选择一种操作

1)选择一个叶子节点,吃掉一些苹果。

2)选择一个非叶子节点,把一些苹果移到它的儿子处。

n<=10^5 满足叶子结点奇偶性相同。

求有多少种方法交换两个点的苹果数量,后手必胜?

发现当与叶子结同奇偶的苹果树塔起来等于0的时候后手必胜。

枚举换哪个,用个桶统计方案数。

然后如果一开始就是0,偶数深度之间随便换,奇数也是。

#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
int x = , f = ; char ch = getchar();
while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x * f;
} int n,head[MN+],s[],s2[],cnt=,a[MN+];
struct edge{int to,next;}e[MN*+]; inline void ins(int f,int t)
{
e[++cnt]=(edge){t,head[f]};head[f]=cnt;
}
int dd,d[MN+];
void Dfs(int x,int fa,int dep)
{
d[x]=dep;
if(dep&) ++s[a[x]];else ++s2[a[x]];
int son=;
for(int i=head[x];i;i=e[i].next)
if(e[i].to!=fa)
++son,Dfs(e[i].to,x,dep+);
if(!son) dd=dep;
} int main()
{
n=read();
for(int i=;i<=n;++i) a[i]=read();
for(int i=;i<=n;++i)
{
int fa=read();
ins(fa,i);ins(i,fa);
}
Dfs(,,);int ans=,num=;
for(int i=;i<=n;++i)
if((d[i]&)==(dd&))
ans^=a[i],++num;
long long aa=;
for(int i=;i<=n;++i)
if((d[i]&)==(dd&))
aa+=(dd&)?s2[a[i]^ans]:s[a[i]^ans];
if(ans==) aa+=1LL*num*(num-)/+1LL*(n-num)*(n-num-)/;
cout<<aa;
return ;
}

[Codeforces Round#417 Div.2]的更多相关文章

  1. Codeforces Round #417 (Div. 2) D. Sagheer and Kindergarten(树中判祖先)

    http://codeforces.com/contest/812/problem/D 题意: 现在有n个孩子,m个玩具,每次输入x y,表示x孩子想要y玩具,如果y玩具没人玩,那么x就可以去玩,如果 ...

  2. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    http://codeforces.com/contest/812/problem/B 题意: 有n层楼,每层楼有m个房间,1表示灯开着,0表示灯关了.最两侧的是楼梯. 现在每从一个房间移动到另一个房 ...

  3. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister —— DP

    题目链接:http://codeforces.com/problemset/problem/812/B B. Sagheer, the Hausmeister time limit per test ...

  4. Codeforces Round #417 (Div. 2)-A. Sagheer and Crossroad

    [题意概述] 在一个十字路口 ,给定红绿灯的情况, 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道,判断汽车是否有可能撞到行人 [题目分析] 需要在逻辑上清晰,只需要把所有情况列出来即可 ...

  5. Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. Codeforces Round #417 (Div. 2)A B C E 模拟 枚举 二分 阶梯博弈

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. 【二分】Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market

    傻逼二分 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...

  8. 【动态规划】Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    预处理每一层最左侧的1的位置,以及最右侧的1的位置. f(i,0)表示第i层,从左侧上来的最小值.f(i,1)表示从右侧上来. 转移方程请看代码. #include<cstdio> #in ...

  9. Codeforces Round #417 (Div. 2) 花式被虐

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

随机推荐

  1. Flask 视图

    写个验证用户登录的装饰器:在调用函数前,先检查session里有没有用户 from functools import wraps from flask import session, abort de ...

  2. 完美解决某法院HP EVA8400删除VDISK问题

    [故障描述] 某地法院一台HP EVA8400存储,2组扩展柜,物理磁盘由12个1T FATA磁盘(AG691A 454414-001)和10个300G 15K FC磁盘(AG690A 454411- ...

  3. MongoDb进阶实践之三 MongoDB查询命令详述

    一.引言           上一篇文章我们已经介绍了MongoDB数据库的最基本操作,包括数据库的创建.使用和删除数据库,文档的操作也涉及到了文档的创建.删除.更新和查询,当然也包括集合的创建.重命 ...

  4. python 字符串的方法

    capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...

  5. Delphi Web开发连载 --ThinkDelphi (序)

    如果把Delphi比作男人,那他曾经独步天下,笑傲江湖过: 如果把Delphi比作女子,那她曾经貌美如花,倾国倾城过! 但那只是历史,那只是曾经, 弹指一挥间,Delphi却似乎英雄迟暮,美人已老.. ...

  6. cookieUtil

    public class CookieUtil { /** * 设置cookie * @param name cookie名字 * @param value cookie值 * @param maxA ...

  7. Docker加速器(阿里云)

    1. 登录阿里开发者平台: https://dev.aliyun.com/search.html,https://cr.console.aliyun.com/#/accelerator,生成专属链接 ...

  8. Docker学习笔记 - Docker的数据卷容器

    一.什么是数据卷容器 如果你有一些持续更新的数据需要在容器之间共享,最好创建数据卷容器. 数据卷容器:用于容器间的数据共享,主动挂载宿主机目录,用于其他容器挂载和共享. 二.数据卷容器的操作 1.创建 ...

  9. CTF中常见密码题解密网站总结

    0x00.综合 网站中包含大多编码的解码. http://web2hack.org/xssee/ https://www.sojson.com/ http://web.chacuo.net/ 0x01 ...

  10. System Rules 更好的测试

    1:编写测试事例时候,我们要从控制台拿到数据与断言进行对比,通常要编写jdk 标准输出的屏蔽控制器.文章标题的包,能够更好的为我们进行工作. package demo2; import static ...