D47113 定制展示盘
-
思路:
我们可以思考一下,给的数小于4那就该输出4,因为展示盘的行数和每行的槽位数量都至少为2。如果是质数的话那凹槽总位是不是比那个质数大的最小偶数呢?但如果是合数就一定会有一个跟它容量一样的展示盘。所以代码如下。
-----------------------我是分割线----------------------- -
代码:
#include <bits/stdc++.h>
using namespace std;
int fun(int n){
if(n == 1 || n == 0) return 1;
for (int i = 2;i <= n / i;i ++){
if (n % i == 0) return 1;
}
return 0;
}
int main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t --){
long long n;
cin >> n;
if (n <= 4){
cout << 4 << '\n';
}else if (fun (n) == 0){
double c = 1.00 * n / 2;
int c1 = n / 2;
if (c > c1) c1 ++;
cout << c1 * 2 << '\n';
}else{
cout << n << '\n';
}
}
return 0;
} D47114 应试玉符
这道题我们就不多说了,按题目要求做即可。
-
代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t --){
string name, s;
cin >> name >> s;
if (name[0] != 'Z' || name[1] != 'J' || name[2] != '-'){
cout << "Wrong Name\n";
continue;
}
int cnt0 = 0, flag = 0 ,cnt1 = 0;
for (int i = 3;i < name.size();i ++){
if (flag == 0 && name[i] == '0'){
cnt0 ++;
}else{
flag = 1;
cnt1 ++;
}
}
if(name.size() != 7){
cout << "Wrong Name\n";
continue;
}
if (cnt0 == 0 || cnt0 == 1 || cnt0 == 2 || cnt0 == 3){
if (s.size() < 6){
cout << "Wrong Password\n";
continue;
}
int cntA = 0;
int cnta = 0;
int cntnum = 0;
for (int i = 0;i < s.size();i ++){
if (s[i] >= 'a' && s[i] <='z'){
cnta ++;
}else if (s[i] >= 'A' && s[i] <='Z'){
cntA ++;
}else{
cntnum ++;
}
}
if (cntA > 0 && cnta > 0 && cntnum > 0){
cout << "Accept\n";
}else{
cout << "Wrong Password\n";
}
}else{
cout << "Wrong Name\n";
}
}
return 0;
}
D47115 珊瑚海
这题是个简单的分类讨论,只需把所有情况考虑清楚即可。
-
代码:
C++ #include <bits/stdc++.h> using namespace std; int main(){ freopen("c.in","r",stdin); freopen("c.out","w",stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, d; cin >> n >> m >> d; long long cnt = n * (d + 1); if (cnt > m){ cout << -1; }else if (cnt == m){ cout << 0; }else{ m -= cnt; if (m <= n){ cout << m; }else{ cout << n + (m - n) / (d + 1); } } return 0; }