2021 ICPC网络赛 第二场 G/J

博客内容涉及两道编程题目,GLimit是关于求导的动态规划问题,使用暴力求解并处理奇偶项。JLeakingRoof是模拟水流的网格问题,通过BFS模拟雨水从高处流向低处的过程。两个问题都展示了动态规划和模拟在解决复杂问题中的应用。
摘要由CSDN通过智能技术生成

PAT题单


目录

G Limit

J Leaking Roof

总结:


G Limit

题意:

求导。

思路:

t<=5,直接暴力。

题解:

#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef  long long int  LL;
using namespace std;
LL n,t;
LL a[bbn],b[bbn];
LL dt[6];
LL q[6]= {1,1,2,6,24,120};
LL gcd(LL a,LL b)
{
    return b!=0?gcd(b,a%b):a;
}
int main()
{
    cin>>n>>t;
    for(LL i=1; i<=n; i++)
    {
        cin>>a[i]>>b[i];
    }
    for(LL i=1; i<=5; i++)
    {
        for(LL j=1; j<=n; j++)
        {
            dt[i]+=q[i-1]*a[j]*pow(b[j],i);
        }
        if(i%2==0)
        {
            dt[i]*=-1;
        }
    }

    bool judge=1;
    for(LL i=1; i<=t-1; i++)
    {
        if(dt[i]!=0)
        {
            judge=0;
            break;
        }
    }
    if(judge)
    {
        if(dt[t]%q[t]==0)
        {
            printf("%lld",dt[t]/q[t]);
        }
        else
        {
            LL k=gcd(dt[t],q[t]);
            printf("%lld/%lld",dt[t]/k,q[t]/k);
        }
    }
    else
    {
        printf("infinity");
    }

    return 0;
}

J Leaking Roof

题意:

n*n的房顶(方格网),每个方格上有m毫升的雨,雨从高处到低处(相等时不会动),流到 h = 0 时,泄露下来。

给了每个方格的高度。

输出一段时间之后的方格网雨量。

思路:

遍历每一个点,对每一个点bfs(bfs和dfs好像混用了)。

模拟流水的过程和分配。

不用记录,反正只能从高处到低处。

用cout会出错...

题解:

#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef  long long int  LL;
using namespace std;
int n;
double m;
int h[501][501];
double store[501][501];
int xx[4]= {1,-1,0,0};
int yy[4]= {0,0,1,-1};
struct p
{
    int x,y;
};
void bfs(double s,int x,int y)
{
    if(h[x][y]==0)
    {
        store[x][y]+=s;
        return ;
    }
    queue<p>q;
    int cnt=0;
    for(int i=0; i<=3; i++)
    {
        int dx=x+xx[i];
        int dy=y+yy[i];
        if(1<=dx&&dx<=n&&1<=dy&&dy<=n)
        {
            if(h[x][y]>h[dx][dy])
            {
                cnt++;
                q.push({dx,dy});
            }
        }
    }
    while(!q.empty())
    {
        bfs(s/(double)cnt,q.front().x,q.front().y);
        q.pop();
    }
    return;
}
void print()
{
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            printf("%lf ",store[i][j]);
            //cout<<store[i][j]<<" ";
        }
        cout<<'\n';
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>h[i][j];
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            bfs(m,i,j);
           // cout<<"::"<<i<<"::"<<j<<'\n';
          //  print();
        }
    }
    print();
    return 0;
}

总结:

参赛资格都没有,呜呜呜...


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值