补题 2019陕西省赛

博主分享比赛解题经历,一人写七八个小时未完成,补了五题。包括简单题、找规律题、需二分答案加最短路的题、类似计算几何求切点的题,以及对差值进行dp的题,还提及部分题的错误思路和正确解法。

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

真的很难想象这个是我打过的比赛,好难啊,我一个人写了七八个小时,还没有写完,主要是我的代码出现了一些思想性的错误,

而且自己还没有意识到,很郁闷。

 

就补了五个题目。

第一个很简单的题目,随便写写就好了

https://nanti.jisuanke.com/t/39268

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 6e3 + 10;
int a[maxn];
int dp[maxn];
int main()
{
    int n, v;
    scanf("%d%d", &n, &v);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i=1;i<=n;i++)
    {
        for(int j=v;j>=a[i];j--)
        {
            dp[j] = max(dp[j], dp[j - a[i]]+1);
        }
    }
    printf("%d\n", dp[v]);
    return 0;
}
背包or贪心

 

第二个就是一个找规律题目,可以打表找,不过我不会。

https://nanti.jisuanke.com/t/39279

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 6e3 + 10;
int main()
{
    int n, x;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &x);
    if (n == 1) printf("1\n");
    else if (n == 3) printf("6\n");
    else if(n%2==0)
    {
        if ((n/2)%2 == 0) printf("4\n");
        else printf("%d\n", n);
    }
    else
    {
        if ((n / 2) % 2 == 1) printf("12\n");
        else printf("%d\n", n * 2);
    }
    return 0;
}
打表找规律

 

第三个就是一个最短路

我之前用最短路的思想去写,但是wa了,一直wa,因为思想错了。

这个应该是二分答案+最短路,二分答案之后就很简单了,因为升级次数确定了。

https://nanti.jisuanke.com/t/39280

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#define pi acos(-1)
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
int n, m;
int a[maxn];
struct node
{
    int v;
    ll dist;
    node(int v=0,ll dist=0):v(v),dist(dist){}
};

struct heapnode
{
    int u;
    ll d;
    heapnode(int u=0,ll d=0):u(u),d(d){}
    bool operator<(const heapnode &a)const
    {
        return a.d < d;
    }
};

vector<node>vec[maxn];
ll d[maxn];
bool vis[maxn];

void dij(int s,ll l)
{
    priority_queue<heapnode>que;
    memset(d, inf, sizeof(d));
    memset(vis, 0, sizeof(vis));
    d[s] = 0;
    que.push(heapnode(s, 0));
    while(!que.empty())
    {
        heapnode x = que.top(); que.pop();
        int u = x.u;
        if (vis[u]) continue;
        vis[u] = 1;
        int len = vec[u].size();
        for(int i=0;i<len;i++)
        {
            node e = vec[u][i];
            if(d[u]+1<d[e.v]&&e.dist<=l)
            {
                d[e.v] = d[u] + 1;
                que.push(heapnode(e.v, d[e.v]));
            }
        }
    }
}

bool ok(ll l,ll num)
{
    dij(1, l);
    if (d[n] > num) return false;
    return true;
}

int main()
{
    int num, cost, dis;
    scanf("%d%d", &n, &m);
    scanf("%d%d%d", &cost, &dis, &num);
    for(int i=1;i<=m;i++)
    {
        int u, v;
        ll w;
        scanf("%d%d%lld", &u, &v, &w);
        vec[u].push_back(node(v, w));
        vec[v].push_back(node(u, w));
    }
    int l = 0, r = 1e5 + 10;
    while(l<r)
    {
        int mid = (l + r) >> 1;
        if (ok(mid*1ll*dis,mid*1ll*num)) r = mid;
        else l = mid + 1;
    }
    printf("%lld\n", r*1ll*cost);
    return 0;
}
二分答案+最短路

 

第四个就是一个有点像计算几何的题目

https://nanti.jisuanke.com/t/39270

但是呢,实质就是求切点,这个切点需要你推公式。

这个公式还是很好推的,但是细节需要注意,比如说这个有a等于0的情况(这个基于我自己的写法)

但是呢,这个题目的写法很多。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#define pi acos(-1)
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;

double dis(double sx, double sy, double gx, double gy) {
    double ans = (sx - gx)*(sx - gx) + (sy - gy)*(sy - gy);
    return ans;
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        double rx, ry, r, sx, sy;
        scanf("%lf%lf%lf%lf%lf", &rx, &ry, &r, &sx, &sy);
        double circle = 2 * pi*r / 4;
        if (sx >= rx + r) {
            double d = sqrt(dis(rx + r, ry, sx, sy));
            printf("%.4lf\n", d + circle);
        }
        else if (sx <= rx - r) {
            double d = sqrt(dis(rx - r, ry, sx, sy));
            printf("%.4lf\n", d + circle);
        }
        else {
            double a = (ry - sy)*(ry - sy) - r * r;
            double b = -(ry - sy)*(ry - sy) * 2 * rx + 2 * r*r*sx;
            double c = (ry - sy)*(ry - sy)*(rx*rx - r * r) - r * r*sx*sx;
            //    printf("%lf %lf %lf\n", a, b, c);
            double ex = sqrt(b*b - 4 * a*c);
            double x1, x2, x;
            if (a != 0) {
                x1 = (-b - ex) / (2 * a);
                x2 = (-b + ex) / (2 * a);
                x = min(fabs(rx - x1), fabs(rx - x2));
            }
            else x = fabs(rx + c / b);
            double ans = fabs(acos(r / x));
            //    printf("%lf\n", ans);
            double l = ans * r;
            double tx = sqrt(dis(sx, sy, rx, ry));
            double len = sqrt(tx*tx - r * r);
            printf("%.4lf\n", l + circle + len);
        }
    }
    return 0;
}
数学计算几何or自己手推公式

 

第五个就是一个dp

https://nanti.jisuanke.com/t/39271

先对这个东西进行分组,分组之后不可以用分组的思想去写,因为分组是至少选一个或者至多选一个。

这个想法我觉得我挺难想到的,这个是对差值进行dp。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#define pi acos(-1)
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[210];
int dp[220][maxn];
int sum1, sum2;
bool vis[210];
vector<int>vec[210];

void dfs(int s, int flag) {
    if (flag) sum1 += a[s];
    else sum2 += a[s];
    for (int i = 0; i < vec[s].size(); i++) {
        int u = vec[s][i];
        if (vis[u]) continue;
        vis[u] = 1;
        dfs(u, !flag);
    }
}
vector<int>v;
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n, m, sum = 0;
        scanf("%d%d", &n, &m);
        memset(vis, 0, sizeof(vis));
        for (int i = 0; i <= n + m; i++) {
            vec[i].clear();
        }
        v.clear();
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            a[i] /= 100;
            sum += a[i];
        }
        for (int i = 1; i <= m; i++) {
            int u, v;
            scanf("%d%d", &u, &v);
            vec[u].push_back(v);
            vec[v].push_back(u);
        }
        for (int i = 1; i <= n; i++) {
            if (vis[i]) continue;
            vis[i] = 1;
            sum1 = sum2 = 0;
            dfs(i, 0);
            v.push_back(abs(sum1 - sum2));
        }
        memset(dp, 0, sizeof(dp));
        dp[0][v[0]] = 1;
        for(int i=1;i<v.size();i++)
        {
            for(int j=0;j<=sum;j++)
            {
                if (dp[i - 1][j]) dp[i][abs(j - v[i])] = dp[i][abs(j + v[i])] = 1;
            }
        }
        int ans = 0;
        for(int i=0;i<=sum;i++)
        {
            if(dp[v.size()-1][i])
            {
                ans = (sum + i)*100 / 2;
                break;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
差值进行dp

 

转载于:https://www.cnblogs.com/EchoZQN/p/10932005.html

内容概要:本文详细探讨了基于MATLAB/SIMULINK的多载波无线通信系统仿真及性能分析,重点研究了以OFDM为代表的多载波技术。文章首先介绍了OFDM的基本原理和系统组成,随后通过仿真平台分析了不同调制方式的抗干扰性能、信道估计算法对系统性能的影响以及同步技术的实现与分析。文中提供了详细的MATLAB代码实现,涵盖OFDM系统的基本仿真、信道估计算法比较、同步算法实现和不同调制方式的性能比较。此外,还讨论了信道特征、OFDM关键技术、信道估计、同步技术和系统级仿真架构,并提出了未来的改进方向,如深度学习增强、混合波形设计和硬件加速方案。; 适合人群:具备无线通信基础知识,尤其是对OFDM技术有一定了解的研究人员和技术人员;从事无线通信系统设计与开发的工程师;高校通信工程专业的高年级本科生和研究生。; 使用场景及目标:①理解OFDM系统的工作原理及其在多径信道环境下的性能表现;②掌握MATLAB/SIMULINK在无线通信系统仿真中的应用;③评估不同调制方式、信道估计算法和同步算法的优劣;④为实际OFDM系统的设计和优化提供理论依据和技术支持。; 其他说明:本文不仅提供了详细的理论分析,还附带了大量的MATLAB代码示例,便于读者动手实践。建议读者在学习过程中结合代码进行调试和实验,以加深对OFDM技术的理解。此外,文中还涉及了一些最新的研究方向和技术趋势,如AI增强和毫米波通信,为读者提供了更广阔的视野。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值