WAWA cried, Weak chicken picking silver for retirement
Thank you for your great help from your teammates, master Fang and brother Qi 👍
C | Infectious disease statisticshttps://ac.nowcoder.com/acm/contest/22352/C |
Title Description
A Qiang came to the street. There were N people on the street, numbered 1 ∼ N. For simplicity, we see everyone as a point on a line. For each legal I, the position of the i-th person is xi.
One of these people happens to be infected with COVID-19, but we don't know which one. When the distance between an infected person and an uninfected person is no more than 2, the virus will spread from the former to the latter. If we wait long enough, some people (determined by the first infected person) will be infected; The number of these people is called the number of people eventually infected.
A Qiang hopes to find the minimum and maximum possible values of the number of people eventually infected, that is, the values of this number in the best and worst cases.
Enter Description:
The first row contains an integer T(1 ≤ T ≤ 2000), indicating the number of data groups. Next is group T data. • the first row of each set of data contains an integer N(2 ≤ N ≤ 8). • the second line contains N integers x1,x2,..., xn(0 ≤ xi ≤ 10) separated by spaces.
Output Description:
For each group of data, the output line contains two integers separated by spaces, indicating the minimum and maximum number of people finally infected.
Example 1
input
3 2 3 6 3 1 3 5 5 1 2 5 6 7
output
1 1 3 3 2 3
#include <bits/stdc++.h> using namespace std; int a[10],d[10]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int t,n; cin >> t; while(t--) { cin>>n; cin>>a[0]; for(int i=1;i<n;i++){ cin>>a[i]; d[i-1]=a[i]-a[i-1]; } int resMax=-1,resMin=8,cnt=0; for(int i=0;i<n-1;i++){ cnt=0; while(d[i]<=2&&i<n-1){ cnt++; i++; } resMax=max(resMax,cnt); resMin=min(resMin,cnt); } cout<<resMin+1<<' '<<resMax+1<<'\n'; } return 0; }
D | A Qiang and gridhttps://ac.nowcoder.com/acm/contest/22352/D |
Title Description
A Qiang is in a grid of N rows and M columns.
A Qiang can move in two ways:
Move down, left, up, or right at a cost of X. In other words, if you are in the cell (i, J) of the grid, you can go to any cell (i+1, J), (i, J − 1), (i − 1, J) or (i, j+1) at the cost of X.
The cost of moving diagonally down left, down right, up left and up right is y. In other words, if you are on the cell (i, J) of the grid, you can go to any cell (i+1, J − 1), (i+1, j+1), (i − 1, J − 1) or (i − 1, j+1) at the cost of Y.
Please find the minimum cost from a Qiang from the upper left corner (1,1) to the lower right corner (N, M).
A Qiang can't move out of the grid.
Enter Description:
In the first row, an integer T(1 ≤ T ≤ 5 * 10 ^ 5) represents the number of data groups.
Next, there are four integers N,M,X,Y(1 ≤ N,M,X,Y ≤ 10 ^ 6) in each line of line T
Output Description:
For each group of data, a row represents the answer.
Example 1
input
3 5 6 2 5 4 7 5 6 7 8 6 5
output
18 33 36
Pure simulation is good
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ long long N,M,X,Y; long long ans = 0; cin >> N >> M >> X >> Y; N--,M--; long long MIN = min(N,M); long long MAX = max(N,M); long long len = MAX - MIN; if(N && M){ if(Y >= 2 * X){ ans += (N + M) * X; }else if(Y >= X){ ans += Y * MIN; ans += len * X; }else{ if(len & 1){ ans += Y * MIN; ans += Y * (len - 1); ans += X; }else{ ans += Y * MAX; } } }else{ ans += X * MAX; } cout << ans << '\n'; } return 0; }
E | The Big Bang Theoryhttps://ac.nowcoder.com/acm/contest/22352/E |
Link: Login - professional IT written examination interview preparation platform niuke.com
Source: niuke.com
Title Description
There are n boys and m girls participating in the drama club. To produce a drama the big bang, they need to choose a group of t actors, including no less than 4 boys and no less than 1 girl. How many ways can they form a group? Of course, only different variants of the composition of the troupe are considered different.
Enter Description:
One line contains three integers n, m, t (4 n ≤ 30, 1 m ≤ 30, 5 t ≤ n+m)
Output Description:
One line represents the answer.
Example 1
input
5 2 5
output
10
#include <bits/stdc++.h> using namespace std; long long C[65][65]; void solve(){ for(int i = 0;i <= 65;i++){ for(int j = 0;j <= i;j++){ if(!j){ C[i][j] = 1; }else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m,t; solve(); cin >> n >> m >> t; long long ans = 0; for(int i = 4;i <= n;i++){ for(int j = 1;j <=m;j++){ if(i + j == t){ ans += C[n][i] * C[m][j]; } } } cout << ans << '\n'; return 0; }
F | Capslockhttps://ac.nowcoder.com/acm/contest/22352/F |
Link: Login - professional IT written examination interview preparation platform niuke.com
Source: niuke.com
Title Description
Caps lock is a computer keyboard key. Press this key to set the input mode. By default, the letters typed are capitalized. If it is pressed accidentally, it will cause some accidents.
Let's consider the case where the Caps lock key opens unexpectedly when typing a character. If:
1. It contains only capital letters;
2. All letters are capitalized except the first one.
In both cases, we should change the case of all letters. For example, the case of the words "hELLO", "HTTP", "z" should be changed.
Write a program to apply the above rules. If the rules cannot be applied, the program should keep the words unchanged.
Enter Description:
The first line contains a word consisting of uppercase and lowercase letters. The length of the word is less than or equal to 100.
Output Description:
Print word processing results.
Example 1
input
cAPS
output
Caps
Example 2
input
Lap
output
Lap
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int len = s.size(); bool ok = true; for(int i=1; i<len ;i++){ if(s[i] > 'Z'){ ok = false; break; } } string a; if(ok){ if(s[0] >= 'A' && s[0] <= 'Z'){ cout << (char)(s[0] + 32); }else{ cout << (char)(s[0] - 32); } for(int i=1;i<len;i++){ cout << (char)(s[i] + 32); } }else{ cout << s << '\n'; } return 0; }
G | Byte typehttps://ac.nowcoder.com/acm/contest/22352/G |
Title Description
A Qiang participated in a programming competition. He wanted to choose a language as his main programming language. Because he liked very large numbers, he chose java. It has a very large integer data type, called BigInteger.
But after writing a few questions, Petya realized that not all tasks need to use the BigInteger type. In fact, sometimes a small range of numbers is more conducive to programming. This is why a question arises: "if you want to store a positive integer n, which integer type should you use?"
A Qiang only knows five integer types:
1) Byte takes up 1 byte, allowing storage from - 128 to 127
2) short takes 2 bytes and allows to store numbers - 32768 to 32767 from
3) int takes up 4 bytes and allows to store numbers - 2147483648 to 2147483647
4) long takes up 8 bytes, allowing storage from - 9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer, but it is not a primitive type, and its operation is much slower.
For all types given above, boundary values are included in the value range.
From this list, a Qiang wants to store the integer n and wants to choose the type with the smallest number of bytes. Because BigInteger works much slower, a Qiang thinks it is the one with the most bytes.
Enter Description:
The first line contains a positive number n. It consists of no more than 100 digits and does not contain any leading zeros. The number n cannot be expressed as an empty string.
Output Description:
A line contains a string. The string is generated in "byte, short, int, long, BigInteger", indicating the type that can store the smallest number of occupied bytes of n
Example 1
input
127
output
byte
Example 2
input
123456789101112131415161718192021222324
output
BigInteger
This question is dead with laughter and hard core judgment. There is no TLE. I knew to use Python
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, a; int rua = 0; cin >> s; bool ok = true; if (s[0] == '-') { a = s.substr(1, s.size()); rua = 1; } else { a = s; } int len = a.size(); if (len < 3) { cout << "byte" << "\n"; } else if (len == 3) { if (a[0] - '0' <= 1) if (a[1] - '0' <= 2) if (a[2] - '0' <= 7 + rua){ cout << "byte" << "\n"; ok = false; } if(ok) cout << "short" << "\n"; } else if (len < 5) { cout << "short" << "\n"; } else if (len == 5) { if (a[0] - '0' <= 3) if (a[1] - '0' <= 2) if (a[2] - '0' <= 7) if (a[3] - '0' <= 6) if (a[4] - '0' <= 7 + rua){ cout << "short" << "\n"; ok = false; } if(ok) cout << "int" << "\n"; } else if (len < 10) { cout << "int" << "\n"; } else if (len == 10) { if (a[0] - '0' <= 2) if (a[1] - '0' <= 1) if (a[2] - '0' <= 4) if (a[3] - '0' <= 7) if (a[4] - '0' <= 4) if (a[5] - '0' <= 8) if (a[6] - '0' <= 3) if (a[7] - '0' <= 6) if (a[8] - '0' <= 4) if (a[9] - '0' <= 7 + rua){ cout << "int" << "\n"; ok = false; } if(ok) cout << "long" << "\n"; } else if (len < 19) { cout << "long" << "\n"; } else if (len == 19) { if (a[0] - '0' <= 9) if (a[1] - '0' <= 2) if (a[2] - '0' <= 2) if (a[3] - '0' <= 3) if (a[4] - '0' <= 3) if (a[5] - '0' <= 7) if (a[6] - '0' <= 2) if (a[7] - '0' <= 0) if (a[8] - '0' <= 3) if (a[9] - '0' <= 6) if (a[10] - '0' <= 8) if (a[11] - '0' <= 5) if (a[12] - '0' <= 4) if (a[13] - '0' <= 7) if (a[14] - '0' <= 7) if (a[15] - '0' <= 5) if (a[16] - '0' <= 8) if (a[17] - '0' <= 0) if (a[18] - '0' <= 7 + rua){ cout << "long" << "\n"; ok = false; } if(ok) cout << "BigInteger" << "\n"; } else cout << "BigInteger" << "\n"; return 0; }
I | Perfectionismhttps://ac.nowcoder.com/acm/contest/22352/I |
Title Description
A Qiang picked some apples and arranged them in a row, numbered from left to right as the first... Pile, of which there are ai apples in the pile.
Perfectionist Jane saw the apples and thought they were placed very disorderly. She asked ah Qiang to do the following.
Adjust a pile of apples: a Qiang will adjust the pile of apples to bi;
Reply to Jane's inquiry: each inquiry is expressed as [𝑙, 𝑟], which means asking whether the number of apples from pile 𝑙 to pile 𝑟 meets al ≤ al+1 ≤ * ar − 1 ≤ ar. if it meets, it is called perfect.
Enter Description:
In the first line, two integers n,q (1 ≤ n,q ≤ 3 * 10 ^ 5) represent the number of Apple heaps and operations;
The second line n integers represent ai.
In the following rows, there are 3 integers in each row, and the first integer is opt;
If opt = 1, the next two integers, i, bi, indicate that the heap of apples is adjusted to bi;
If opt = 2, the next two integers 𝑙, 𝑟 represent the query of the apple heap between [𝑙, 𝑟].
(1≤ai,bi≤10^9)
Output Description:
A total of rows are output, with a Yes or No for each row, indicating whether the corresponding interval of each query is perfect.
Example 1
input
7 4 1 2 2 4 3 4 5 1 1 4 2 1 7 2 6 7 2 4 7
output
No Yes No
Segment tree
#include <bits/stdc++.h> using namespace std; const int maxn = 3 * 100005; int a[maxn]; struct segtree{ bool ok; int l; int r; }tr[maxn << 2]; void pushup(int rt){ tr[rt].ok = (tr[rt << 1].ok && tr[rt << 1 | 1].ok)&&(tr[rt << 1].r <= tr[rt << 1 | 1].l); tr[rt].l = tr[rt << 1].l; tr[rt].r = tr[rt << 1 | 1].r; } void build(int l,int r,int rt){ if(l == r){ tr[rt].l = tr[rt].r = a[l]; tr[rt].ok = true; return ; } int mid = (l + r) >> 1; build(l,mid,rt << 1); build(mid + 1,r,rt << 1 | 1); pushup(rt); } void update(int t,int l,int r,int C,int rt){ if(l == r){ tr[rt].l = tr[rt].r = C; return ; } int mid = (l + r) >> 1; if(t <= mid)update(t,l,mid,C,rt << 1); else update(t,mid + 1,r,C,rt << 1 | 1); pushup(rt); } bool query(int L,int R,int l,int r,int rt){ if(L <= l && r <= R){ return tr[rt].ok; } bool ok = true; int mid = (l + r) >> 1; if(L <= mid) ok = (ok && query(L,R,l,mid,rt << 1)); if(R > mid) ok = (ok && query(L,R,mid + 1,r,rt << 1 | 1)); if(L <= mid && R > mid){ ok = (ok && (tr[rt << 1].r <= tr[rt << 1 | 1].l)); } return ok; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,q; cin >> n >> q; for(int i=1;i<=n;i++){ cin >> a[i]; } build(1,n,1); while(q--){ int x; cin >> x; if(x == 1){ int t,C; cin >> t >> C; update(t,1,n,C,1); }else{ int l,r; cin >> l >> r; if(query(l,r,1,n,1)){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; } } } return 0; }
L | Magical answerhttps://ac.nowcoder.com/acm/contest/22352/L |
Title Description
A Qiang is very sensitive to age. Whenever asked about his age, he always wants to escape. So when he is under the age of 18, when others ask him how old he is, he will answer truthfully. When he is older than 18, he will answer: 18.
He travels to different years in a time machine. He knows his age after crossing. So how should he answer when people ask him his age after he crosses?
Enter Description:
The first line is an integer n(1 ≤ n ≤ 100000). Indicates the number of times through the time machine. Next n lines, an integer x(1 ≤ x ≤ 100000) for each line represents the age after crossing.
Output Description:
There are n lines in total, and an integer in each line represents the age of the answer after a crossing.
Example 1
input
4 19 14 4 122
output
18 14 4 18
Check in question
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ int x; cin >> x; if(x >= 18){ cout << 18 << '\n'; }else{ cout << x << '\n'; } } return 0; }