#凉肝的比赛
##A - Mezo Playing Zoma
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x=0. Mezo starts sending n commands to Zoma. There are two possible commands:
‘L’ (Left) sets the position x:=x−1;
‘R’ (Right) sets the position x:=x+1.
Unfortunately, Mezo’s controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position x doesn’t change and Mezo simply proceeds to the next command.
For example, if Mezo sends commands “LRLR”, then here are some possible outcomes (underlined commands are sent successfully):
“LRLR” — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position 0;
“LRLR” — Zoma recieves no commands, doesn’t move at all and ends up at position 0 as well;
“LRLR” — Zoma moves to the left, then to the left again and ends up in position −2.
Mezo doesn’t know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.
Input
The first line contains n (1≤n≤105) — the number of commands Mezo sends.
The second line contains a string s of n commands, each either ‘L’ (Left) or ‘R’ (Right).
Output
Print one integer — the number of different positions Zoma may end up at.
Example
Input
4
LRLR
Output
5
Note
In the example, Zoma may end up anywhere between −2 and 2.
今天,Mezo在玩游戏。Zoma是游戏中的一个角色,最初的位置是x=0。Mezo开始向Zoma发送n个命令。有两个可能的命令:
“L”(左)设置位置x:=x−1;
“R”(右)设置位置x:=x+1
不幸的是,Mezo的控制器有时会出现故障。一些命令已成功发送,一些命令被忽略。如果忽略该命令,则位置x不会改变,Mezo将直接执行下一个命令。
例如,如果Mezo发送命令“LRLR”,则以下是一些可能的结果(带下划线的命令成功发送):
“LRLR”-Zoma最后一次向左、向右、向左和向右移动,最终到达位置0;
“LRLR”-Zoma不接收任何命令,完全不移动,最后也在位置0;
“LRLR”-Zoma向左移动,然后再次向左移动,最后到达位置-2。
Mezo事先不知道哪些命令会成功发送。因此,他想知道Zoma最终会有多少不同的位置。
输入
第一行包含n(1≤n≤105)-Mezo发送的命令数。
第二行包含n个命令的字符串s,每个命令要么是“L”(左)要么是“R”(右)。
输出
打印一个整数-Zoma可能会在不同的位置结束。
Example
Input
4
LRLR
Output
5
注意
在本例中,Zoma可能最终出现在-2到2之间的任何位置。
代码:
#include <stdio.h>
const int maxn=1e+5;
char a[maxn+10];
int main()
{
int n;
scanf("%d%s",&n,a);
printf("%d",n+1);
}
##E - Deadline


http://codeforces.com/problemset/problem/1288/A
代码:
#include <stdio.h>
#include <math.h>
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
int n,d;
scanf("%d%d",&n,&d);
if(n>=d)
{
printf(“YES\n”);
}
else if(n==1&&d>1)
{
printf(“NO\n”);
}
else
{
double k=sqrt(d);
if(k-(int)k)
{
int n2=(int)k,m=n2+1,n1,m1,min;
if(!((d/(double)n2)-(d/n2)))
n1=n2+d/n2-1;
else
n1=n2+(d/n2);
if(!((d/(double)m)-(d/m)))
m1=m+d/m-1;
else
m1=m+(d/m);
if(n1>=m1)
min=m1;
else
min=n1;
if(min<=n)
printf(“YES\n”);
else
printf(“NO\n”);
}
else
{
int min=2*k-1;
if(min<=n)
printf("YES\n");
else
printf("NO\n");
}
}
}
return 0;
}
#G - HQ9+
HQ9+ is a joke programming language which has only four one-character instructions:
“H” prints “Hello, World!”,
“Q” prints the source code of the program itself,
“9” prints the lyrics of “99 Bottles of Beer” song,
“+” increments the value stored in the internal accumulator.
Instructions “H” and “Q” are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input
The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output
Output “YES”, if executing the program will produce any output, and “NO” otherwise.
Examples
Input
Hi!
Output
YES
Input
Codeforces
Output
NO
Note
In the first case the program contains only one instruction — “H”, which prints “Hello, World!”.
In the second case none of the program characters are language instructions.
HQ9+是一种笑话编程语言,只有四个一字符指令:
H打印“你好,世界!”,
“Q”打印程序本身的源代码,
“9”打印了“99瓶啤酒”的歌词,
“+”递增存储在内部累加器中的值。
指令“H”和“Q”区分大小写,必须大写。程序的非指令字符将被忽略。
给你一个用HQ9+编写的程序。你必须弄清楚执行这个程序是否会产生任何输出。
输入
输入将由一行p组成,p将给出一个HQ9+格式的程序。字符串p将包含1到100个字符(包括1到100个字符)。p的每个字符的ASCII代码将介于33(感叹号)和126(颚化符)之间(含)。
输出
如果执行程序将产生任何输出,则输出“是”,否则输出“否”。
Examples
Input
Hi!
Output
YES
Input
Codeforces
Output
NO
注意
在第一种情况下,程序只包含一条指令-“H”,它会打印“Hello,World!”.
在第二种情况下,程序字符都不是语言指令。
代码:
#include <stdio.h>
#include <string.h>
int main()
{
char a[1000];
scanf("%s",a);
int str=strlen(a);
int d=0;
for(int i=0;i<str;i++)
{
if(a[i]‘H’||a[i]‘Q’||a[i]‘9’)
{
printf(“YES”);
d=1;
break;
}
}
if(d0)
printf(“NO”);
return 0;
}
2349

被折叠的 条评论
为什么被折叠?



