# 蓝桥刷题------第八天

Namarie.. 2023-03-11 16:33:53

1.

``````#include <bits/stdc++.h>
using namespace std;
int main()
{
int t=1,sum=0;
for(int i=1;i<=20;i++){
sum+=t;
t*=2;
}
int gcd=__gcd(t,sum);
t/=gcd;
sum/=gcd;
printf("%d/%d",sum,t/2);
return 0;
}``````

2.

``````#include<bits/stdc++.h>
using namespace std;
int a[10];
int N;
int check(int n){
int mon=n%10*10+n%100/10;
int day=n/100%10*10+n/1000;
if(mon>12||mon<=0) return 0;
if(day>31||day<=0) return 0;
if(mon==4||mon==6||mon==9||mon==11){
if(day>30) return 0;
}
if(mon==2){
if((n%4==0&&n%100!=0)||n%400==0){
if(day>29) return 0;
}
else{
if(day>28) return 0;
}
}
return 1;
}
int huiwen(int n){
int i=0;
int n1=n;
while(n1!=0){
a[i]=n1%10;
i++;
n1/=10;
}
int hui=n*10000;
int x=1000;
for(int i=0;i<4;i++){
hui+=a[i]*x;
x/=10;
}
return hui;
}
int main(){
cin>>N;
int N1=N/10000;
while(1){
if(check(N1)&&huiwen(N1)>N){
cout<<huiwen(N1)<<endl;
break;
}
N1++;
}
int N2=N1/100;
while(1){
N1=N2*100+N2;
if(check(N1)&&huiwen(N1)>N){
cout<<huiwen(N1)<<endl;
break;
}
N2++;
}
return 0;
}``````

3.

``````#include <bits/stdc++.h>
using namespace std;
int d[2005][2005],n,m;
bool st[2005][2005];
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
void bfs() {
queue<array<int, 2>> q;
d[n][n]=0;
q.push({n, n});
while (q.size()) {
auto t=q.front();
q.pop();
if (st[t[0]][t[1]]) {
if (d[tt[0]][tt[1]]>d[t[0]][t[1]]+1) {
q.push({tt[0], tt[1]});
d[tt[0]][tt[1]]=d[t[0]][t[1]]+1;
}
}
}
for (int i=0;i<4;++i) {
int x=t[0]+dx[i],y=t[1]+dy[i];
if (x<1||x>n||y<1||y>n) {
continue;
}
if (d[x][y]>d[t[0]][t[1]]+1) {
q.push({x,y});
d[x][y]=d[t[0]][t[1]]+1;
}
}
}
}
int main() {
cin>>n>>m;
while (m--) {
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
st[x1][y1]=st[x2][y2]=true;
}
memset(d,0x3f,sizeof d);
bfs();
double res=0;
for (int i=1;i<=n;++i) {
for (int j=1;j<=n;++j) {
res+=d[i][j];
}
}
printf("%.2lf\n",res/(n*n));
return 0;
}``````

...全文
8 回复 打赏 收藏 转发到动态 举报

49,441

• 近7日
• 近30日
• 至今

刷题！