CodeForces Good Bye 2016
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的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- Codeforces Good Bye 2016 题解
好久没有fst题了...比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完...然后C题fst掉了结果就掉rating 了...下面放题解 ### [A. New ...
- Codeforces Good Bye 2016 E. New Year and Old Subsequence
传送门 题意: 给出一个长度为\(n\)的串,现在有\(q\)个询问,每个询问是一个区间\([l,r]\),要回答在区间\([l,r]\)中,最少需要删多少个数,满足区间中包含\(2017\)的子序列 ...
- Codeforces Good Bye 2016 D 模拟搜索?
给出烟花的爆炸方式和爆炸次数 问最后有多少个格子会被炸到 如果dfs的话会超时... 利用模拟每一层来搜索..? 思想就是一开始有一个爆炸点向上 然后模拟完第一段 会产生一个爆炸点 朝两个方向 就用v ...
- 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 ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- Good Bye 2016 - D
题目链接:http://codeforces.com/contest/750/problem/D 题意:新年烟花爆炸后会往两端45°差分裂.分裂完后变成2部分,之后这2部分继续按这种规则分裂.现在给你 ...
- Good Bye 2016 - C
题目链接:http://codeforces.com/contest/750/problem/C 题意:在CF中,每个人都有个Rank值. 当Rank>=1900时,为DIV1.Rank< ...
- Good Bye 2016 - B
题目链接:http://codeforces.com/contest/750/problem/B 题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走. ...
随机推荐
- Spring实战(五)Spring中条件化地创建bean
1.@Conditional 为生成bean设置条件 Spring 4中引入了一个新的注解---@Conditional,它用在有@Bean的方法上. 如果给定条件计算结果为true,Spring会创 ...
- 怎样终止HTTP请求
使用 xhr.abort() var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://www.example.com/page.php', tr ...
- ArrayList插入1000w条数据的时间比较分析
一分钟系列: 读懂GC日志 ArrayList插入1000w条数据之后,我怀疑了jvm... Java JIT性能调优 Java性能优化指南系列(三):理解JIT编译器 准备:调试程序加入VM Opt ...
- IExtenderProvider,c#组件扩展控件属性
[ProvideProperty("IsEnabled", typeof(LayoutControlItem)), ToolboxItemFilter("System.W ...
- vue项目中引入animate.css和wow.js
本文转自:https://blog.csdn.net/liyunkun888/article/details/85003152 https://www.zhuimengzhu.com/content/ ...
- UART串口简介
通用异步收发传输器(Universal Asynchronous Receiver Transmitter) 原理 发送数据时,CPU将并行数据写入UART,UART按照一定的格式在一根电线上串行发出 ...
- 在Ubuntu中使用uwsgi 启动 Django ,但是静态文件映射出错
错误 : 找不到/static/下面的静态文件 解决方法: 在uswgi.ini 文件中配置参数 static-map=/static=/home/wb/Desktop/test_django/st ...
- 什么时候用assert
assertion(断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制.在实现中,assertion就是在程序中的一条语句,它对一个boolean表达式进行检查,一个正确程序必须保证 ...
- aop 的一些表达式
切入点的表达式 execution(void cn.itcast.e_xml.a_before.UserServiceImpl.saveUser(java.lang.String,java.lang. ...
- python3:iterable, iterator, generator,抽象基类, itertools的使用。
目录: iterable对象 iterator对象, 数据类型Iterator类 数据类型Generator类. 生成器表达式 collections.abc:容器的抽象基类.用于判断具体类. ite ...