第二十八届欢乐赛题解来啦~
2024-08-26 13:21:00
发布于:江苏
马上开学了,在此先祝大家学业有成,门门进步!
上代码!
第一题
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
if(b <= a+c) cout <<"YES";
if(b > a+c) cout << "NO";
return 0;
}
第二题
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x,y,sum=0;
cin >> n;
for(int i=1; i<=n/2; i++){
cin >> x >> y;
sum += x;
}
if(n%2==1){
cin>>x;
sum += x;
}
cout << sum;
return 0;
}
第三题
#include<bits/stdc++.h>
using namespace std;
int main(){
char x;
int sum = 0;
for(int i = 1; i <= 7; i++){
cin >> x;
if(x =='R')
sum++;
}
cout << sum;
return 0;
}
第四题
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
int x, y, z;
int n;
cin >> a >> b >> c >> x >> y >> z >> n;
if(a*x + b*y + c*z <= n) cout << "YES";
if(a*x + b*y + c*z > n+50) cout << "NO";
if(a*x + b*y + c*z > n && a*x + b*y + c*z <= n+50)
cout << "V me 50" << endl << "YES";
return 0;
}
第五题
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch;
int n;
cin >> n >> ch;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cout << ch;
}
cout << endl;
}
return 0;
}
第六题
#include<bits/stdc++.h>
using namespace std;
int sp[105][105];
int fsp[105][105];
int main(){
int n;
cin >> n;
int cnt = 1;
for(int i = 1; i <= n; i++){
if(i%2==0){
for(int j = n; j >= 1; j--){
sp[i][j]=cnt;
cnt++;
}
}
else{
for(int j = 1; j <= n; j++){
sp[i][j] = cnt;
cnt++;
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
fsp[i][j] = sp[j][i];
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cout << fsp[i][j] << " ";
}
cout << endl;
}
}
第七题
#include<bits/stdc++.h>
using namespace std;
int n;
void print(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n-i;j++){
cout<<"*";
}
int p=n-1;
for(int j=1;j<=i;j++){
cout<<p;
p--;
}
p++;
for(int j=1;j<=i-1;j++){
p++;
cout<<p;
}
for(int j=1;j<=n-i;j++){
cout<<"*";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=n-i;j++){
cout<<"*";
}
int p=n-1;
for(int j=1;j<=i;j++){
cout<<p;
p--;
}
p++;
for(int j=1;j<=i-1;j++){
p++;
cout<<p;
}
for(int j=1;j<=n-i;j++){
cout<<"*";
}
cout<<endl;
}
}
int main(){
cin>>n;
print();
}
第八题
#include <bits/stdc++.h>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
bitset <1000005> vis;
vector <int> p;
void sieve(int n){
for(int i = 2; i * i <= n; i++){
if(!vis[i]){
for(int j = i << 1; j <= n; j += i){
vis[j] = 1;
}
}
}
for(int i = 2; i <= n; i++){
if(!vis[i]) p.push_back(i);
}
}
signed main(){
sieve(1000000);
int n;
cin >> n;
int ct = 0;
for(int i = 0; i < p.size() && p[i] * p[i] * p[i] <= n; i++){
for(int j = i + 1; j < p.size() && p[i] * p[i] * p[j] <= n; j++){
int l = 0, r = p.size() - 1, val = n / (p[i] * p[i] * p[j]);
if(p[j] * p[j] > val) break;
while(l <= r){
int mid = (l + r) >> 1;
if(p[mid] * p[mid] > val) r = mid - 1;
else l = mid + 1;
}
ct += r - j;
}
}
cout << ct;
return 0;
}
有任何不足大家都可以指出!
全部评论 1
正在裂开...
2024-08-28 来自 广东
0
有帮助,赞一个