来自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. Exception in thread "main" expected '<document start>', but found BlockMappingStart in 'reader', line 23, column 2: nimbus.host: "master"

    平台:centos-6.3-i386 jdk-7u51 storm 0.9.1 python 2.6.6   hadoop 1.2.1 启动storm的时候,遇到这个问题,百度之后,看到大家的解决方案 ...

  2. android之SVG制作与应用

    文章解析及例子:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0825/3362.html 工具:Photoshop CC+sv ...

  3. raid5两块硬盘离线怎么办? 强制上线失败如何恢复数据

    服务器故障描述: 客户使用Dell 2850服务器组建了raid5磁盘阵列,阵列中包含有6块硬盘(SCSI硬盘,单盘容量300G),服务器操作系统为linux Redhat4:文件系统为ext3文件系 ...

  4. nyoj 对决

    对决 时间限制:1000 ms  |  内存限制:65535 KB 难度:0   描述 Topcoder 招进来了 n 个新同学,Yougth计划把这个n个同学分成两组,要求每组中每个人必须跟另一组中 ...

  5. linux的链接工具secure设置字体大小和颜色

  6. c# 字符串的内存分配和驻留池( 转 )

    刚开始学习C#的时候,就听说CLR对于String类有一种特别的内存管理机制:有时候,明明声明了两个String类的对象,但是他们偏偏却指向同一个实例.如下: string s1 = "he ...

  7. Spring知识点回顾(01)Java Config

    Spring知识点回顾(01) 一.Java Config 1.服务和服务注入 2.Java 注解 :功能更强一些 3.测试验证 二.注解注入 1.服务和服务注入 2.配置加载 3.测试验证 三.总结 ...

  8. C#程序编写规范

    代码书写规则 1.尽量使用接口,然后使用类实现接口,提高程序的灵活性. 2.一行不要超过80个字符. 3.尽量不要手工更改计算机生成的代码,若必须要改,一定要改为和计算机生成的代码风格一样. 4.关键 ...

  9. python实现 字符串匹配函数

    通配符是 shell 命令中的重要功能,? 表示匹配任意 1 个字符,*表示匹配 0 个或多个字符.请使用你熟悉的编程语言实现一个字符串匹配函数,支持 ? 和 * 通配符.如 "a?cd*d ...

  10. Python生成随机验证码

    Python生成随机验证码,需要使用PIL模块. 安装: pip3 install pillow 基本使用 1.创建图片 from PIL import Image img = Image.new(m ...