Codeforces Round #356 (Div. 1) 题解(待补)

本文解析了Codeforces上几道竞赛题目,包括质数判断、塔的体积最大化、网格最大连通块及追击游戏的概率计算。通过算法和数据结构解决实际问题,并提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bear and Prime 100

This is an interactive problem. In the output section below you will see the information about flushing the output.

Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.

Integer x > 1 is called prime if it has exactly two distinct divisors, 1 and x. If integer x > 1 is not prime, it’s called composite.

You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2, 100]. The system will answer “yes” if your integer is a divisor of the hidden number. Otherwise, the answer will be “no”.

For example, if the hidden number is 14 then the system will answer “yes” only if you print 2, 7 or 14.

When you are done asking queries, print “prime” or “composite” and terminate your program.

You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2, 100]. Also, you will get the Wrong Answer verdict if the printed answer isn’t correct.

You will get the Idleness Limit Exceeded verdict if you don’t print anything (but you should) or if you forget about flushing the output (more info below).
第一次做交互题。
100以内有25个质数,所以考虑合数,100以内的一个数是合数当且仅当它为2,3,5,7的倍数。

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (100+10)
int p[MAXN],tot;
bool b[MAXN]={0};
void make_prime(int n)
{
    tot=0; 
    Fork(i,2,n)
    {
        if (!b[i]) p[++tot]=i;
        For(j,tot)
        {
            if (i*p[j]>n) break;
            b[i*p[j]]=1;
            if (i%p[j]==0) {
                break;
            }  
        }
    }
}
int main()
{
//  freopen("A.in","r",stdin);
//  freopen(".out","w",stdout);
    make_prime(100);
//  For(i,tot) cout<<p[i]<<' ';

//  cout<<tot<<endl;

    bool flag=0;
    For(i,4) {
        cout<<p[i]<<endl;
        fflush(stdout);

        char response[10];
        scanf("%s", response);
        if (strcmp(response, "no") == 0) continue;
        bool flag=0;
        For(j,tot) {
            if (p[i]*p[j]>100) break;
            printf("%d\n", p[i]*p[j]);
            fflush(stdout);

            char response[10];
            scanf("%s", response);
            if (strcmp(response, "no") == 0) continue;
            else {
                puts("composite");fflush(stdout); return 0;
            }
        }    
        puts("prime");fflush(stdout);    return 0;
    }
    puts("prime"); fflush(stdout);   return 0;



    return 0;
}

Bear and Tower of Cubes

Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.

A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, …, ak has the total volume a13 + a23 + … + ak3.

Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn’t exceed X.

Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.

Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
1 ≤ m ≤ 10^15

对于1个X,要么取最大的v[x],要么取次大的v[x-1],再小的一定不优
官方证明http://codeforces.com/blog/entry/45310

Bear and Square Grid

给一个n*n的矩阵,有一些地方是障碍,你可以移除一个k*k的子矩阵的所有障碍,问之后的最大连通块大小。
n<=500
枚举k*k的子矩阵位置,每次向一个方向移一格,暴力处理相邻4k个方格的连通块,
复杂度 O(nk(k+n))

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (510)
int n,k;
int a[MAXN][MAXN],c_sz[MAXN*MAXN]={0},c[MAXN][MAXN]={0};
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int mark[MAXN*MAXN]={0};
bool inside(int x,int y) {
    return 0<min(x,y)&&max(x,y)<=n;
}
void dfs(int x,int y,int col) {
    c[x][y]=col;
    c_sz[col]++;
    Rep(di,4) {
        int nx=x+dir[di][0],ny=y+dir[di][1];
        if (inside(nx,ny)&&a[nx][ny]&&!c[nx][ny]) dfs(nx,ny,col);
    }
}
void modi(int x,int y,int t,int &ans) {
    int id=c[x][y];
//  cout<<x<<' '<<y<<endl;
    if (!inside(x,y)||!a[x][y]) return;

    if (mark[id]!=t) {
        mark[id]=t;
        ans+=c_sz[id];
    }
}
int main()
{
//  freopen("C.in","r",stdin);
//  freopen(".out","w",stdout);

    cin>>n>>k;
    For(i,n) {
        char s[MAXN];
        cin>>(s+1);
        For(j,n) a[i][j]=(s[j]=='.');
    }
    int tot=0;
    For(i,n) For(j,n) if (a[i][j]&&c[i][j]==0) {
        dfs(i,j,++tot);
    } 

    int bestans=0,cur_time=1;
    For(i,n-k+1) {

        Fork(x,i,i+k-1)
            For(y,k) {
                if (c[x][y]) --c_sz[c[x][y]];
            }

        For(j,n-k+1) {
            int ans=0;
            For(l,k) {
                modi(i-1,j+l-1,cur_time,ans);
                modi(i+k,j+l-1,cur_time,ans);
                modi(i+l-1,j-1,cur_time,ans);
                modi(i+l-1,j+k,cur_time,ans);
            }   
            bestans=max(bestans,ans);       
            ++cur_time;

            if (j<n-k+1)
                For(l,k) {
                    if (c[i+l-1][j]) ++c_sz[c[i+l-1][j]];
                    if (c[i+l-1][j+k]) --c_sz[c[i+l-1][j+k]];
                }   
        }

        Fork(x,i,i+k-1)
            Fork(y,n-k+1,n) {
                if (c[x][y]) ++c_sz[c[x][y]];
            }

    }
    cout<<bestans+k*k<<endl;

    return 0;
}

Bear and Chase

算清楚概率 O(n3) 暴力
假设从g1出发到距离为d的点,明天要考虑的只有距离为d-1,d,d+1的,
对每个g1来说1个点最多考虑3次
其实还是要算清楚概率
PS:Tutorial http://codeforces.com/blog/entry/45310
官解写的略诡异看不出来,后来自己写了一遍发现式子一样。。。

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (410)
vi edges[MAXN];
int n,m,f[MAXN][MAXN];
double pro[MAXN],pro_dis[MAXN];
bool b[MAXN];
double calc(int g1,int d1,int cnt) {
    MEM(pro) MEM(b) MEM(pro_dis)
    vi visit_point;
    For(i,n) if (f[g1][i]==d1) {
        int sz=SI(edges[i]);
        Rep(j,sz) {
            int v=edges[i][j];
            pro[v]+=1./cnt/sz;
            if (!b[v]) b[v]=1,visit_point.pb(v);
        }
    }
    // which city use BGDS tomorrow
    double ans=0;
    For(i,n) {
        int sz=SI(visit_point);
        Rep(j,sz) {
            int v=visit_point[j];
            pro_dis[f[i][v]] =max(pro_dis[f[i][v]],pro[v]);
        }
        double an=0;
        Rep(j,sz) {
            int v=visit_point[j];
            an+=pro_dis[f[i][v]]; 
            pro_dis[f[i][v]]=0;
        }
        ans=max(ans,an);
    }
    return ans;

}
int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>n>>m;
    MEMI(f)
    For(i,n) f[i][i]=0;
    For(i,m) {
        int a=read(),b=read();
        f[a][b]=f[b][a]=min(f[a][b],1);
        edges[a].pb(b);
        edges[b].pb(a);
    }
    For(k,n) For(i,n) For(j,n) if (f[i][k]!=INF&&f[k][j]!=INF)
        f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
    double ans=0;
    For(i,n) {
        double nowans=0;
        Rep(d,n+1) {
            int cnt=0;
            For(j,n) if (f[i][j]==d) ++cnt;
            if (!cnt) continue;
            double p=(double)cnt/n;
            // wait tomorrow
            double t=calc(i,d,cnt);
            nowans+=p*max(t,1./cnt);
        }
        ans=max(ans,nowans);
    }
    printf("%.12lf\n",ans);
    return 0;
}
标题基于SpringBoot+Vue的社区便民服务平台研究AI更换标题第1章引言介绍社区便民服务平台的研究背景、意义,以及基于SpringBoot+Vue技术的研究现状和创新点。1.1研究背景与意义分析社区便民服务的重要性,以及SpringBoot+Vue技术在平台建设中的优势。1.2国内外研究现状概述国内外在社区便民服务平台方面的发展现状。1.3研究方法与创新点阐述本文采用的研究方法和在SpringBoot+Vue技术应用上的创新之处。第2章相关理论介绍SpringBoot和Vue的相关理论基础,以及它们在社区便民服务平台中的应用。2.1SpringBoot技术概述解释SpringBoot的基本概念、特点及其在便民服务平台中的应用价值。2.2Vue技术概述阐述Vue的核心思想、技术特性及其在前端界面开发中的优势。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue如何有效整合,以提升社区便民服务平台的性能。第3章平台需求分析与设计分析社区便民服务平台的需求,并基于SpringBoot+Vue技术进行平台设计。3.1需求分析明确平台需满足的功能需求和性能需求。3.2架构设计设计平台的整体架构,包括前后端分离、模块化设计等思想。3.3数据库设计根据平台需求设计合理的数据库结构,包括数据表、字段等。第4章平台实现与关键技术详细阐述基于SpringBoot+Vue的社区便民服务平台的实现过程及关键技术。4.1后端服务实现使用SpringBoot实现后端服务,包括用户管理、服务管理等核心功能。4.2前端界面实现采用Vue技术实现前端界面,提供友好的用户交互体验。4.3前后端交互技术探讨前后端数据交互的方式,如RESTful API、WebSocket等。第5章平台测试与优化对实现的社区便民服务平台进行全面测试,并针对问题进行优化。5.1测试环境与工具介绍测试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值