赞
踩
有n张卡,每张卡有k个特征,每个特征有三种(‘S’, ‘E’, ‘T’),让你选出三张卡组成一套,使得三张卡中的每个特征全部相等或者全部不同。如样例三中的"SETT", “TEST”, "EEET"是一套,“TEST”, “ESTE”, "STES"也是一套,问一共能选出几套。
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.
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 a single integer — the number of ways to choose three cards that form a set.
3 3
SET
ETS
TSE
1
3 4
SETE
ETSE
TSES
0
5 4
SETT
TEST
EEET
ESTE
STES
2
In the third example test, these two triples of cards are sets:
#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; }
t t t 组数据。
给定一个 n n n 和一个长度为 n n n 的,除 − 1 -1 −1 外其它数字均为非负数的序列 a a a,要求将 a a a 中所有 − 1 -1 −1 填充为 k k k,使得该序列相邻数字绝对值之差最小。
输出最小绝对值之差及填充的数字 k k k,如果有多个可能的 k k k,输出任意一个。
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?
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 .
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.
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
1 11
5 35
3 6
0 42
0 0
1 2
3 4
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] .
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; }
一个餐馆中有个空调,每分钟可以选择上调 1 1 1 个单位的温度或下调 1 1 1 个单位的温度,当然你也可以选择不变,初始的温度为 m m m 。
有 n n n 个食客,每个食客会在 t i t_i ti 时间点到达,他所能适应的最低温度是 l i l_i li ,最高温度是 h i h_i hi ,他只会在 t i t_i ti 时刻逗留。
如果温度不在食客的适应范围内,他就会不舒服,请你判断,空调能否使得 n n n 位来就餐的食客都感到舒服。
本题多组数据,数据组数不大于 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。
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.
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 .
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).
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
YES
NO
YES
NO
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
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; }
一共有 t t t 组数据。
每组数据有三个整数 n 0 , n 1 , n 2 n_0,n_1,n_2 n0,n1,n2。
你需要构造一个 01 01 01 串,长度为 n 0 + n 1 + n 2 + 1 n_0+n_1+n_2+1 n0+n1+n2+1,对于每一个长度为 2 2 2 的连续子串,总共有 n 0 n_0 n0 个和为 0 0 0, 有 n 1 n_1 n1 个和为 1 1 1,有 n 2 n_2 n2 个和为 2 2 2。
保证输入有解,对于每一组数据,输出一行,为一个 01 01 01 串,没有空格,如果有多组解,输出任意一个即可。
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:
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.
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.
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.
7
1 3 5
1 1 1
3 9 3
0 1 0
3 1 2
0 0 3
2 0 0
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; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。