2020QLU第二三次训练补题

狂风中的少年 提交于 2020-01-20 06:39:00

String can be called correct if it consists of characters “0” and “1” and there are no redundant leading zeroes. Here are some examples: “0”, “10”, “1001”.

You are given a correct string s.

You can perform two different operations on this string:

swap any pair of adjacent characters (for example, “101” “110”);
replace “11” with “1” (for example, “110” “10”).
Let val(s) be such a number that s is its binary representation.

Correct string a is less than some other correct string b iff val(a) < val(b).

Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

Input
The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.

The second line contains the string s consisting of characters “0” and “1”. It is guaranteed that the string s is correct.

Output
Print one string — the minimum correct string that you can obtain from the given one.

Examples
Input
4
1001
Output
100
Input
1
1
Output
1
Note
In the first example you can obtain the answer by the following sequence of operations: “1001” “1010” “1100” “100”.

In the second example you can’t obtain smaller answer no matter what operations you use.
签到思维题

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n;
char a[110];
cin>>n;
for(int i=1;i<=n;i++){
    cin>>a[i];
}
if(a[1]=='0')
{
    for(int i=1;i<=n;i++){
    cout<<a[i];
    }
    cout<<endl;

}
else{
    cout<<"1";
    for(int i=1;i<=n;i++){
        if(a[i]=='0'){
            cout<<a[i];
        }
    }
}
cout<<endl;

return 0;

}

You are given a sequence a1, a2, …, an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.

Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.

Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.

Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.

Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:

(2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
(3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
(5, 2), (2, 5) — match exactly.
对线段进行二次条件排序

#include <algorithm>
#include <iostream>
#include <cstdio>

#define ll long long
using namespace std;
struct xianduan{
    int l,r;
    int xulie;
};
bool cmp(xianduan a,xianduan b)
{
    if(a.l==b.l)
           return a.r>b.r;
    else
           return a.l<b.l;
}
 xianduan t[300010];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>t[i].l>>t[i].r;
        t[i].xulie=i;
    }
     sort(t+1,t+1+n,cmp);

      // for(int i=1;i<=n;i++){
      //     cout<<t[i].l<<" "<<t[i].r<<endl;
      //     cout<<t[i].xulie<<endl;
      //    }
     for(int i=2;i<=n;i++){

         if (t[i].r<=t[i-1].r) {
             cout<<t[i].xulie<<" "<<t[i-1].xulie<<endl;
            return 0;

           }
     }
  cout<<"-1 -1"<<endl;

    return 0;
}

Fafa owns a company that works on huge projects. There are n employees in Fafa’s company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.

Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.

Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.

Input
The input consists of a single line containing a positive integer n (2 ≤ n ≤ 105) — the number of employees in Fafa’s company.

Output
Print a single integer representing the answer to the problem.

Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:

choose only 1 employee as a team leader with 9 employees under his responsibility.
choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
注意用取余 不要用乘

#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
int main(){
   ll int n;
   ll int goal=1;
   ll int res=0;
    cin>>n;

    for(int i=1; i<=n/2; i++)
    {
        if(n%i==0)
        {
            res++;
        }
    }


   cout<<res<<endl;
    return 0;
}

Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.

The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), …). The wall and the gates do not belong to any of the kingdoms.

Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are ‘U’ (move one step up, from (x, y) to (x, y + 1)) and ‘R’ (move one step right, from (x, y) to (x + 1, y)).

Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn’t pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

Input
The first line of the input contains single integer n (1 ≤ n ≤ 105) — the number of moves in the walking sequence.

The second line contains a string S of length n consisting of the characters ‘U’ and ‘R’ describing the required moves. Fafa will follow the sequence S in order from left to right.

Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
看图分析即可

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int main(){
int n;

string t;
ll x=0,y=0,res=0;
cin>>n>>t;

if(n==1){
    cout<<"0"<<endl;
    return 0;
}

for(int i=0;i<n;i++){
    if(t[i]=='U')y++;
    if(t[i]=='R')x++;
    if(x==y&&t[i]==t[i+1])
    res++;
    else
    continue;
}
cout<<res<<endl;
return 0;
}

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.
签到其实输出n+1即可

#include<iostream>
#include<cstdio>
using namespace std;
char t[100010];
int main(){
    int n;
    int a=0,b=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    for(int i=1;i<=n;i++){
        if(t[i]=='L') a++;
        if(t[i]=='R') b++;
    }
    cout<<a+b+1<<endl;
    return 0;
}

Today, Yasser and Adel are at the shop buying cupcakes. There are n cupcake types, arranged from 1 to n on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type i is an integer ai. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.

Yasser, of course, wants to try them all, so he will buy exactly one cupcake of each type.

On the other hand, Adel will choose some segment [l,r] (1≤l≤r≤n) that does not include all of cupcakes (he can’t choose [l,r]=[1,n]) and buy exactly one cupcake of each of types l,l+1,…,r.

After that they will compare the total tastiness of the cupcakes each of them have bought. Yasser will be happy if the total tastiness of cupcakes he buys is strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel’s choice.

For example, let the tastinesses of the cupcakes be [7,4,−1]. Yasser will buy all of them, the total tastiness will be 7+4−1=10. Adel can choose segments [7],[4],[−1],[7,4] or [4,−1], their total tastinesses are 7,4,−1,11 and 3, respectively. Adel can choose segment with tastiness 11, and as 10 is not strictly greater than 11, Yasser won’t be happy 😦

Find out if Yasser will be happy after visiting the shop.

Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.

The first line of each test case contains n (2≤n≤105).

The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109), where ai represents the tastiness of the i-th type of cupcake.

It is guaranteed that the sum of n over all test cases doesn’t exceed 105.

Output
For each test case, print “YES”, if the total tastiness of cupcakes Yasser buys will always be strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel’s choice. Otherwise, print “NO”.

Example
Input
3
4
1 2 3 4
3
7 4 -1
3
5 -5 5
Output
YES
NO
NO
Note
In the first example, the total tastiness of any segment Adel can choose is less than the total tastiness of all cupcakes.

In the second example, Adel will choose the segment [1,2] with total tastiness 11, which is not less than the total tastiness of all cupcakes, which is 10.

In the third example, Adel can choose the segment [3,3] with total tastiness of 5. Note that Yasser’s cupcakes’ total tastiness is also 5, so in that case, the total tastiness of Yasser’s cupcakes isn’t strictly greater than the total tastiness of Adel’s cupcakes.
codeforse上大神写的代码风格学会了

#include<bits/stdc++.h>
using namespace std;
#define ll long long
// vector<int> v;          在外面定义会一直追加 
bool solve(){
	
	vector<int> v;
    int n;
    ll sum=0;
    int tt;
    cin>>n;
    //int e[1000];
  
//    v.resize(n);
//    for(auto &i:v)            c++11特性写法
//	    cin>>i;  

//	for(int i=0;i<n;i++){
//		cin>>e[i];
//	}
//	
//	 for(int i=0;i<n;i++){
//	 	v.push_back(e[i]);
//	 }
 		                                        
    for(int i=0;i<n;i++){
    	cin>>tt;
    	v.push_back(tt);
	}

//	for(int i=0;i<v.size();i++){
//		cout<<v[i]<<" ";
//	}

    
    
    for(int i=0;i<=n;i++){
        sum+=v[i];
        if(sum<=0) 
		return 0;
    }
    
    sum=0;
    for(int i=n-1;i>=0;i--){
        sum+=v[i];
        if(sum<=0) 
		    return 0;
    }
    return 1;
}
int main(){
    int t;
    cin>>t; 
    while(t--){
      if(solve())     
	  cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
    }
    return 0;
}

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
数学题
最小的必然是互质的两个数(若本身是合数)
否则为1和本身

#include<bits/stdc++.h>                              
#define ll long long 
using namespace std;
int main(){
	ll a;
	ll  x,y;
	cin>>a;
	for(ll i=1;i<=a;i++)
	{
		if(a%i==0&&__gcd(i,a/i)==1){
			x=i;
			y=a/i;
		}
		if(i*i>a) 
			break;
	}	
	cout<<x<<" "<<y<<endl;
	return 0;
}

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.
模拟题根据题目要求写即可

#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
ll int n,d;
ll int t;
int main(){
cin>>t;
while(t--){
    cin>>n>>d;
    ll int i=1;
    int flag=1;
    if(n>=d) {
        cout<<"YES"<<endl;
    }
    if(n<d){
        for(i=1;i<=n;i++){
             ll int gg=0;
             if(d%(i+1)==0){
                    gg=d/(i+1);
              }
              else{
                  gg=d/(i+1)+1;
              }       
              if(gg+i<=n){
                  flag=0;
                  cout<<"YES"<<endl;
                  break;
              }
          }
          if(i==n+1&&flag)
          cout<<"NO"<<endl;
      }
}
 return 0;
}

You are given two integers A and B, calculate the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true; conc(a,b) is the concatenation of a and b (for example, conc(12,23)=1223, conc(100,11)=10011). a and b should not contain leading zeroes.

Input
The first line contains t (1≤t≤100) — the number of test cases.

Each test case contains two integers A and B (1≤A,B≤109).

Output
Print one integer — the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true.

Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a=1, b=9 (1+9+1⋅9=19).
不要直接想要暴力 看看式子能否化简再说

#include<iostream>
#include<cstdio>
#define ll long long 
using namespace std;
int main(){
	int t;
	ll a,b;
	cin>>t;
	while(t--){
		ll c=0;
		int weishu=0;
		cin>>a>>b;
		while(1){		
			c=c*10+9;
			weishu++;
			if(c>b){
				break;
			}				
		}
		weishu--;
		cout<<a*weishu<<endl;		
	}
	return 0;
	
}

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.
注意题目要求相信自己理解

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
 int main(){
    string t;
    int a=0,b=0,c=0,d=0;
    cin>>t;
    for(int i=0;i<t.length();i++){
        if(t[i]=='H'){
            a=1;
        }
        if(t[i]=='Q'){
            b=1;
        }
        if(t[i]=='9'){
            c=1;
        }
    }
    if(!a&&!b&&!c)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
     return 0; }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!