A. Telephone Number
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.
You are given a string s of length n, consisting of digits.
In one operation you can delete any character from string s. For example, it is possible to obtain strings 112, 111 or 121 from string 1121.
You need to determine whether there is such a sequence of operations (possibly empty), after which the string s becomes a telephone number.
Input
The first line contains one integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤100) — the length of string s.
The second line of each test case contains the string s (|s|=n) consisting of digits.
Output
For each test print one line.
If there is a sequence of operations, after which s becomes a telephone number, print YES.
Otherwise, print NO.
Example
inputCopy
2
13
7818005553535
11
31415926535
outputCopy
YES
NO
Note
In the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535.
题意:定义一个数字串串为一个手机号当且仅当这个数字串以8开头并且长度为11,现在给出t组数据,每组数据给出一个数字串,询问这个数字串能否经过删除一些数字变成字符串
题解:只要从8出现的位置到末尾的长度>=11即可
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
char ch[105];
scanf("%s",ch+1);
int f=0;
for(int i=1;i<=n;i++){
if(ch[i]=='8'&&n-i+1>=11){
f=1;
break;
}
}
if(f)printf("YES\n");
else printf("NO\n");
}
return 0;
}
B. Lost Numbers
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.
The jury guessed some array a consisting of 6 integers. There are 6 special numbers — 4, 8, 15, 16, 23, 42 — and each of these numbers occurs in a exactly once (so, a is some permutation of these numbers).
You don’t know anything about their order, but you are allowed to ask up to 4 queries. In each query, you may choose two indices i and j (1≤i,j≤6, i and j are not necessarily distinct), and you will get the value of ai⋅aj in return.
Can you guess the array a?
The array a is fixed beforehand in each test, the interaction program doesn’t try to adapt to your queries.
Interaction
Before submitting the answer, you may ask up to 4 queries. To ask a query, print one line in the following format: ? i j, where i and j should be two integers such that 1≤i,j≤6. The line should be ended with a line break character. After submitting a query, flush the output and read the answer to your query — one line containing one integer ai⋅aj. If you submit an incorrect query (or ask more than 4 queries), the answer to it will be one string 0. After receiving such an answer, your program should terminate immediately — otherwise you may receive verdict “Runtime error”, “Time limit exceeded” or some other verdict instead of “Wrong answer”.
To give the answer, your program should print one line ! a1 a2 a3 a4 a5 a6 with a line break in the end. After that, it should flush the output and terminate gracefully.
Example
inputCopy
16
64
345
672
outputCopy
? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42
Note
If you want to submit a hack for this problem, your test should contain exactly six space-separated integers a1, a2, …, a6. Each of 6 special numbers should occur exactly once in the test. The test should be ended with a line break character.
题意:一道简单的交互题,只要会写交互格式即可。有6个数字4, 8, 15, 16, 23, 42的一个排列,要求你经过4次询问得出这个排列,询问格式为"? a b"得到a*b的值。第一次询问"? 1 2",第二次"? 1 3"即可得出a1,a2,a3的值,第三次询问"? 4 5",第四次询问"? 4 6"即可得出a4,a5,a6的值
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
int a[7]={
0,4, 8, 15, 16, 23, 42 };
int a1,a2,a3,a4,a5,a6;
int main(){
cout<<"? 1 2"<<endl;
fflush(stdout);
int x,y;
cin>>x;
cout<<"? 1 3"<<endl;
fflush(stdout);
cin>>y;
for(int i=1;i<=6;i++){
for(int j=1;j<=6;j++){
for(int k=1;k<=6;k++){
if((i!=j&&i!=k&&j!=k)&&(a[i]*a[j]==x&&a[i]*a[k]==y)){
a1=a[i];
a2=a[j];
a3=a[k];