文章目录
据说F是假题,就没看了。
牛客小白月赛103(打表、二进制、几何、思维)
A. 小冰的正多边形
根据题意,判断是否可以构成正三角形。如可以,答案取周长最小的正三角形的周长。
#include<bits/stdc++.h>
using namespace std;
int main(){
int ncase;
cin >> ncase;
while(ncase--){
int n;
cin >> n;
map<int, int> m;
int res = 1e9, x;
for(int i = 1; i <= n; i++){
cin >> x;
m[x]++;
if(m[x] == 3) res = min(res, 3 * x);
}
if(res == 1e9) cout << "no" << endl;
else{
cout << "yes" << endl;
cout << res << endl;
}
}
return 0;
}
B. 冰冰的电子邮箱
字符串处理,根据题意判断即可。
#include<bits/stdc++.h>
using namespace std;
int check_char(char c){
if(c >= 'a' && c <= 'z') return 1;
if(c >= 'A' && c <= 'Z') return 1;
if(c >= '0' && c <= '9') return 1;
return 0;
}
int main(){
int ncase;
cin >> ncase;
while(ncase--){
string s;
cin >> s;
string a, b;
int flag = 0;
for(auto c : s){
if(c == '@' && flag == 0) flag = 1;
else if(flag == 0) a += c;
else b += c;
}
int res = 1;
if(a.size() == 0 || a.size() > 64) res = 0;
for(int i = 0; i < a.size(); i++){
if(check_char(a[i]) == 0){
if(a[i] == '.'){
if(i == 0 || i+1 == a.size()) res = 0;
else continue;
}
else res = 0;
}
}
if(b.size() == 0 || b.size() > 255) res = 0;
for(int i = 0; i < b.size(); i++){
if(check_char(b[i]) == 0){
if(b[i] == '.' || b[i] == '-'){
if(i == 0 || i+1 == b.size()) res = 0;
else continue;
}
else res = 0;
}
}
cout << (res ? "Yes" : "No") << endl;
}
return 0;
}
C. 冰冰的异或(打表、二进制)
观察输入 n 的范围,单次查询需要在O(1) 或 O(log(n)) 的时间内,打表观察规律, r e s = 2 ⌈ l o g ( n ) ⌉ , n > 2 res = 2^{\lceil {log(n)} \rceil}, n > 2 res=2⌈log(n)⌉,n>2。
PS:这里的打表,即暴力枚举对于每一个 n,观察 n 与其对应的答案的规律。
对于规律的证明:
对于 4 为二进制,取X = 1000,设 Y = 0ABC, ABC为任意的01,此时,可以得到 [ 100 0 2 , 111 1 2 ] [1000_2, 1111_2] [10002,11112] 之间的所有数。
取X = 0100,设 Y = 00BC, BC为任意的01,此时,可以得到 [ 010 0 2 , 011 1 2 ] [0100_2, 0111_2] [01002,01112] 之间的所有数。
取X = 0010,设 Y = 000C, C为任意的01,此时,可以得到 [ 001 0 2 , 001 1 2 ] [0010_2, 0011_2] [00102,00112] 之间的所有数。
取X = 0001,设 Y = 0000, C为任意的01,此时,可以得到 [ 000 1 2 , 000 1 2 ] [0001_2, 0001_2] [00012,00012] 之间的所有数。
根据题意,Y ≠ 0,故而,上述四种情况中,需要排除左端点 100 0 2 、 010 0 2 、 001 0 2 、 000 1 2 1000_2、0100_2、0010_2、0001_2 10002、01002、00102、00012 。即,除这四个数外,其他数都可以被覆盖。
考虑覆盖这四个数:
即, 001