来自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. 多种在线地图综合对比,Google,必应,arcgis Online...

    不同网络地图的对比 天地图 坐标系:WGS84 地图配色:   POI数量:丰富      有无建筑:有 地图特点:天地图按照国家标准进行配图,道路.水系.植被等图层用对应颜色渲染, POI信息丰富, ...

  2. Docker_部署jenkins(dockerfile实现)

    docker+jenkins开始合体! 我用的是ubuntu14.04的基础镜像,具体的这里不做赘述. 我在/tmp/目录下建了一个Dockerfile文件: touch Dockerfile vi ...

  3. 构建微服务开发环境8————Hello 微服务

    [内容指引] 1.用IDEA打开微服务项目; 2.更新Maven依赖: 3.IntelliJ IDEA JDK配置; 4.修改代码: 5.运行微服务: 6.将代码变更提交到Github. 经过前面的努 ...

  4. 儿童节,我们从零开始——Python入门资源推荐

    原创 2017-06-01 玄魂工作室 玄魂工作室 今天是六一儿童节,首先祝所有的小朋友身体健康,能永远生活在一个没有战争,没有压迫的世界里,永远快乐. 上一篇文章,很多人都对Python的各种书籍感 ...

  5. java 实现多文件打包下载

    jsp页面js代码: function downloadAttached(){ var id = []; id.push(infoid); var options = {}; options.acti ...

  6. 新概念英语(1-99)Ow!

    Lesson 99 Owl! 啊哟! Listen to the tape then answer this question. Must Andy go to see the doctor?听录音, ...

  7. JWT(JSON Web Token) 多网站的单点登录,放弃session

    多个网站之间的登录信息共享, 一种解决方案是基于cookie - session的登录认证方式,这种方式跨域比较复杂. 另一种替代方案是采用基于算法的认证方式, JWT(json web token) ...

  8. ABP CORE 框架入门视频教程《电话薄》基于 Asp.NET Core2.0 EF Core

    ABP框架简介 ABP是"ASP.NET Boilerplate Project (ASP.NET样板项目)"的简称. ASP.NET Boilerplate是一个用最佳实践和流行 ...

  9. Spring Boot面试题

    Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...

  10. python基础—迭代器、生成器

    python基础-迭代器.生成器 1 迭代器定义 迭代的意思是重复做一些事很多次,就像在循环中做的那样. 只要该对象可以实现__iter__方法,就可以进行迭代. 迭代对象调用__iter__方法会返 ...