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.现在你从北极出发,按照题目输入方式来走. ...
随机推荐
- hdu 1281 匈牙利算法
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- springboot application.properties配置大全
springboot application.properties配置大全 官方文档 https://docs.spring.io/spring-boot/docs/current/reference ...
- TypeScript入门四:TypeScript的类(class)
TypeScript类的基本使用(修饰符) TypeScript类的抽象类(abstract) TypeScript类的高级技巧 一.TypeScript类的基本使用(修饰符) TypeScript的 ...
- c#调用存储过程实现批量增加和修改数据
1 例如当我在编辑表格数据,一次编辑了多行需要保存到数据库时,就需要判断数据库中是否已经存在,存在则修改,不存在则新增一条或多条数据,即所谓批量增加或者跟新数据. 首先需要构建数据包,把要添加或者跟新 ...
- LLVM的RTTI特性
本文思路来源于http://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html,叙述有不同,望谅解,希望能从其他方面帮助大家了解C++语言的底层实现. 背景 在LLV ...
- Google C++单元测试框架GoogleTest---AdvancedGuide(译文)
上篇在这里: 下篇在这里.
- 十:Razor语法
1.Razor简介 不是一种代码语言,而是视图中使用的代码引擎. 它以简洁的类似客户端的语法结构,呈现网页服务端代码功能 它替代了ASPX页面的“<%...%>”代码块语法. 在编写时使用 ...
- Ubuntu系统---安装思维导图XMind
Ubuntu系统---安装思维导图XMind @wp20181011 XMind安装很简单,这里简单记录记录一下.分为三步:1,下载.2,安装.3,设置桌面快捷图标. 详细步骤如下: 1,下载. 首先 ...
- mysql主从同步监控---邮件告警
#!/bin/bash #check MySQL_Slave Status #crontab time : MYSQLPORT=`netstat -na|grep "|awk -F[:&qu ...
- CentOS7 内核优化 修改参数
一:内核简介 内核是操作系统最基本的部分.它是为众多应用程序提供对计算机硬件的安全访问的一部分软件,这种访问是有限的,并且内核决定一个程序在什么时候对某部分硬件操作多长时间. 内核的分类可分为单内核和 ...