感觉这是最近打过最开心的一场比赛!!!下面正片开始啦
这个题就是一个思维题(至少我是这么做的)
有n步就能有n+1个答案啦(因为失效是随机的)
Today, Mezo is playing a game. Zoma, a character in that game, is
initially at position x=0x=0. Mezo starts sending nn commands to Zoma.
There are two possible commands:
‘L’ (Left) sets the position x:=x−1x:=x−1; ‘R’ (Right) sets the position x:=x+1x:=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 xx 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 00;
“LRLR” — Zoma recieves no commands, doesn’t move at all and ends up at
position 00 as well; “LRLR” — Zoma moves to the left, then to the
left again and ends up in position −2−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 nn (1≤n≤105)(1≤n≤105) — the number of commands Mezo sends. The second line contains a string ss of nn
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
#include
int main(){
int n;
scanf("%d",&n);
printf("%d",n+1);
}
【一开始的奇妙想法】这个题刚开始是想用判断+for循环实现,但不知道为啥就是实现不出来(暂时还没想通)
后来再一看这好像是个不等式 (应该是类似于基本不等式那样的),试了试写出来的…
(那个for循环的写法写了我半个多小时还写不出来orz)
Adilbek was assigned to a special project. For Adilbek it means that
he has nn days to run a special program and provide its results. But
there is a problem: the program needs to run for dd days to calculate
the results. Fortunately, Adilbek can optimize the program. If he
spends xx (xx is a non-negative integer) days optimizing the program,
he will make the program run in ⌈d/x+1⌉days (⌈a⌉⌈a⌉ is the ceiling
function: ⌈2.4⌉=3, ⌈2⌉=2). The program cannot be run and optimized
simultaneously, so the total number of days he will spend is equal to
x+⌈d/x+1⌉x. Will Adilbek be able to provide the generated results in
no more than nn days?
Input
The first line contains a single integer TT (1≤T≤501≤T≤50) — the number of test cases. The next TT lines contain test cases – one
per line. Each line contains two integers nn and dd (1≤n≤1091≤n≤109,
1≤d≤1091≤d≤109) — the number of days before the deadline and the
number of days the program runs.
Output
Print TT answers — one per test case. For each test case print YES
(case insensitive) if Adilbek can fit in nn days or NO (case
insensitive) otherwise.
Example
Input 3 1 1 4 5 5 11
Output YES YES NO
Note
In the first test case, Adilbek decides not to optimize the program at
all, since d≤nd≤n. In the second test case, Adilbek can spend 11 day
optimizing the program and it will run ⌈52⌉=3 days. In total, he
will spend 44 days and will fit in the limit. In the third test case,
it’s impossible to fit in the limit. For example, if Adilbek will
optimize the program 22 days, it’ll still work ⌈112+1⌉=4 days.
#include
#include
#include
using namespace std;
int main(){
long long t,n,d;
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>d;
double tem=(double)2*sqrt(d);
if(tem>n+1) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}
这个题是又是一个思维题,刚开始看题看样例死活想不出,一看note清晰明了,就是跟一串9比大小嘛
题目不好复制就改成超链接啦
下面是代码实现
#include
#include
#include
using namespace std;
int main(){
long long t,a,b,f[9]={9,99,999,9999,99999,999999,9999999,99999999,999999999};
cin>>t;
for(int i=1;i<=t;i++){
cin>>a>>b;
int j=0,count=0;
while(f[j++]<=b) count++;
cout<<a*count<<endl;
}
}
这个题就是输入里有H Q 9这三个数就是yes
否则就是no
真的 很 简 单(一开始光顾着看别的题没注意到这个题这么简单)
#include
#include
#include
using namespace std;
int main(){
char c[110];
int f=0;
cin>>c;
for(int i=0;i<strlen(c);i++){
if(c[i]=='H'||c[i]=='Q'||c[i]=='9'){
f=1;
break;
}
}
if(f) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}