【思特奇杯·云上蓝桥-算法集训营】第二周

1.带分数

#include<iostream>
using namespace std;
const int M = 9;
int n,ans,a[M+5];
void swap(int x,int y){int t=a[x];a[x]=a[y];a[y]=t;}
int pow(int x,int y){if(!y)return 1;return x*pow(x,y-1);}
void sort(int x,int y){
    for(int i=x;i<y;i++)
        for(int j=i+1;j<=y;j++)
            if(a[i]>a[j])swap(i,j);
}
void ask(){
    int x=0,y=0;
    for(int i=1;i<=M;i++)y = y*10+a[i];
    for(int i=1;i<M-1;i++){
        x = x*10+a[i];
        if(x>=n)break;
        int t = y%pow(10,M-i);
        int z = 0;
        for(int j=M-1;j>i;j--){
            t /= 10;
            z = z*10+a[j+1];
            if(t<z)break;
            if(t%z)continue;
            if(x + t/z == n){
                //cout<<x<<'+'<<t<<'/'<<z<<endl;
                //for(int T=1;T<=M;T++)cout<<a[T];cout<<endl;
                ans++;
                break;
            }
        }
    }//闅旀澘娉?
    return;
}
void Search(){
    ask();
    //for(int i=1;i<=M;i++)cout<<a[i];cout<<endl;
    for(int i=M-1;i>0;i--)if(a[i]<a[i+1]){
        for(int j=M;j>i;j--)if(a[i]<a[j]){
            swap(i,j);
            sort(i+1,M);
            Search();
            return;
        }
    }
    return;
}
int main(){
    for(int i=1;i<=M;i++)a[i]=i;
    cin>>n;
    Search();
    cout<<ans;
    return 0;
}

2.李白打酒

#include<iostream>
using namespace std;
int dp(int a,int b,int n){
    if(!a&&b==n)return 1;
    if(n==0||b==0)return 0;
    int t=0;
    if(a)t+=dp(a-1,b,n*2);
    if(b)t+=dp(a,b-1,n-1);
    return t;
}
int main(){
    cout<<dp(5,10,2);
    return 0;
}

3.第三十九级台阶

#include<iostream>
using namespace std;
int dp[40][2];
int search(int a,bool b){    //a涓哄彴闃舵暟,b涓哄乏鍙宠剼
    if(dp[a][b]||a<2)return dp[a][b];
    return dp[a][b] = search(a-1,b^1) + search(a-2,b^1);
}
int main(){
    dp[1][0]=d[2][0]=1;
    cout << search(39,1);
    return 0;
}

4.跨越雷区

#include<iostream>
#include<queue>
using namespace std;
const int M = 100;
const int INF = 99999;
const int X[4] = {-1,0,1,0};
const int Y[4] = {0,-1,0,1};
int n;
int endx,endy;
char ch[M+5][M+5];
int a[M+5][M+5];
struct Coordinate{
    int x,y;
    Coordinate(int x,int y):x(x),y(y){}
};
queue<Coordinate>q;
void bfs(){
    Coordinate t = q.front();
    q.pop();
    //cout<<t.x<<' '<<t.y<<endl;
    for(int i=0;i<4;i++){
        int tx = t.x + X[i] , ty = t.y + Y[i];
        if(tx<1||ty<1||tx>n||ty>n||a[tx][ty]||ch[tx][ty]==ch[t.x][t.y])continue;
        q.push(Coordinate(tx,ty));
        a[tx][ty] = a[t.x][t.y] + 1;
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
        cin>>ch[i][j];
        if(ch[i][j]=='A'){
            q.push(Coordinate(i,j));
            a[i][j]=1;
        }
        if(ch[i][j]=='B')endx = i,endy = j;
    }
    while(!q.empty())bfs();
    cout << a[endx][endy]-1;
    return 0;
}

5.迷宫

#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
const int X[4] = {1,0,0,-1};
const int Y[4] = {0,-1,1,0};
const string S[4] = {"D","L","R","U"};
bool a[31][51];
struct Coordinate{
    int x,y;
    string s;
    Coordinate(int x,int y,string s):x(x),y(y),s(s){}
};
queue<Coordinate> q;
void bfs(){
    Coordinate t = q.front();
    q.pop();
    for(int i=0;i<4;i++){
        int tx = t.x + X[i];
        int ty = t.y + Y[i];
        if(tx<1||tx>30||ty<1||ty>50||a[tx][ty])continue;
        string ts = t.s + S[i];
        if(tx==30&&ty==50){
            while(!q.empty())q.pop();
            cout<<ts;
            return;
        }
        a[tx][ty]=true;
        q.push(Coordinate(tx,ty,ts));
    }
}
int main(){
    for(int i=1;i<=30;i++)for(int j=1;j<=50;j++){
        char ch;
        cin>>ch;
        a[i][j] = (ch=='1');
    }
    q.push(Coordinate(1,1,""));
    while(!q.empty())bfs();
    return 0;
}

6.跳马

#include<iostream>
#include<queue>
using namespace std;
const int X[8] = {-2,-2,-1,-1,1,1,2,2};
const int Y[8] = {-1,1,-2,2,-2,2,-1,1};
int board[9][9];
struct Coordinate{
    int x,y,p;
    Coordinate(int x,int y,int p):x(x),y(y),p(p){}
};
queue<Coordinate> q;
void bfs(){
    Coordinate t = q.front();
    q.pop();
    for(int i=0;i<8;i++){
        int tx = t.x + X[i];
        int ty = t.y + Y[i];
        if(tx<1||tx>8||ty<1||ty>8||board[tx][ty])continue;
        board[tx][ty] = t.p + 1;
        q.push(Coordinate(tx,ty,board[tx][ty]));
    }
}
int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    board[x1][y1] = 1;
    q.push(Coordinate(x1,y1,1));
    bfs();
    cout<<board[x2][y2]-1<<endl;
    return 0;
}
7.路径之谜

#include<iostream>
using namespace std;
const int X[4] = {1,-1,0,0};
const int Y[4] = {0,0,1,-1};
int n,a[21],b[21];
bool bo[21][21];
int st[401],p=0;        //鎵嬪姩妯℃嫙鏍?<stack>搴撹兘涓嶇敤灏变笉鐢?
bool dfs(int x,int y){
    if(!a[y]||!b[x])return false;
    a[y]--,b[x]--;
    if(x==n&&y==n){
        bool bo = true;
        for(int i=1;i<=n;i++)if(a[i]||b[i])bo = false;
        if(bo){
            st[p++] = (x-1)*n+y-1;
            return true;
        }
    }
    for(int i=0;i<4;i++){
        int tx = x + X[i];
        int ty = y + Y[i];
        if(tx<1||tx>n||ty<1||ty>n)continue;
        if(dfs(tx,ty)){
            st[p++] = (x-1)*n+y-1;
            return true;
        }
    }
    a[y]++,b[x]++;
    return false;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    dfs(1,1);
    cout<<0;
    for(int i=p-2;i>=0;i--)cout<<' '<<st[i];
    return 0;
}

8.未名湖边的烦恼

#include<iostream>
using namespace std;
int m,n,p;            //p琛ㄧず姝ゆ椂杩樺墿澶氬皯鍐伴瀷
int dfs(int x){        //x琛ㄧず杩樺墿澶氬皯浜?
    if(!m)return 1;
    int t=0;
    if(m){
        m--,p++;
        t += dfs(x-1);
        m++,p--;
    }
    if(n&&p){
        n--,p--;
        t += dfs(x-1);
        n++,p++;
    }
    return t;
}
int main(){
    cin>>m>>n;
    cout<< ((m<n)?0:dfs(m+n));
    return 0;
}

9.大臣的旅费

//ps:姝ら鐢╠fs绠楁硶鍙兘鍦∣nlineJudge涓婂緱60鍒?瓒呮椂)
//   浣嗕簨瀹炰笂搴旇婊¤冻浜嗙幇闃舵鐨勯渶姹?
//   寤鸿鐢ㄦ爲鐨勬€濈淮鍘昏В鍐?绗旇€呰刀鏃堕棿,涓嶅啓婊″垎瑙d簡
#include<iostream>
#include<vector>
using namespace std;
const int M = 900000;
int max(int x,int y){return x<y?y:x;}
int n,ans;
struct DOUBLE{
    int x;
    int y;
    DOUBLE(int x,int y):x(x),y(y){}
};
vector<DOUBLE> v[M+1];
bool bo[M+1];
int dfs(int x){
    bo[x] = true;
    int t = 0;
    for(int i=0;i<v[x].capacity();i++){
        if(bo[v[x][i].x])continue;
        t = max(t,v[x][i].y + dfs(v[x][i].x));
    }
    bo[x] = false;
    return t;
}
int main(){
    cin>>n;
    for(int i=1;i<n;i++){
        int x,y,z;
        cin>>x>>y>>z;
        v[x].push_back(DOUBLE(y,z));
        v[y].push_back(DOUBLE(x,z));
    }
    for(int i=1;i<=n;i++)if(v[i].capacity()==1)ans=max(ans,dfs(i));
    cout<< ans*(ans+21)/2;
    return 0;
}

10.皇后问题

//杩欐槸浠庣綉涓婃憳鐨勪唬鐮?
#include<cstdio>
#include<cstring>
int a[9][9],vis1[9],vis2[9],cnt,n;
int x1[19],x2[19],y1[19],y2[19];
void DFS(int dep)
{
    if(dep==n+1) { cnt++; return ;}
    for(int i=1;i<=n;i++)
    {
        if(!vis1[i] && a[dep][i] && !x1[dep+i] && !y1[dep-i+n])
        {
            vis1[i]=1; a[dep][i]=0; x1[dep+i]=1; y1[dep-i+n]=1;
            for(int j=1;j<=n;j++)
            {
                if(!vis2[j] && a[dep][j] && !x2[dep+j] && !y2[dep-j+n])
                {
                    vis2[j]=1;a[dep][j]=0; x2[dep+j]=1; y2[dep-j+n]=1;
                    DFS(dep+1);
                    vis2[j]=0;a[dep][j]=1; x2[dep+j]=0; y2[dep-j+n]=0;
                }
            }
            vis1[i]=0; a[dep][i]=1; x1[dep+i]=0; y1[dep-i+n]=0;
        }
    }
}
int main(void)
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            scanf("%d",&a[i][j]);
    DFS(1);
    printf("%d",cnt);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 思特威(Datasheet)是一种技术文档,其主要目的是提供有关特定产品或设备的技术规格和详细信息。通过阅读思特威,用户可以了解该产品的功能、性能、尺寸、接口和电气特性等重要信息。 在思特威中,常见的内容包括产品的规格参数、功能特点、性能指标、工作条件、接口定义、电器特性、示意图以及连接示例等。这些信息对于开发人员、工程师、以及产品消费者都非常重要。工程师们可以利用思特威来了解和评估产品是否满足其需求和规格要求。消费者则可以通过思特威了解产品的功能和性能,以便做出购买决策。 思特威通常以简洁且易读的方式呈现,使用技术术语和图表来提供必要的信息。一份完整的思特威应该包括产品的物理尺寸和重量、工作电压和功率要求、接口类型和规格、传输速率、最大传输距离、环境工作温度范围、支持的协议标准等。 对于技术人员来说,思特威是他们在设计和开发产品时的重要参考资料。通过对Datasheet进行仔细研究,他们可以更好地了解产品的特性和限制,从而能够做出更好的设计决策。同时,思特威还可以作为售后服务的重要参考,提供产品的详细规格和性能信息,以便用户能够更好地了解和操作产品。 总而言之,思特威是一份技术文档,旨在提供关于特定产品的详细规格和技术信息。通过阅读思特威,用户可以全面了解产品的功能、性能和特性,以及使用该产品时的限制和条件。 ### 回答2: 思特威 datasheet 是指思特威公司产品的技术规格表。该规格表提供了关于该产品的详细信息,包括但不限于产品的规格、性能参数、接口配置、功能特点等。 在思特威 datasheet 中,首先会列出产品的基本信息,例如产品名称、型号以及适用范围等。接下来,会详细介绍产品的物理外观和尺寸,以及各个接口的类型和数量。这些信息对于用户来说非常重要,可以帮助他们了解产品的大小和适应性。 此外,datasheet中还会列出产品的性能参数,包括但不限于传输速率、工作温度范围、功耗、电压要求等。这些参数对用户来说也是至关重要的,可以帮助他们确定产品是否符合其需求。 在datasheet中,还会详细描述产品的功能特点和技术规格。例如,如果是一款网络设备,会介绍其支持的网络标准、安全功能、管理方式等。通过这些介绍,用户可以更好地了解产品的性能和功能,从而更好地评估其是否适合自己的应用场景。 综上所述,思特威 datasheet 是一份非常重要的技术规格表,提供了关于该产品的详细信息。通过阅读和理解该规格表,用户可以更好地了解产品的性能、功能和适用性,从而做出正确的购买和使用决策。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fine282

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值