当前位置:网站首页>Codeworks 5 questions per day (average 1500) - day 23
Codeworks 5 questions per day (average 1500) - day 23
2022-07-24 02:18:00 【Soup key】
Tile Painting
Topic translation
Brief introduction
There is one by n n n The length of the tile is n n n Way .
For two tiles i , j i,j i,j, If $ |i-j| > 1 $ And n n n mod \text{mod} mod ∣ i − j ∣ = 0 |i-j|=0 ∣i−j∣=0 , Then their colors must be the same .
Find out how many tiles of different colors can be used at most , And meet the above requirements .
Input format
One positive integer per line n ( 1 ≤ n ≤ 1 0 12 ) n(1\leq n \leq 10^{12}) n(1≤n≤1012).
Output format
Output a positive integer , Indicates the number of tiles of different colors that can be used at most , Make it meet the above requirements .
Title Description
Ujan has been lazy lately, but now has decided to bring his yard to good shape.
First, he decided to paint the path from his house to the gate.
The path consists of n n n consecutive tiles, numbered from 1 1 1 to n n n .
Ujan will paint each tile in some color.
He will consider the path aesthetic if for any two different tiles with numbers i i i and j j j , such that ∣ j − i ∣ |j - i| ∣j−i∣ is a divisor of n n n greater than 1 1 1 , they have the same color.
Formally, the colors of two tiles with numbers i i i and j j j should be the same if ∣ i − j ∣ > 1 |i-j| > 1 ∣i−j∣>1 and n m o d ∣ i − j ∣ = 0 n \bmod |i-j| = 0 nmod∣i−j∣=0 (where x m o d y x \bmod y xmody is the remainder when dividing x x x by y y y ).
Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?
Input format
The first line of input contains a single integer n n n ( 1 ≤ n ≤ 1 0 12 1 \leq n \leq 10^{12} 1≤n≤1012 ), the length of the path.
Output format
Output a single integer, the maximum possible number of colors that the path can be painted in.
Examples #1
The sample input #1
4
Sample output #1
2
Examples #2
The sample input #2
5
Sample output #2
5
Tips
In the first sample, two colors is the maximum number.
Tiles 1 1 1 and 3 3 3 should have the same color since 4 m o d ∣ 3 − 1 ∣ = 0 4 \bmod |3-1| = 0 4mod∣3−1∣=0 .
Also, tiles 2 2 2 and 4 4 4 should have the same color since 4 m o d ∣ 4 − 2 ∣ = 0 4 \bmod |4-2| = 0 4mod∣4−2∣=0 .
In the second sample, all five colors can be used.

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
ll n;
vector<ll>a;
int main(){
cin>>n;
for(ll i=2;i*i<=n;i++)
if(n%i==0)
{
a.push_back(i);
while(n%i==0) n/=i;
}
if(n!=1) a.push_back(n);
sort(a.begin(),a.end());
if(a.size()==1) printf("%lld\n",a.front());
else if(a.empty()) printf("%lld\n",n);
else puts("1");
return 0;
}
Boxers
Topic translation
Title Description :
Yes n n n A boxer , The first i i i The weight of a boxer is a i a_i ai. Each of them can change their weight by no more than 1( Weight cannot equal zero , in other words , It must remain positive )., Weight is always an integer .
You need to choose the largest boxing team according to the number of people , Make the weight of each boxer in the team unique .
Write a program , For a given weight a i a_i ai, Find out the maximum possible number of boxers in the team . After some changes , The weight of all boxers does not exceed 150001.
Input format :
The first line contains an integer n n n( 1 ≤ n ≤ 150000 1\leq n\leq 150000 1≤n≤150000), That is, the number of boxers . The second line contains n n n It's an integer a 1 a_1 a1, a 2 a_2 a2,…, a n a_n an( 1 ≤ a i ≤ 150000 1\leq ai\leq 150000 1≤ai≤150000), among a i a_i ai For the first time i i i Weight of a boxer .
Output format :
Output the maximum possible number of people in the team .
Title Description
There are n n n boxers, the weight of the i i i -th boxer is a i a_i ai .
Each of them can change the weight by no more than 1 1 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.
It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers’ weights in the team are different (i.e. unique).
Write a program that for given current values a i a_i ai will find the maximum possible number of boxers in a team.
It is possible that after some change the weight of some boxer is 150001 150001 150001 (but no more).
Input format
The first line contains an integer n n n ( 1 ≤ n ≤ 150000 1 \le n \le 150000 1≤n≤150000 ) — the number of boxers.
The next line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an , where a i a_i ai ( 1 ≤ a i ≤ 150000 1 \le a_i \le 150000 1≤ai≤150000 ) is the weight of the i i i -th boxer.
Output format
Print a single integer — the maximum possible number of people in a team.
Examples #1
The sample input #1
4
3 2 4 1
Sample output #1
4
Examples #2
The sample input #2
6
1 1 1 4 4 4
Sample output #2
5
Tips
In the first example, boxers should not change their weights — you can just make a team out of all of them.
In the second example, one boxer with a weight of 1 1 1 can be increased by one (get the weight of 2 2 2 ), one boxer with a weight of 4 4 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 3 3 and 5 5 5 , respectively).
Thus, you can get a team consisting of boxers with weights of 5 , 4 , 3 , 2 , 1 5, 4, 3, 2, 1 5,4,3,2,1 .
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
int n,k,a[N],mmax=0,s=0;
int main(){
cin>>n;
for(ll i=1;i<=n;i++){
scanf("%d",&k);
a[k]++;
mmax=max(mmax,k);
}
for(int i=1;i<=mmax+1;i++){
if(a[i-1]) a[i-1]--,s++;
else if(a[i]) a[i]--,s++;
else if(a[i+1]) a[i+1]--,s++;
}
cout<<s<<endl;
return 0;
}
Zero Array
Topic translation
Given a sequence of Numbers n ( 2 ≤ n ≤ 1 0 5 ) n(2 \le n \le10^5) n(2≤n≤105), You can operate on the sequence any time . Operation is defined as :
- Select two numbers in the sequence a i a_{i} ai, a j a_{j} aj ( i ≠ j , 1 ≤ a i , a j ≤ 1 0 9 ) (i \ne j, 1 \le a_{i},a_{j} \le 10^9) (i=j,1≤ai,aj≤109), Subtract their values respectively 1 1 1.
Find the... Of the sequence after several operations n n n Is it possible that all the numbers are 0 0 0. If possible, output Y E S YES YES, Otherwise output N O NO NO.
Title Description
You are given an array a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an .
In one operation you can choose two elements a i a_i ai and a j a_j aj ( i ≠ j i \ne j i=j ) and decrease each of them by one.
You need to check whether it is possible to make all the elements equal to zero or not.
Input format
The first line contains a single integer n n n ( 2 ≤ n ≤ 1 0 5 2 \le n \le 10^5 2≤n≤105 ) — the size of the array.
The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1≤ai≤109 ) — the elements of the array.
Output format
Print “YES” if it is possible to make all elements zero, otherwise print “NO”.
Examples #1
The sample input #1
4
1 1 2 2
Sample output #1
YES
Examples #2
The sample input #2
6
1 2 3 4 5 6
Sample output #2
NO
Tips
In the first example, you can make all elements equal to zero in 3 3 3 operations:
- Decrease a 1 a_1 a1 and a 2 a_2 a2 ,
- Decrease a 3 a_3 a3 and a 4 a_4 a4 ,
- Decrease a 3 a_3 a3 and a 4 a_4 a4
In the second example, one can show that it is impossible to make all elements equal to zero.
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
ll n,k,s=0,mmax=0;
int main(){
cin>>n;
for(ll i=1;i<=n;i++){
scanf("%lld",&k);
s+=k;
mmax=max(mmax,k);
}
if(s%2==1||s<2*mmax) puts("NO");
else puts("YES");
return 0;
}
RGB Substring (easy version)
Topic translation
The only difference is the range of data .
Here you are. q q q Group inquiry ( 1 ≤ q ≤ 2000 1 \le q \le 2000 1≤q≤2000)
Each group will first give you one n n n And a k k k( 1 ≤ k ≤ n ≤ 2000 1 \le k \le n \le 2000 1≤k≤n≤2000)
The next line is a string s s s( Data assurance s s s Only capital letters R R R、 G G G、 B B B form , Input data to ensure all s s s Length and $ \le 2000 ) Now I ask you how many times to modify at least ) Now I ask you how many times to modify at least ) Now I ask you how many times to modify at least s Letters in ( Only one letter can be modified at a time ), Can make Letters in ( Only one letter can be modified at a time ), Can make Letters in ( Only one letter can be modified at a time ), Can make s A substring of is a string A substring of is a string A substring of is a string RGBRGBRGB… The string of , At the same time, the length of the substring The string of , At the same time, the length of the substring The string of , At the same time, the length of the substring \ge k$.
Title Description
The only difference between easy and hard versions is the size of the input.
You are given a string s s s consisting of n n n characters, each character is ‘R’, ‘G’ or ‘B’.
You are also given an integer k k k .
Your task is to change the minimum number of characters in the initial string s s s so that after the changes there will be a string of length k k k that is a substring of s s s , and is also a substring of the infinite string “RGBRGBRGB …”.
A string a a a is a substring of string b b b if there exists a positive integer i i i such that a 1 = b i a_1 = b_i a1=bi , a 2 = b i + 1 a_2 = b_{i + 1} a2=bi+1 , a 3 = b i + 2 a_3 = b_{i + 2} a3=bi+2 , …, a ∣ a ∣ = b i + ∣ a ∣ − 1 a_{|a|} = b_{i + |a| - 1} a∣a∣=bi+∣a∣−1 .
For example, strings “GBRG”, “B”, “BR” are substrings of the infinite string “RGBRGBRGB …” while “GR”, “RGR” and “GGG” are not.
You have to answer q q q independent queries.
Input format
The first line of the input contains one integer q q q ( 1 ≤ q ≤ 2000 1 \le q \le 2000 1≤q≤2000 ) — the number of queries.
Then q q q queries follow.
The first line of the query contains two integers n n n and k k k ( 1 ≤ k ≤ n ≤ 2000 1 \le k \le n \le 2000 1≤k≤n≤2000 ) — the length of the string s s s and the length of the substring.
The second line of the query contains a string s s s consisting of n n n characters ‘R’, ‘G’ and ‘B’.
It is guaranteed that the sum of n n n over all queries does not exceed 2000 2000 2000 ( ∑ n ≤ 2000 \sum n \le 2000 ∑n≤2000 ).
Output format
For each query print one integer — the minimum number of characters you need to change in the initial string s s s so that after changing there will be a substring of length k k k in s s s that is also a substring of the infinite string “RGBRGBRGB …”.
Examples #1
The sample input #1
3
5 2
BGGGG
5 3
RBRGR
5 5
BBBRR
Sample output #1
1
0
3
Tips
In the first example, you can change the first character to ‘R’ and obtain the substring “RG”, or change the second character to ‘R’ and obtain “BR”, or change the third, fourth or fifth character to ‘B’ and obtain “GB”.
In the second example, the substring is “BRG”.
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
int n,k,q;
int main(){
cin>>q;
while(q--){
string s;
scanf("%d%d",&n,&k);
cin>>s;
int w=k,mmin=INT_MAX,t=0,ss=0;
while(w<=n){
for(int j=t;j<w;j++){
if(j%3==0&&s[j]!='R') ss++;
if(j%3==1&&s[j]!='G') ss++;
if(j%3==2&&s[j]!='B') ss++;
}
mmin=min(mmin,ss),ss=0;
for(int j=t;j<w;j++){
if(j%3==0&&s[j]!='G') ss++;
if(j%3==1&&s[j]!='B') ss++;
if(j%3==2&&s[j]!='R') ss++;
}
mmin=min(mmin,ss),ss=0;
for(int j=t;j<w;j++){
if(j%3==0&&s[j]!='B') ss++;
if(j%3==1&&s[j]!='R') ss++;
if(j%3==2&&s[j]!='G') ss++;
}
mmin=min(mmin,ss),ss=0;
t++,w++;
}
cout<<mmin<<endl;
}
return 0;
}
Robot Breakout
Topic translation
Topic translation
Yes n n n A robot is on a plane , The first i i i The position of the robot is ( X i , Y i ) (X_i,Y_i) (Xi,Yi).
In design , The first i i i Operations that a robot can perform :
Location slave ( X i , Y i ) (X_i,Y_i) (Xi,Yi) Turn into ( X i − 1 , Y i ) (X_i-1,Y_i) (Xi−1,Yi).
Location slave ( X i , Y i ) (X_i,Y_i) (Xi,Yi) Turn into ( X i , Y i + 1 ) (X_i,Y_i+1) (Xi,Yi+1).
Location slave ( X i , Y i ) (X_i,Y_i) (Xi,Yi) Turn into ( X i + 1 , Y i ) (X_i+1,Y_i) (Xi+1,Yi).
Location slave ( X i , Y i ) (X_i,Y_i) (Xi,Yi) Turn into ( X i , Y i − 1 ) (X_i,Y_i-1) (Xi,Yi−1).
But the design has defects , Some robots may not be able to perform some of the above operations .
You need to find a point ( A , H ) (A,H) (A,H), bring n n n Every robot can reach ( A , H ) (A,H) (A,H) . Be careful , The initial position is ( A , H ) (A,H) (A,H) It's also arrival , And for A , H A,H A,H The scope of is limited —— − 1 0 5 ≤ A , H ≤ 1 0 5 -10^5\leq A,H \leq 10^5 −105≤A,H≤105.
Input format
There are several groups of data in this question .
The first line of the entire input , It's an integer q ( 1 ≤ q ≤ 1 0 5 ) q (1\leq q \leq 10^5) q(1≤q≤105) , Represents the number of data groups .
For each set of data , The first line has an integer n n n , Indicates the number of robots .
Next n n n That's ok , Each row 6 6 6 It's an integer X i , Y i , f 1 , f 2 , f 3 , f 4 ( − 1 0 5 ≤ X i , Y i ≤ 1 0 5 , 0 ≤ f 1 , f 2 , f 3 , f 4 ≤ 1 ) X_i,Y_i,f_1,f_2,f_3,f_4( - 10^ 5 \leq X_i,Y_i \leq 10^ 5,0 \leq f_1,f_2,f_3,f_4 \leq 1) Xi,Yi,f1,f2,f3,f4(−105≤Xi,Yi≤105,0≤f1,f2,f3,f4≤1). X i , Y i X_i,Y_i Xi,Yi Represents the coordinates of the robot , f 1 , f 2 , f 3 , f 4 f_1,f_2,f_3,f_4 f1,f2,f3,f4 Separate indication control i i i The above of robots 4 4 4 Whether the functions are available . If f a h a k = 1 ( 1 ≤ a h a k ≤ 4 ) f_{ahak} = 1 (1\leq ahak \leq 4) fahak=1(1≤ahak≤4), It means No a h a k ahak ahak Functions are available , Otherwise, it is not available .
Output format
For each set of data , If there is no solution , Output 0 0 0.
otherwise , Output A , H A,H A,H, It means that all robots can reach ( A , H ) (A,H) (A,H).
Title Description
n n n robots have escaped from your laboratory!
You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous!
Fortunately, even though your robots have escaped, you still have some control over them.
First of all, you know the location of each robot: the world you live in can be modeled as an infinite coordinate plane, and the i i i -th robot is currently located at the point having coordinates ( x i x_i xi , y i y_i yi ).
Furthermore, you may send exactly one command to all of the robots.
The command should contain two integer numbers X X X and Y Y Y , and when each robot receives this command, it starts moving towards the point having coordinates ( X X X , Y Y Y ).
The robot stops its movement in two cases:
- either it reaches ( X X X , Y Y Y );
- or it cannot get any closer to ( X X X , Y Y Y ).
Normally, all robots should be able to get from any point of the coordinate plane to any other point.
Each robot usually can perform four actions to move. Let’s denote the current coordinates of the robot as ( x c x_c xc , y c y_c yc ).
Then the movement system allows it to move to any of the four adjacent points:
- the first action allows it to move from ( x c x_c xc , y c y_c yc ) to ( x c − 1 x_c - 1 xc−1 , y c y_c yc );
- the second action allows it to move from ( x c x_c xc , y c y_c yc ) to ( x c x_c xc , y c + 1 y_c + 1 yc+1 );
- the third action allows it to move from ( x c x_c xc , y c y_c yc ) to ( x c + 1 x_c + 1 xc+1 , y c y_c yc );
- the fourth action allows it to move from ( x c x_c xc , y c y_c yc ) to ( x c x_c xc , y c − 1 y_c - 1 yc−1 ).
Unfortunately, it seems that some movement systems of some robots are malfunctioning.
For each robot you know which actions it can perform, and which it cannot perform.
You want to send a command so all robots gather at the same point.
To do so, you have to choose a pair of integer numbers X X X and Y Y Y so that each robot can reach the point ( X X X , Y Y Y ). Is it possible to find such a point?
Input format
The first line contains one integer q q q ( 1 ≤ q ≤ 1 0 5 1 \le q \le 10^5 1≤q≤105 ) — the number of queries.
Then q q q queries follow.
Each query begins with one line containing one integer n n n ( 1 ≤ n ≤ 1 0 5 1 \le n \le 10^5 1≤n≤105 ) — the number of robots in the query.
Then n n n lines follow, the i i i -th of these lines describes the i i i -th robot in the current query: it contains six integer numbers x i x_i xi , y i y_i yi , f i , 1 f_{i, 1} fi,1 , f i , 2 f_{i, 2} fi,2 , f i , 3 f_{i, 3} fi,3 and f i , 4 f_{i, 4} fi,4 ( − 1 0 5 ≤ x i , y i ≤ 1 0 5 -10^5 \le x_i, y_i \le 10^5 −105≤xi,yi≤105 , $0 \le f_{i, j} \le 1 $ ).
The first two numbers describe the initial location of the i i i -th robot, and the following four numbers describe which actions the i i i -th robot can use to move ( f i , j = 1 f_{i, j} = 1 fi,j=1 if the i i i -th robot can use the j j j -th action, and f i , j = 0 f_{i, j} = 0 fi,j=0 if it cannot use the j j j -th action).
It is guaranteed that the total number of robots over all queries does not exceed 1 0 5 10^5 105 .
Output format
You should answer each query independently, in the order these queries appear in the input.
To answer a query, you should do one of the following:
- if it is impossible to find a point that is reachable by all n n n robots, print one number 0 0 0 on a separate line;
- if it is possible to find a point that is reachable by all n n n robots, print three space-separated integers on the same line: 1 1 1 X X X Y Y Y , where X X X and Y Y Y are the coordinates of the point reachable by all n n n robots.
Both X X X and Y Y Y should not exceed 1 0 5 10^5 105 by absolute value; it is guaranteed that if there exists at least one point reachable by all robots, then at least one of such points has both coordinates not exceeding 1 0 5 10^5 105 by absolute value.
Examples #1
The sample input #1
4
2
-1 -2 0 0 0 0
-1 -2 0 0 0 0
3
1 5 1 1 1 1
2 5 0 1 0 1
3 5 1 0 0 0
2
1337 1337 0 1 1 1
1336 1337 1 1 0 1
1
3 5 1 1 1 1
Sample output #1
1 -1 -2
1 2 5
0
1 -100000 -100000
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
int n,q;
int main(){
cin>>q;
while(q--){
scanf("%d",&n);
int minx=-1e5,maxx=1e5,miny=-1e5,maxy=1e5;
for(int i=1;i<=n;i++){
int x,y,a,b,c,d;
scanf("%d%d",&x,&y);
scanf("%d%d%d%d",&a,&b,&c,&d);
if(!a) minx=max(minx,x);
if(!c) maxx=min(maxx,x);
if(!b) maxy=min(maxy,y);
if(!d) miny=max(miny,y);
}
if(minx>maxx||miny>maxy) puts("0");
else printf("1 %d %d\n",minx,miny);
}
return 0;
}
边栏推荐
- The combination sum of C language power deduction question 39. Backtracking method and traversal method
- LeetCode 70爬楼梯、199二叉树的右视图、232用栈实现队列、143重排链表
- Try to run this command from the system terminal Make sure that you use the correct
- pbootcms模板调用标签序数从2开始或者自动数开始
- Draw pictures with canvas
- Study and use of windows security defect detection tool wesng
- 暗黑系王者,低照度图像增强技术解析
- View Binding 混淆问题。我两天都在研究混淆。
- What is naked SQL? What middleware or plug-in is good for express to operate MySQL?
- 浅谈元宇宙中DeFi的可能性和局限性
猜你喜欢

Use the hiflow scene connector to view the epidemic situation in the region every day

ggplot2显示png

Performance optimization of wechat applet (subcontracting, operation process details, simplified structure, native component communication)

原生组件、小程序与客户端通信原理、video、map、canvas、picker等运行原理

5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字

Install go environment under Kali

Combined with actual combat, analyze gb/t 28181 (II) -- equipment directory synchronization

One year after graduation, I gave up the internship opportunity and taught myself software testing at home. The internship of my classmates has just ended. I have become a 12K monthly salary testing e

Network protocol details: TCP part1

Seatunnel architecture
随机推荐
Responsive layout a web page displays different effects on different devices) meta:vp
Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
Digicert code signing certificate
Digital transformation behind the reshaping growth of catering chain stores
STM32 installation tutorial and j-link burning driver installation tutorial [the next day]
Performance test of ArrayList and LinkedList insertion based on jmh
深入理解微信小程序的底层框架(二)组件系统、Exparser
Phpcms realizes product multi condition screening function
[bdsec CTF 2022] partial WP
Preliminary use of 145 keep alive
Leetcode 70 climbing stairs, 199 right view of binary tree, 232 realizing queue with stack, 143 rearranging linked list
Is Huatai Securities safe to open an account? How to handle it
Share two interesting special effects
[Luogu] p1972 HH Necklace
Hydrogen entrepreneurship competition | Liu Xiaoqi, chairman of Guohua Investment: take advantage of the integration of scenery, hydrogen storage and finance to host the entrepreneurship competition a
Improvement of DB file sequential read caused by insert
奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5
Login with a third-party account
What is restful
Jmeter+influxdb+grafana pressure measurement real-time monitoring platform construction