当前位置:网站首页>Codeworks 5 questions per day (average 1500) - day 24
Codeworks 5 questions per day (average 1500) - day 24
2022-07-27 20:09:00 【Soup key】
Hyperset
Topic translation
Yes n Zhang card , Each card has k Features , There are three kinds of features (‘S’, ‘E’, ‘T’), Let you choose three cards to form a set , Make each feature of the three cards equal or different . As in example 3 "SETT", “TEST”, "EEET" It's a set ,“TEST”, “ESTE”, "STES" Is a set of , Ask how many sets you can choose .
Title Description
Bees Alice and Alesya gave beekeeper Polina famous card game “Set” as a Christmas present.
The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color.
In this game, some combinations of three cards are said to make up a set.
For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different.
The picture below shows how sets look.

Polina came up with a new game called “Hyperset”. In her game, there are n n n cards with k k k features, each feature has three possible values: “S”, “E”, or “T”.
The original “Set” game can be viewed as “Hyperset” with k = 4 k = 4 k=4 .
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different.
The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it’s time for Polina to go to school.
Help Polina find the number of sets among the cards lying on the table.
Input format
The first line of each test contains two integers n n n and k k k ( 1 ≤ n ≤ 1500 1 \le n \le 1500 1≤n≤1500 , 1 ≤ k ≤ 30 1 \le k \le 30 1≤k≤30 ) — number of cards and number of features.
Each of the following n n n lines contains a card description: a string consisting of k k k letters “S”, “E”, “T”.
The i i i -th character of this string decribes the i i i -th feature of that card.
All cards are distinct.
Output format
Output a single integer — the number of ways to choose three cards that form a set.
Examples #1
The sample input #1
3 3
SET
ETS
TSE
Sample output #1
1
Examples #2
The sample input #2
3 4
SETE
ETSE
TSES
Sample output #2
0
Examples #3
The sample input #3
5 4
SETT
TEST
EEET
ESTE
STES
Sample output #3
2
Tips
In the third example test, these two triples of cards are sets:
- “SETT”, “TEST”, “EEET”
- “TEST”, “ESTE”, “STES”
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int n,k;
string s[N];
ll ss=0;
map<string,int> gg;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>s[i];
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
string p="";
for(int kk=0;kk<k;kk++){
if(s[i][kk]==s[j][kk]) p+=s[i][kk];
else{
if(s[i][kk]!='S'&&s[j][kk]!='S') p+='S';
if(s[i][kk]!='E'&&s[j][kk]!='E') p+='E';
if(s[i][kk]!='T'&&s[j][kk]!='T') p+='T';
}
}
ss+=gg[p];
}gg[s[i]]++;
}
cout<<ss<<endl;
return 0;
}
Motarack’s Birthday
Topic translation
t t t Group data .
Given a n n n And a length of n n n Of , except − 1 -1 −1 A sequence in which all other numbers are non negative a a a, The request will a a a All in − 1 -1 −1 Fill in with k k k, Make the difference between the absolute values of adjacent numbers in the sequence minimum .
Output the difference between the minimum absolute value and the filled number k k k, If there are multiple possibilities k k k, Output any one .
Title Description
Dark is going to attend Motarack’s birthday.
Dark decided that the gift he is going to give to Motarack is an array a a a of n n n non-negative integers.
Dark created that array 1000 1000 1000 years ago, so some elements in that array disappeared.
Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them.
He doesn’t have much time so he wants to choose an integer k k k ( 0 ≤ k ≤ 1 0 9 0 \leq k \leq 10^{9} 0≤k≤109 ) and replaces all missing elements in the array a a a with k k k .
Let m m m be the maximum absolute difference between all adjacent elements (i.e. the maximum value of ∣ a i − a i + 1 ∣ |a_i - a_{i+1}| ∣ai−ai+1∣ for all 1 ≤ i ≤ n − 1 1 \leq i \leq n - 1 1≤i≤n−1 ) in the array a a a after Dark replaces all missing elements with k k k .
Dark should choose an integer k k k so that m m m is minimized. Can you help him?
Input format
The input consists of multiple test cases.
The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1≤t≤104 ) — the number of test cases.
The description of the test cases follows.
The first line of each test case contains one integer n n n ( 2 ≤ n ≤ 1 0 5 2 \leq n \leq 10^{5} 2≤n≤105 ) — the size of the array a a a .
The second line of each test case 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 \leq a_i \leq 10 ^ {9} −1≤ai≤109 ).
If a i = − 1 a_i = -1 ai=−1 , then the i i i -th integer is missing. It is guaranteed that at least one integer is missing in every test case.
It is guaranteed, that the sum of n n n for all test cases does not exceed 4 ⋅ 1 0 5 4 \cdot 10 ^ {5} 4⋅105 .
Output format
Print the answers for each test case in the following format:
You should print two integers, the minimum possible value of m m m and an integer k k k ( 0 ≤ k ≤ 1 0 9 0 \leq k \leq 10^{9} 0≤k≤109 ) that makes the maximum absolute difference between adjacent elements in the array a a a equal to m m m .
Make sure that after replacing all the missing elements with k k k , the maximum absolute difference between adjacent elements becomes m m m .
If there is more than one possible k k k , you can print any of them.
Examples #1
The sample input #1
7
5
-1 10 -1 12 -1
5
-1 40 35 -1 35
6
-1 -1 9 -1 3 -1
2
-1 -1
2
0 -1
4
1 -1 3 -1
7
1 -1 7 5 2 -1 5
Sample output #1
1 11
5 35
3 6
0 42
0 0
1 2
3 4
Tips
In the first test case after replacing all missing elements with 11 11 11 the array becomes [ 11 , 10 , 11 , 12 , 11 ] [11, 10, 11, 12, 11] [11,10,11,12,11] .
The absolute difference between any adjacent elements is 1 1 1 .
It is impossible to choose a value of k k k , such that the absolute difference between any adjacent element will be ≤ 0 \leq 0 ≤0 .
So, the answer is 1 1 1 .
In the third test case after replacing all missing elements with 6 6 6 the array becomes [ 6 , 6 , 9 , 6 , 3 , 6 ] [6, 6, 9, 6, 3, 6] [6,6,9,6,3,6] .
- ∣ a 1 − a 2 ∣ = ∣ 6 − 6 ∣ = 0 |a_1 - a_2| = |6 - 6| = 0 ∣a1−a2∣=∣6−6∣=0 ;
- ∣ a 2 − a 3 ∣ = ∣ 6 − 9 ∣ = 3 |a_2 - a_3| = |6 - 9| = 3 ∣a2−a3∣=∣6−9∣=3 ;
- ∣ a 3 − a 4 ∣ = ∣ 9 − 6 ∣ = 3 |a_3 - a_4| = |9 - 6| = 3 ∣a3−a4∣=∣9−6∣=3 ;
- ∣ a 4 − a 5 ∣ = ∣ 6 − 3 ∣ = 3 |a_4 - a_5| = |6 - 3| = 3 ∣a4−a5∣=∣6−3∣=3 ;
- ∣ a 5 − a 6 ∣ = ∣ 3 − 6 ∣ = 3 |a_5 - a_6| = |3 - 6| = 3 ∣a5−a6∣=∣3−6∣=3 .
So, the maximum difference between any adjacent elements is 3 3 3 .
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int t,n,kmax,kmin,k,a[N],s=0;
int main(){
cin>>t;
while(t--){
scanf("%d",&n);
kmax=-1,kmin=2e9;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
a[n+1]=0;
for(int i=1;i<=n;i++){
if(a[i]!=-1&&(a[i-1]==-1||a[i+1]==-1)){
kmax=max(kmax,a[i]);
kmin=min(kmin,a[i]);
}
}
k=(kmin+kmax)/2;
for(int i=1;i<=n;i++){
if(a[i]==-1) a[i]=k;
if(i!=1) s=max(s,abs(a[i]-a[i-1]));
}
printf("%d %d\n",s,k);
s=k=0;
}
return 0;
}
Air Conditioner
Topic translation
There is an air conditioner in a restaurant , You can choose to increase every minute 1 1 1 The temperature of a unit may be lowered 1 1 1 Unit temperature , Of course, you can also choose not to change , The initial temperature is m m m .
Yes n n n Diners , Every diner will be t i t_i ti Arrive at , The lowest temperature he can adapt to is l i l_i li , The maximum temperature is h i h_i hi , He will only be t i t_i ti Always stay .
If the temperature is not within the adaptive range of diners , He will feel uncomfortable , Please judge , Can the air conditioner make n n n All the diners who came to dinner felt comfortable .
Multiple groups of data , The number of data groups is not greater than 500 500 500.
1 ≤ n ≤ 100 1\le n\le 100 1≤n≤100, − 1 0 9 ≤ m , l i , h i ≤ 1 0 9 -10^9\le m,l_i,h_i\le 10^9 −109≤m,li,hi≤109, 1 ≤ t i ≤ 1 0 9 1\le t_i\le 10^9 1≤ti≤109.
Title Description
Gildong owns a bulgogi restaurant.
The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers’ preferred temperature ranges!
Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling.
When it’s off, the restaurant’s temperature remains the same.
When it’s heating, the temperature increases by 1 in one minute.
Lastly, when it’s cooling, the temperature decreases by 1 in one minute.
Gildong can change the state as many times as he wants, at any integer minutes.
The air conditioner is off initially.
Each customer is characterized by three values: t i t_i ti — the time (in minutes) when the i i i -th customer visits the restaurant, l i l_i li — the lower bound of their preferred temperature range, and h i h_i hi — the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant.
Formally, the i i i -th customer is satisfied if and only if the temperature is between l i l_i li and h i h_i hi (inclusive) in the t i t_i ti -th minute.
Given the initial temperature, the list of reserved customers’ visit times and their preferred temperature ranges, you’re going to help him find if it’s possible to satisfy all customers.
Input format
Each test contains one or more test cases.
The first line contains the number of test cases q q q ( 1 ≤ q ≤ 500 1 \le q \le 500 1≤q≤500 ).
Description of the test cases follows.
The first line of each test case contains two integers n n n and m m m ( 1 ≤ n ≤ 100 1 \le n \le 100 1≤n≤100 , − 1 0 9 ≤ m ≤ 1 0 9 -10^9 \le m \le 10^9 −109≤m≤109 ), where n n n is the number of reserved customers and m m m is the initial temperature of the restaurant.
Next, n n n lines follow.
The i i i -th line of them contains three integers t i t_i ti , l i l_i li , and h i h_i hi ( 1 ≤ t i ≤ 1 0 9 1 \le t_i \le 10^9 1≤ti≤109 , − 1 0 9 ≤ l i ≤ h i ≤ 1 0 9 -10^9 \le l_i \le h_i \le 10^9 −109≤li≤hi≤109 ), where t i t_i ti is the time when the i i i -th customer visits, l i l_i li is the lower bound of their preferred temperature range, and h i h_i hi is the upper bound of their preferred temperature range.
The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0 0 0 .
Output format
For each test case, print “YES” if it is possible to satisfy all customers. Otherwise, print “NO”.
You can print each letter in any case (upper or lower).
Examples #1
The sample input #1
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Sample output #1
YES
NO
YES
NO
Tips
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
- At 0 0 0 -th minute, change the state to heating (the temperature is 0).
- At 2 2 2 -nd minute, change the state to off (the temperature is 2).
- At 5 5 5 -th minute, change the state to heating (the temperature is 2, the 1 1 1 -st customer is satisfied).
- At 6 6 6 -th minute, change the state to off (the temperature is 3).
- At 7 7 7 -th minute, change the state to cooling (the temperature is 3, the 2 2 2 -nd customer is satisfied).
- At 10 10 10 -th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0 0 0 -th minute and leave it be.
Then all customers will be satisfied.
Note that the 1 1 1 -st customer’s visit time equals the 2 2 2 -nd customer’s visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int t,n,m;
struct stu{
int t,l,r;
}s[N];
bool cmp(stu x,stu y){
return x.t<y.t;
}
int main(){
cin>>t;
while(t--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&s[i].t,&s[i].l,&s[i].r);
}
sort(s+1,s+1+n,cmp);
int l=m,r=m;
bool ok=1;
for(int i=1;i<=n;i++){
int d=s[i].t-s[i-1].t;
l-=d,r+=d;
l=max(l,s[i].l);
r=min(r,s[i].r);
if(l>r){
ok=0;
break;
}
}
if(ok) puts("YES");
else puts("NO");
}
return 0;
}
Binary String Reconstruction
Topic translation
Altogether t t t Group data .
Each set of data has three integers n 0 , n 1 , n 2 n_0,n_1,n_2 n0,n1,n2.
You need to build a 01 01 01 strand , The length is n 0 + n 1 + n 2 + 1 n_0+n_1+n_2+1 n0+n1+n2+1, For each length 2 2 2 A continuous substring of , All in all n 0 n_0 n0 A and for 0 0 0, Yes n 1 n_1 n1 A and for 1 1 1, Yes n 2 n_2 n2 A and for 2 2 2.
Make sure the input is clear , For each set of data , Output one line , For one 01 01 01 strand , There are no spaces , If there are multiple solutions , Output any one .
Title Description
For some binary string s s s (i.e. each character s i s_i si is either ‘0’ or ‘1’), all pairs of consecutive (adjacent) characters were written.
In other words, all substrings of length 2 2 2 were written.
For each pair (substring of length 2 2 2 ), the number of ‘1’ (ones) in it was calculated.
You are given three numbers:
- n 0 n_0 n0 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 0 0 0 ;
- n 1 n_1 n1 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 1 1 1 ;
- n 2 n_2 n2 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 2 2 2 .
For example, for the string s = s= s= “1110011110”, the following substrings would be written: “11”, “11”, “10”, “00”, “01”, “11”, “11”, “11”, “10”.
Thus, n 0 = 1 n_0=1 n0=1 , n 1 = 3 n_1=3 n1=3 , n 2 = 5 n_2=5 n2=5 .
Your task is to restore any suitable binary string s s s from the given values n 0 , n 1 , n 2 n_0, n_1, n_2 n0,n1,n2 .
It is guaranteed that at least one of the numbers n 0 , n 1 , n 2 n_0, n_1, n_2 n0,n1,n2 is greater than 0 0 0 .
Also, it is guaranteed that a solution exists.
Input format
The first line contains an integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1≤t≤1000 ) — the number of test cases in the input.
Then test cases follow.
Each test case consists of one line which contains three integers n 0 , n 1 , n 2 n_0, n_1, n_2 n0,n1,n2 ( 0 ≤ n 0 , n 1 , n 2 ≤ 100 0 \le n_0, n_1, n_2 \le 100 0≤n0,n1,n2≤100 ; n 0 + n 1 + n 2 > 0 n_0 + n_1 + n_2 > 0 n0+n1+n2>0 ).
It is guaranteed that the answer for given n 0 , n 1 , n 2 n_0, n_1, n_2 n0,n1,n2 exists.
Output format
Print t t t lines.
Each of the lines should contain a binary string corresponding to a test case.
If there are several possible solutions, print any of them.
Examples #1
The sample input #1
7
1 3 5
1 1 1
3 9 3
0 1 0
3 1 2
0 0 3
2 0 0
Sample output #1
1110011110
0011
0110001100101011
10
0000111
1111
000
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int t,n0,n1,n2;
int main(){
cin>>t;
while(t--){
scanf("%d%d%d",&n0,&n1,&n2);
if(n1==0){
if(n0) for(int i=1;i<=n0+1;i++) cout<<0;
else for(int i=1;i<=n2+1;i++) cout<<1;
cout<<endl;
}
else{
for(int i=1;i<=n0+1;i++) cout<<0;
for(int i=1;i<=n2+1;i++) cout<<1;
n1--;
for(int i=1;i<=n1;i++){
if(i%2) cout<<0;
else cout<<1;
}
cout<<endl;
}
}
return 0;
}
边栏推荐
猜你喜欢

MVCC的底层原理

Chapter 3 basic operation

22年PMP考试【全真敏捷试题】

Understanding of basic concepts of channel capacity and channel bandwidth

2022 love analysis · smart community manufacturer panoramic report manufacturer solicitation

Common errors reported by pytorch

cesium基本控件介绍

C background GC cause and effect

New library online | cnopendata detailed address data of all patents in China

How to encrypt the data in MySQL database? Mysql8.0 comes with new features
随机推荐
产品经理:排查下线上哪里冒出个“系统异常”的错误提示
cesium基本控件介绍
unity2D 动态漫画剧本(给猛虎桥章节做动画演示二)
Capacitance in series and in parallel and capacitance in series and balance resistance
C193:评分系统
focal loss
C # network application programming, experiment 2: IP address translation and domain name resolution exercises
Common operators 9.21
C191: password compilation
Online Judge 输出超限
[paper reading] rich feature hierarchies for accurate object detection and semantic segmentation
C243: examination ranking
LED high precision scale scheme specification
LeetCode练习2——两数之和
会员卡头部组件使用文档
2022爱分析·智慧社区厂商全景报告 厂商征集
C#网络应用编程,实验一:WPF练习
Global function
顶级“黑客”能厉害到什么地步?无信号也能上网,专家:高端操作!
Can go to QQ but can't open the web page