// 比赛链接:https://codeforces.com/contest/1200

A - Hotelier

题意:

有一家旅馆有10间房,编号0~9,从左到右顺序排列。旅馆有左右两扇门,每次新来旅客从进来门的方向分配最近的空闲房间。给你一段旅客到来方向以及离开位置的序列,输出最终旅馆房间使用情况。

输入:

8

LLRL1RL1

输出:

1010000011

题解:

序列长度不超过10^5,暴力模拟复杂度O(10*n)。

AC代码:

#include<iostream>
#include<cstdio>
using namespace std; char s[];
bool r[]; // true:有人 false:无人
int main()
{
int n; cin>>n;
scanf("%s", s);
for(int i=;i<n;i++) {
if(s[i]=='L') {
for(int j=;j<=;j++) {
if(!r[j]) {
r[j] = ;
break;
}
}
} else if(s[i]=='R') {
for(int j=;j>=;j--) {
if(!r[j]) {
r[j] = ;
break;
}
}
} else {
r[s[i]-''] = ;
}
}
for(int i=;i<=;i++) {
putchar(r[i]?'':'');
} return ;
}

B - Block Adventure

题意:

从起点到终点有 n 个格子,每块高度 h[i],初始时背包有m块方块,从 i 跳到 i+1 有三种选择,1. 把背包的方块放到当前的格子上;2. 把当前格子的方块放到背包里;3.跳到下一块。

只有当 | h[i] - h[i+1] | <= k 才能跳到下一块。 问是否能跳到终点。

输入:

第一行组数,后面每组第一行 n,m,k,第二行 n个值代表 h[i]。


3 0 1
4 3 5
3 1 2
1 4 7
4 10 0
10 20 10 20
2 5 5
0 11
1 9 9
99

输出:

YES
NO
YES
NO
YES

题解:

贪心

如果能跳到下一块,(左边能凑到的最多方块要大于等于右边最少需要的方块,即m+h[i]>= h[i+1]-k ),把前一块上的方块取到前后差值不超过 k。否则跳不到终点。

AC代码:

#include<iostream>
#include<cstdio>
using namespace std; int h[];
int main()
{
int t; cin>>t;
while(t--) {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for(int i=;i<n;i++) {
scanf("%d", &h[i]);
}
bool flag = true;
for(int i=;i+<n;i++) {
if(h[i]+m>=h[i+]-k) {
if(h[i+]>=k) m = h[i]+m - (h[i+]-k);
else
m = h[i]+m;
}
else {
flag = false;
break;
}
} if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}

C - Round Corridor

题意:

一个圆盘,内层分割成m块,外层分割成n块,给出 q 个询问,判断所给两块区域是否连通。

输入:

第一行 n,m,q,后面 q 行,每行四个数 sx,sy,ex,ey。sx,ex 为 1 代表内层,为 2 代表外层;sy,ey 代表编号,如图顺时针排序。

4 6 3
1 1 2 3
2 6 1 2
2 6 2 4

输出:

YES
NO
YES

题解:

思维题。设 g = gcd(m, n),由图可知 1*g,2*g,3*g,…… k*g 把圆盘分割开。这些单独块之内连通,不在同一块则不连通。

AC代码:

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
return b==?a:gcd(b, a%b);
} ll g, m, n;
ll f(int d, ll v) { // 计算 v 所在块的编号
if(d==) return v/(m/g);
else return v/(n/g);
}
int main() {
int q;
cin>>m>>n>>q;
int sx, ex;
ll sy, ey;
g = gcd(m, n);
while(q--) {
scanf("%d %lld %d %lld", &sx, &sy, &ex, &ey);
if(f(sx, sy-)==f(ex, ey-)) printf("YES\n");
else printf("NO\n"); } return ;
}

E - Compress

题意:

有1e5个单词,当前一个单词的后缀与后一个单词的前缀相同时,相同部分可以压缩省略,这个过程递归进行。输出一行字符串表示最终结果。

输入:

5

I want to order pizza

输出:

Iwantorderpizza

题解:

字符串哈希

AC代码:

注意压缩过程是递归进行的,没注意一直WA5。

单模数哈希WA78,可能没取好模数吧。双模数哈希AC。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll; const int N = 1e6 + ;
const int Base1 = ;
const int Base2 = ;
const int Mod1 = 1e9 + ;
const int Mod2 = ;
char s[N], ans[N]; int main() {
int n;
scanf("%d", &n);
int len = ; // 前一个串长度
for(int i = ; i < n; ++i) {
scanf("%s", s);
int m = strlen(s); ll now1 = , last1 = ; // 前面所有串的哈希,当前串的哈希
ll now2 = , last2 = ;
ll bs1 = , bs2 = ;
int same = ; // 公共长度
for(int k = ; k <= m && k <= len; ++k) {
now1 = (now1*Base1 + s[k-]) % Mod1; // 从前往后加
last1 = (bs1*ans[len-k] + last1) % Mod1; // 从后往前加
bs1 = bs1 * Base1 % Mod1; now2 = (now2*Base2 + s[k-]) % Mod2;
last2 = (bs2*ans[len-k] + last2) % Mod2;
bs2 = bs2 * Base2 % Mod2; if(now1==last1 && now2==last2) same = k;
}
for(int k = same; k < m; ++k) {
ans[len++] = s[k];
}
}
ans[len] = '\0';
puts(ans);
return ;
}

CF #578 Div2的更多相关文章

  1. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  2. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

  3. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  4. CF#581 (div2)题解

    CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...

  5. [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)

    题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...

  6. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

  7. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  8. CF R303 div2 C. Woodcutters

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. CF 192 Div2

    A.Cakeminator 暴搞之,从没有草莓覆盖的行.列遍历 char map[30][30]; int vis[30][30]; int hang[30],lie[30]; int main() ...

随机推荐

  1. element-ui的layout将24等分换为48等分

    按住ctr箭点击element-ui/packages/theme-chalk/src/index";,再按住ctr贱点击col.scss跳转,将跳转到的col.scss中的24换为48(c ...

  2. 2019-5-21-dotnet-使用-GC.GetAllocatedBytesForCurrentThread-获取当前线程分配过的内存大小...

    title author date CreateTime categories dotnet 使用 GC.GetAllocatedBytesForCurrentThread 获取当前线程分配过的内存大 ...

  3. shell命令 安装软件包

    软件包分类 Debian Linux首先提出  “软件包”   的管理机制——Deb软件包 Redhat Linux基于这个理念推出了自己的软件包管理机制——Rpm软件包 安装包格式: filenam ...

  4. JS对象 charAt() 方法可返回指定位置的字符。返回的字符是长度为 1 的字符串。

    返回指定位置的字符 charAt() 方法可返回指定位置的字符.返回的字符是长度为 1 的字符串. 语法: stringObject.charAt(index) 参数说明: 注意:1.字符串中第一个字 ...

  5. python 封装一个取符串长度的函数

    def getStrLen(str): return len(str) print(getStrLen("dsa456das4dasdas21"))

  6. 【JZOJ6293】迷宫

    description analysis 有没有想起[\(NOIP2018\)]保卫王国? 设\(tr[t][x][y]\)表示线段树上的\(t\)节点代表的区间,从最左边列的\(x\)行到最右边列\ ...

  7. thinkphp DEFINE标签

    DEFINE标签用于中模板中定义常量,用法如下: 直线电机厂家 <define name="MY_DEFINE_NAME" value="3" /> ...

  8. python相关软件安装流程图解——Windows下安装Redis以及可视化工具——Redis-x64-3.2.100——redis-desktop-manager-0.9.3.817

    https://www.2cto.com/database/201708/666191.html https://github.com/MicrosoftArchive/redis/releases ...

  9. SpringCloud及其五大常用组件之Feign、Ribbon和Hystrix

    1.Feign 我们已经将Eureka和Zuul开发完毕,而且上面注册了两个微服务,现在我们实现两个微服务之间的调用. String baseUrl = "http://127.0.0.1: ...

  10. Java程序员注意:Tomcat Get请求的巨坑!

    Tomcat8.5,当Get请求中包含了未经编码的中文字符时,会报以下错误,请求未到应用程序在Tomcat层就被拦截了. Tomcat报错: java.lang.IllegalArgumentExce ...