Codeforces Round #372 (Div. 2)

不知不觉自己怎么变的这么水了,几百年前做A、B的水平,现在依旧停留在A、B水平。甚至B题还不会做。难道是带着一种功利性的态度患得患失?总共才打的几场 CF 节节掉分。学了快一年了成了个水货。

废话就不多说了,来看这次的这两题吧。很多CF的题是不想写博客的,如果题目质量很好的话我倒是愿意留在我的博客里;

A. Crazy Computer
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!

More formally, if you typed a word at second a and then the next word at second b,
then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c,
then everything on the screen disappears and after that the word you have typed appears on the screen.

For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then
at the second 8 there will be 3 words
on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another
two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words
remain on the screen.

You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

Input

The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) —
the number of words ZS the Coder typed and the crazy computer delay respectively.

The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109),
where ti denotes
the second when ZS the Coder typed the i-th word.

Output

Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the
second tn.

Examples
input
6 5
1 3 8 14 19 20
output
3
input
6 1
1 3 5 7 9 10
output
2
Note

The first sample is already explained in the problem statement.

For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and3 - 1 > 1.
Similarly, only 1 word will remain at the second 9.
Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.

说实话这题并没有看太明白,一开始直接上样例和Note,有点明白了然后大致看了看题。貌似就是类似一种黑板,隔一段时间不在上面写字,那么字迹会消失。样例可以理解为Ti时刻在黑板上写下一个字。只要下次写字的时间间隔超过给定的C,那么以前写的字全部消失。求最终Tn时刻黑板上有多少字。

以前做过类似的题,题读懂后急功近利的写了一发,WA了(多正常),稍加修改过了。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
using namespace std;
typedef long long ll;
#define pi 3.141592653
const int INF=1e9;
const int N=1000000+10;
int a[N];
int main()
{
int t,x,n,c;
while(~scanf("%d%d",&n,&c))
{
x=0;
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]-a[i-1]>c)
x=1;
else
x++;
}
printf("%d\n",x);
} return 0;
}

好了,上B题:

B. Complete the Word
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters)
of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26,
no such substring exists and thus it is not nice.

Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such
a word as well. Can you help him?

Input

The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000),
the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.

Output

If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print  - 1 in
the only line.

Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.

If there are multiple solutions, you may print any of them.

Examples
input
ABC??FGHIJK???OPQR?TUVWXY?
output
ABCDEFGHIJKLMNOPQRZTUVWXYS
input
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
output
-1
input
??????????????????????????
output
MNBVCXZLKJHGFDSAQPWOEIRUYT
input
AABCDEFGHIJKLMNOPQRSTUVW??M
output
-1
Note

In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the
whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.

In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains
all the letters of the alphabet, so the answer is  - 1.

In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answe

这道题题意很好懂的,给定一个字符串,问是否存在一个长度为26的字串其中所有的字母互不相同,问号位置可以填这段区间内未出现的字母;最终只要存在这样一个字串(长度为26且26个大写字母全部能凑齐),输出原串改变为nice的串,反之,-1;

思路就是26*len的思路,第一遍以为输出的是这个nice字串,后来发现要输出原串的产物;于是我把字串填满后全部输出结果一直跪在第6组,时间就这样慢慢消磨了,最后重打了一遍代码,还是跪在第6组。于是洗洗睡了。。。

早上来看第6 组样例简直哭死,原来原串中的问号全部要改成字母。。。。于是原代码稍加修改A了。。。。

昨晚做的时候求助学长,学长给了一个O(n)的思路--two points。当时没怎么理解,现在感觉确实挺好。

typedef long long ll;
#define pi 3.141592653
const int INF=1e9;
const int N=50000+10;
char a[N];
int wh[N],v[300];
int main()
{
while(~scanf("%s",a))
{
int len=strlen(a);
if(len<26)
{
printf("-1\n");
continue;
}
for(int i=0; i<len; i++)//前缀预处理问号。
if(a[i]=='?') wh[i]=wh[i-1]+1;
else wh[i]=wh[i-1];
int f=0,k=0;
for(int i=0; i<=len-26; i++)//O(26*len)
{
int x=0,ff=0;
memset(v,0,sizeof(v));
for(int j=i; j<i+26; j++)
{
if(a[j]!='?')
{
if(v[a[j]-'A'])//重复的情况。
{
ff=1;
break;
}
else
{
x++;//区间内不同字母的个数。
v[a[j]-'A']=1;
}
}
}
if(!ff)
{
if(wh[i+26-1]-wh[i-1]+x==26)//不同字母的个数加上问号的个数。
{
f=1;
k=i;
break;
}
}
}
if(f)
{
for(int i=k; i<k+26; i++)
if(a[i]=='?')
{
for(int j=0; j<26; j++)
if(!v[j])
{
a[i]='A'+j;
v[j]=1;
break;
}
}
for(int i=0;i<len;i++)//就是没加这一句,一直WA
if(a[i]=='?') a[i]='A';
printf("%s\n",a);
}
else printf("-1\n");
}
return 0;
}

O(n)的思路:枚举左端点与右端点,判断不同字母的个数与问号的个数。

typedef long long ll;
#define pi 3.141592653
const int INF=1e9;
const int N=50000+10;
char a[N];
int v[300];
void fill(int x)
{
for(int i=0; i<x; i++)
if(a[i]=='?') a[i]='A';
printf("%s\n",a);
}
int main()
{
while(~scanf("%s",a))
{
int len=strlen(a);
if(len<26)
{
printf("-1\n");
continue;
}
int temp=0,f=0;
memset(v,0,sizeof(v));
for(int i=0; i<26; i++)
{
if(a[i]=='?') temp++;//不同字母与问号的总数;
else
{
if(!v[a[i]-'A']) temp++;
v[a[i]-'A']++;
}
}
if(temp==26)
{
int cur=0;
while(v[cur]) cur++;
for(int i=0; i<26; i++)
if(a[i]=='?')
{
a[i]='A'+cur;
cur++;
while(v[cur]) cur++;
}
fill(len);
continue;
}
for(int i=26; i<len; i++)//相当于尺取法,每次区间右移一位。
{
if(a[i-26]=='?') temp--;//左端点已经不在区间内,问号个数减一,即总数减一;
if(a[i]=='?') temp++;右端点在区间内,总数加一;
if(a[i]!='?')
{
v[a[i]-'A']++;
if(v[a[i]-'A']==1) temp++;
}
if(a[i-26]!='?')
{
v[a[i-26]-'A']--;
if(v[a[i-26]-'A']==0) temp--;
}
if(temp==26)
{
int cur=0;
while(v[cur]) cur++;
for(int j=i-25; j<=i; j++)
if(a[j]=='?')
{
a[j]=cur+'A';
cur++;
while(v[cur]) cur++;
}
fill(len);
f=1;
break;
}
}
if(!f)
printf("-1\n");
}
return 0;
}

这次的总结就是:做题有自己的节奏,不用在乎别人过了多少,心平气和而不是急功近利。

Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word的更多相关文章

  1. Codeforces Round #372 (Div. 2)

    Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...

  2. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #372 (Div. 2) A

    Description ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecut ...

  4. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #372 (Div. 2) A ,B ,C 水,水,公式

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何

    A. Crazy Town 题目连接: http://codeforces.com/contest/498/problem/A Description Crazy Town is a plane on ...

  8. Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))

    B. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))

    C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Oracle10g初探DBCA

    Database Configuration Assistant. [oracle@dbsrv3 bin]$ pwd /opt/oracle//bin [oracle@dbsrv3 bin]$ ./d ...

  2. Snort里如何将读取的包记录存到二进制tcpdump文件下(图文详解)

    不多说,直接上干货! 如果网络速度很快,或者想使日志更加紧凑以便以后的分析,那么应该使用二进制的日志文件格式.如tcpdump格式或者pcap格式.  这里,我们不需指定本地网络了,因为所以的东西都被 ...

  3. InChatter系统之服务端的Windows服务寄宿方式(三)

    为了部署的方便,我们开发Windows服务的服务寄宿程序,这样我们的服务便可以作为系统服务,随着系统的启动和关闭而启动和关闭,而避免了其他的设置,同时在服务的终止时(如系统关闭等)能及时处理服务的关闭 ...

  4. vue框架的知识

    基础:实例----组件----指令----选项-----计算属性----事件绑定----模板渲染-----内置动画 ---组件交互----路由. vuejs干了什么事情:数据渲染/数据同步 组件化/模 ...

  5. 3D旋转矩阵的推导过程

    3D旋转矩阵的推导过程 包含平移的线性变换称作仿射变换,3D中的仿射变换不能用 3 x 3 矩阵表达,必须使用4 x 4矩阵. 一般来说,变换物体相当于以相反的量变换描述这个物体的坐标系.当有多个变换 ...

  6. Spring工作原理及其作用

    1.springmvc请所有的请求都提交给DispatcherServlet,它会委托应用系统的其他模块负责负责对请求进行真正的处理工作. 2.DispatcherServlet查询一个或多个Hand ...

  7. flutter 实现圆角头像的2种方法

    圆角头像在开发中应用太普遍了,我总结了2种实现方法,分享给大家 方法一: 使用Container组件的decoration可以实现 Container( width: 40, height: 40, ...

  8. ssd训练自己的数据集

    1.在ssd/caffe/data下创建VOC2007的目录,将ssd/caffe/data/VOC0712里的create_data.sh.create_list.sh和labelmap_voc.p ...

  9. vue-router 基本使用(vue工程化)

    (1)概念: 路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮  => h ...

  10. Java C

    先说一下自己叫什么,免得面试的人张冠李戴. 介绍自己有几个方面:1学什么专业的那方面学的过硬,可以说的具体点. 2以前做过什么.(这家公司要你肯定是和你的经历有关.) 3现在来这家公司的目的是什么(当 ...