A题,水题略过。

  B题,也水,但是想复杂了。只要运动超出[0,20000]的范围就算不可能了。

  C题,我自己的方法是解不等式,然后取最大的答案即可。代码如下:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
const int N = + ;
const int inf = 2e9; int main()
{
int L = -inf, R = -inf;
int n; cin >> n;
//int add = 0;
int pre = ;
for(int i=;i<=n;i++)
{
int change, d;
scanf("%d%d",&change, &d);
//add += change;
if(d == )
{
if(L == -inf) L = - pre;
else L = max(L, - pre);
}
else
{
if(R == -inf) R = - pre;
else R = min(R, - pre);
}
pre += change;
}
if(L != -inf && R != -inf && L > R) puts("Impossible");
else if(L != -inf && R == -inf) puts("Infinity");
else printf("%d\n",R + pre);
return ;
}

C

  D题是记忆化搜索,补题的时候没做出来。。代码如下:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
using namespace std;
const int N = + ;
const int inf = 2e9;
typedef pair<int,int> pii; int dirx[] = {,,,,-,-,-,};
int diry[] = {,,-,-,-,,,};
int vis[][][N][N];
int t[], n;
int mp[N][N]; void dfs(int pos, int dir, int x, int y)
{
if(pos > n || vis[pos][dir][x][y]) return ;
vis[pos][dir][x][y] = ;
for(int i=;i<t[pos];i++) mp[x+dirx[dir]*i][y+diry[dir]*i] = ;
x += dirx[dir] * (t[pos] - );
y += diry[dir] * (t[pos] - );
dfs(pos+, (dir+)%, x+dirx[(dir+)%], y+diry[(dir+)%]);
dfs(pos+, (dir+)%, x+dirx[(dir+)%], y+diry[(dir+)%]);
} int main()
{
cin >> n;
for(int i=;i<=n;i++) scanf("%d",t+i);
dfs(,,N/,N/);
int ans = ;
for(int i=;i<N;i++)
{
for(int j=;j<N;j++) ans += mp[i][j];
}
cout << ans << endl;
return ;
}

D

  E题,好题。用0~4分别表示拥有2017的前若干个字母的情况,x[i][j]表示从i状态转移到j状态需要删除几个字符,然后进行转移。并且用线段树进行维护答案。具体见代码:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#define ls (o<<1)
#define rs (o<<1|1)
#define t_mid (l+r>>1)
#define lson ls,l,t_mid
#define rson rs,t_mid+1,r
using namespace std;
const int N = + ;
const int inf = 0x3f3f3f3f;
typedef pair<int,int> pii; int n,q;
char s[N];
struct node
{
int x[][];
node operator + (const node A) const
{
node ans;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
ans.x[i][j] = inf;
for(int k=;k<;k++) ans.x[i][j] = min(ans.x[i][j], x[i][k] + A.x[k][j]);
}
}
return ans;
}
}p[N<<]; void build(int o,int l,int r)
{
if(l == r)
{
for(int i=;i<;i++) for(int j=;j<;j++) p[o].x[i][j] = i==j ? : inf;
if(s[l] == '')
{
p[o].x[][] = ;
p[o].x[][] = ;
}
else if(s[l] == '')
{
p[o].x[][] = ;
p[o].x[][] = ;
}
else if(s[l] == '')
{
p[o].x[][] = ;
p[o].x[][] = ;
}
else if(s[l] == '')
{
p[o].x[][] = ;
p[o].x[][] = ;
}
else if(s[l] == '')
{
p[o].x[][] = ;
p[o].x[][] = ; // 已经有2017,现在多出6,要删掉6
}
return ;
}
build(lson);
build(rson);
// up(o)
p[o] = p[ls] + p[rs];
} node query(int o,int l,int r,int ql,int qr)
{
if(l == ql && r == qr) return p[o];
if(qr <= t_mid) return query(lson,ql,qr);
else if(ql > t_mid) return query(rson,ql,qr);
else return query(lson,ql,t_mid) + query(rson,t_mid+,qr);
} int main()
{
cin >> n >> q;
scanf("%s",s+);
build(,,n);
while(q--)
{
int l, r;
scanf("%d%d",&l, &r);
int ans = query(,,n,l,r).x[][];
printf("%d\n",ans == inf ? - : ans);
}
return ;
}

E

CodeForces Good Bye 2016的更多相关文章

  1. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  2. Codeforces Good Bye 2016 题解

    好久没有fst题了...比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完...然后C题fst掉了结果就掉rating 了...下面放题解 ### [A. New ...

  3. Codeforces Good Bye 2016 E. New Year and Old Subsequence

    传送门 题意: 给出一个长度为\(n\)的串,现在有\(q\)个询问,每个询问是一个区间\([l,r]\),要回答在区间\([l,r]\)中,最少需要删多少个数,满足区间中包含\(2017\)的子序列 ...

  4. Codeforces Good Bye 2016 D 模拟搜索?

    给出烟花的爆炸方式和爆炸次数 问最后有多少个格子会被炸到 如果dfs的话会超时... 利用模拟每一层来搜索..? 思想就是一开始有一个爆炸点向上 然后模拟完第一段 会产生一个爆炸点 朝两个方向 就用v ...

  5. Codeforces Good Bye 2015 A. New Year and Days 水题

    A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...

  6. Codeforces:Good Bye 2018(题解)

    Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...

  7. Good Bye 2016 - D

    题目链接:http://codeforces.com/contest/750/problem/D 题意:新年烟花爆炸后会往两端45°差分裂.分裂完后变成2部分,之后这2部分继续按这种规则分裂.现在给你 ...

  8. Good Bye 2016 - C

    题目链接:http://codeforces.com/contest/750/problem/C 题意:在CF中,每个人都有个Rank值. 当Rank>=1900时,为DIV1.Rank< ...

  9. Good Bye 2016 - B

    题目链接:http://codeforces.com/contest/750/problem/B 题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走. ...

随机推荐

  1. C#使用phantomjs,爬取AJAX加载完成之后的页面

    1.开发思路:入参根据apiSetting配置文件,分配静态文件存储地址,可实现不同站点的静态页生成功能.静态页生成功能使用无头浏览器生成,生成之后的字符串进行正则替换为固定地址,实现本地正常访问. ...

  2. 如何使用classnames模块库为react动态添加class类样式

    摘要 在react中添加动态的css时,传统的方式较为繁琐,今天刚好学习到一个模块库可以便捷的解决这个问题.对的,它就是“classnames”. classnames模块库 npm安装 npm in ...

  3. 原生js实现选项卡样式切换的几种方式。

    先分享一个不能实现的实例(因为es5没有块作用域) for(var i=0; i<list.length; i++ ) { list[i].onclick = function(){ tabch ...

  4. sql server 语句书写注意事项

    1  Between在某些时候比IN 2 在必要是对全局或者局部临时表创建索引,有时能够提高速度,但不是一定会这样,因为索引也耗费大量的资源.他的创建同是实际表一样 3 尽量少用视图,它的效率低.对视 ...

  5. GitHub代码复现之opencv

    GitHub代码复现之opencv链接:https://github.com/vonzhou/opencv 待解决!!! ISSUE汇总: Issue1:vs2015找不到配置dirent.h头文件? ...

  6. List.ForEach批量新增并发异常解决

    批量新增操作在业务系统中十分常见,尤其是主从表中对从表的批量处理.昨天在对wms主从表进行业务操作时使用了c#中list自带的函数ForEach对从表批量新增,代码如下: 在无并发的情况下接口请求正常 ...

  7. 【linux】ubuntu修改系统时间

    ubuntu修改时间步骤 ① 先把系统校验时间的程序停止掉 /lib/systemd/systemd-timesyncd systemd 开始,包括了一个名为systemd-timesyncd 的守护 ...

  8. iview 如何在表格中给操作图标添加Tooltip文字提示?

    项目需要用到的iview 表格中操作项目有各种各样的图标,而各种各样的图标代表不同的操作,面对新用户可能很懵,那如何给这些图标添加Tooltip文字提示? 废话不多讲,直接看代码: <templ ...

  9. cmake学习笔记之add_library、target_link_libraries和link_directories

    cmake是Linux(这里默认是Ubuntu系统)下常使用的编译C++的工具,而使用cmake就需要先在CmakeLists.txt文件中对编译规则进行.这里介绍常用的三种指令add_library ...

  10. 【WEB】jQuery 判断复选框是否选中

    1.背景 在 jQuery 1.6 版本之前,判断方式 <input type='checkbox' id='test'/> <script> var isChecked = ...