来自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. 201621123043 《Java程序设计》第3周学习总结

    1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系.步骤如下: 1.1 写出你 ...

  2. 从PRISM开始学WPF(三)Prism-Region?

    从PRISM开始学WPF(一)WPF? 从PRISM开始学WPF(二)Prism? 从PRISM开始学WPF(三)Prism-Region? 从PRISM开始学WPF(四)Prism-Module? ...

  3. 如何进行服务器Linux系统下的ext文件系统修复

    一.故障描述 服务器是dell 730系列服务器,存储阵列是MD3200系列存储5T的Lun,操作系统是Linux centos 7,文件系统类型是EXT4,因意外断电,导致系统不能正常启动,修复之后 ...

  4. Linux入门(1)_VMware和系统分区和系统安装和远程登陆管理

    1 VMware的安装和使用 注意有 快照 和 克隆 的功能. 快照相当于建立一个 系统还原点, 可以随时恢复到原来状态. 克隆功能可以复制一个和当前一样的系统,并可以选择链接安装,只使用很少的空间就 ...

  5. Python-进程与线程理论基础-Day10

    进程与线程理论基础 1.背景知识 理论基础: 一 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬件的竞争变得有序 二 多道技术: 1.产生背景 ...

  6. sts中maven

    建立一个maven web的工程 网上有很多关于maven的下载,配置等,我这里就不多说了. 下面介绍主要介绍关于在sts中建立一个maven时最开始出现的错误问题. 创建maven工程 file-& ...

  7. Docker加速器(阿里云)

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

  8. SpringCloud是否值得引入?

    中小型互联网公司微服务实践-经验和教训 http://xujin.org/sc/sc-zq/#more Spring Cloud在国内中小型公司能用起来吗?https://mp.weixin.qq.c ...

  9. 新概念英语(1-9)How is Ema?

    A:Hello Helen. B:Hi Steven. A:How are you today? B:I'm very well, thank you. And you? A:I'm fine tha ...

  10. Ubuntu+apt-get update时的源

    源是通过 /etc/apt/sources.list # file /etc/apt/sources.list.d # dir 来确定的, 只要将其中的相应文件/相应行删除了, 在apt-get up ...