凉肝的比赛

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.



题意:
LR来表示坐标左移或者右移,还有LRLR这种情况来迷惑你
思路:
开始想记录LR来模拟,后来发现无论含不含LRLR,情况都是n+1种
代码:

#include<iostream>
#include<cstring>
using namespace std;

int main(void)
{
   string str;
   int n;
   cin>>n>>str;
   cout<<n+1;
   return 0;
}

C - Fadi and LCM

题目:

Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a,b) such that LCM(a,b) equals X. Both a and b

should be positive integers.

LCM(a,b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6,8)=24, LCM(4,12)=12, LCM(2,3)=6
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
Input

The first and only line contains an integer X
(1≤X≤1012).

Output

Print two positive integers, a
and b, such that the value of max(a,b) is minimum possible and LCM(a,b) equals X

If there are several possible such pairs, you can print any.
Examples
Input

2

Output

1 2

Input

6

Output

2 3

Input

4

Output

1 4

Input

1

Output

1 1



题意:
找输入数的因数,并且使得两个因数都尽可能地小且接近
思路:
穷举,只需要举到sqrt(n)就行,为使它们尽可能接近,只需要从后面往前举,为使它们都很小,那么它们之间没有公因数,即互素。并且题目中数的上限较大,用int不够。
代码:

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

int is_coprime(long long a,long long b)
{
    long long t,p=1,product;
    if(a<b) t=a,a=b,b=t;
    product=a*b;
    while(p)
    {
        p=a%b;
        a=b;
        b=p;
    }
    if(a==1) return 1;
    else return 0;
}

int main(void)
{
   long long n;
   cin>>n;
   double p=sqrt(n);
   for(long long i=p;i;i--)
   {
      long long j=n%i;
      if(j==0)
      {
         j=n/i;
         if(is_coprime(i,j))
         {cout<<i<<' '<<j<<endl;return 0;}
      }
   }
   return 0;
}

E - Deadline

题目:

Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d

days to calculate the results.

Fortunately, Adilbek can optimize the program. If he spends x
(x is a non-negative integer) days optimizing the program, he will make the program run in ⌈dx+1⌉ days (⌈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+⌈dx+1⌉

Will Adilbek be able to provide the generated results in no more than n days?

Input

The first line contains a single integer T
(1≤T≤50

) — the number of test cases.

The next T
lines contain test cases – one per line. Each line contains two integers n and d (1≤n≤109, 1≤d≤109) — the number of days before the deadline and the number of days the program runs.

Output

Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n 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≤n

In the second test case, Adilbek can spend 1
day optimizing the program and it will run ⌈52⌉=3 days. In total, he will spend 4

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 2
days, it’ll still work ⌈112+1⌉=4 days.



题意:
判断是否能在截止日期完成工作
思路:
1.截止日期不小于工期直接YES
2.反之,用题中所给的公式来计算最优工期,我用的是均值不等式,考虑到[n]取上限,又多判断了在均值x后200的情况满不满足,没想到过了。后来又试了一下,好像直接用均值也能过。。。
在这里插入图片描述
代码:

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

int is_ok(int dea,int day)
{
   int u=(int)sqrt(day);
   double v;
      v=ceil((double)day/(double)u);
      int need=(int)v+u-1;
      if(need<=dea) return 1;
   return 0;
}

int main(void)
{
   //a是deadline
   int n,dea,day;
   cin>>n;
   while(n--)
   {
      cin>>dea>>day;
      if(day<=dea) cout<<"YES"<<endl;
      else
      {
         if(is_ok(dea,day)) cout<<"YES"<<endl;
         else cout<<"NO"<<endl;
      }
   }
   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.



题意:
判断有无题中所给的字符
思路:
个人感觉比A题简单,但是当时为什么大家都去做A了呢。。。但是“figure out whether executing this program will produce any output.”这句话很关键。
代码:

#include<iostream>
#include<cstring>
using namespace std;

int main(void)
{
   char str[105];
   cin>>str;
   int p=strlen(str);
   for(int i=0;i<p;i++)
      if(str[i]=='H'||str[i]=='Q'||str[i]=='9')
         {
            cout<<"YES";
            return 0;
         }
   cout<<"NO";
   return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值