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.现在你从北极出发,按照题目输入方式来走. ...
随机推荐
- CPA ,CFA,ACCA
CPA是“注册会计师”(Certified Public Accountant,CPA)的简称,是指取得注册会计师证书并在会计师事务所执业的人员,是从事社会审计/中介审计/独立审计的专业人士,CPA为 ...
- Java 8 Collectors 类的静态工厂方法
摘自<<Java 8 实战>> Collectors 类的静态工厂方法 工厂方法 返回类型 用于 toList List<T> 把流中所有项目收集到一个 List ...
- SqlServer2008 跨服务器同步数据
最近工作中需要跨服务器同步数据,在数据库DB1中的表T1插入数据,同时触发T1的触发器(这里暂不讨论触发器的效率问题),向另一台服务器DB2中的相同的一张表T2插入数据,查看了一些资料说, 需要打开D ...
- LeetCode:197.上升的温度
题目链接:https://leetcode-cn.com/problems/rising-temperature/ 题目 给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日 ...
- 使用百度echarts仿雪球分时图(三)
这章节将完成我们的分时图,并使用真实的数据来进行展示分时图. 一天的交易时间段分为上午的09:30~11:30,下午的13:00~15:00两个时间段,因为分时间段的关系,数据是不连续的,所以会先分为 ...
- 简单SQL注入试探、一
DVWA——简单SQL注入小记 前不久刚开始接触SQL注入,今天来记录一些最近的一些收获和一些SQL注入方面的知识. 主要是基于DVWA这个开源的平台来进行练习. 废话不多说开始解题. 从简单的SQL ...
- 修正Calendar的Bug
procedure TAndroidNativeCalendarListener.onSelectedDayChange(view: JCalendarView; year, month, dayOf ...
- 在SqlServer和Oralce中创建索引
给表名A的字段A增加索引 SqlServer: if exists (select 1 from sysobjects where name='表名A' and type='u')and exists ...
- 4.caffe:train_val.prototxt、 solver.prototxt 、 deploy.prototxt( 创建模型与编写配置文件)
一,train_val.prototxt name: "CIFAR10_quick" layer { name: "cifar" type: "Dat ...
- 学习elasticsearch(一)linux环境搭建(3)——head插件安装
对于5.x的es,head插件不支持 ./elasticearch-plugin install [plugin_name]方式安装. 进入正文 1.首先确保你的机器安装了python,如果没有,请看 ...