window.cnblogsConfig = {//可以放多张照片,应该是在每一个博文上面的图片,如果是多张的话,那么就随机换的。 homeTopImg: [ "https://cdn.luogu.com.cn/upload/image_hosting/xkzro04i.png" ], }

2023 CSP-J 比赛复盘

2023 CSP-J 比赛复盘

总分:$90+10+0+0=100$

(赛时 Code 没找到,暂略)

题目分析

T1

第一道题是一道数学找规律题,模拟约瑟夫环可以获得 $90 \text{pts}$ 的部分分。比赛的时候拿到了 $90 \text{pts}$,剩下 $10 \text{pts}$ 没有推导出来……

通过如下表格的推导:

$n$ 取完的天数 第 $n$ 个苹果取走的天数
$1$ $1$ $1$
$2$ $2$ $2$
$3$ $3$ $3$
$4$ $3$ $1$
$5$ $4$ $4$
$6$ $4$ $2$
$7$ $4$ $1$
$8$ $5$ $8$
$9$ $5$ $3$
$10$ $5$ $1$

设 $a_1$ 为取完的天数,$a_2$ 为第 $n$ 个苹果取走的天数。不难发现,当 $n \le 3$ 时,$a_1 = a_2 = n$;否则,每轮 $n \leftarrow \left\lceil\dfrac{n}{3}\right\rceil, a_1 \leftarrow a_1 + 1$,每次当取到第 $n$ 个苹果时,$a_2 \leftarrow a_1$。

时间复杂度:$O(\log_3 n)$

${\color{#52C41A} \texttt{AC}}$ Code

#include <cstdio>
using namespace std;

int main()
{
   int n, ans1 = 0, ans2 = 0;
   scanf("%d", &n);
   while(n)
   {
       ++ans1;
       if(!ans2 && n % 3 == 1)
       ans2 = ans1;
       n -= n / 3 + !!(n % 3);
   }
   printf("%d %d", ans1, ans2);
   return 0;
}

T2

第二题是一道朴素的贪心题,然而我赛时居然没有想到解法,只获得了 $10 \text{pts}$ 的特殊数据。贪心策略是先在第一个加油站加油,使油量到达下一个价格更便宜的加油站,并重复该过程。整体比较简单。

时间复杂度:$O(n)$

${\color{#52C41A} \texttt{AC}}$ Code

#include <cstdio>
#include <algorithm>
using namespace std;

int v[100003];

int main()
{
   int n, d, minn = 0x3f3f3f3f;
   scanf("%d%d", &n, &d);
   for(int i = 1; i < n; ++i)
       scanf("%d", &v[i]);
   long long ans = 0, tot = 0;
   for(int i = 1, a; i < n; ++i)
   {
       scanf("%d", &a);
       tot += v[i];
       minn = min(minn, a);
       if(tot > 0)
       {
       ans += (tot + d - 1) / d * minn;
       tot -= (tot + d - 1) / d * d;
       }
   }
   printf("%lld", ans);
   return 0;
}

T3

这道题是一道数学+大模拟题。首先需要有一元二次方程的数学知识储备,然后还要有足够的码力。这道题赛时没有做出来,赛后把我折磨了好几天才 ${\color{#52C41A} \texttt{AC}}$ 了。

时间复杂度:$O(Tn)$

${\color{#52C41A} \texttt{AC}}$ Code

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

inline void print(int q1, int q2)
{
   int g = abs(__gcd(q1, q2));
   q1 /= g;
   q2 /= g;
   if(q2 == 1)
       printf("%d", q1);
   else
   printf("%d/%d", q1, q2);
}

int main()
{
   int T;
   scanf("%d%*d", &T);
   while(T--)
   {
       int a, b, c;
       scanf("%d%d%d", &a, &b, &c);
       int d = b * b - 4 * a * c;
       if(d < 0)
           printf("NO");
       else
       {
           int x = 0, q1, q2;
           for(int i = 1; i * i <= d; ++i)
           if(d % (i * i) == 0)
               x = i;
           if(x * x == d)
           {
               if(a > 0)
               {
                   q1 = -b + x;
                   q2 = 2 * a;
               }
               else
               {
                   q1 = b + x;
                   q2 = -2 * a;
               }
               print(q1, q2);
           }
       else
       {
           if(a > 0)
           {
               q1 = -b;
               q2 = 2 * a;
           }
           else
           {
               q1 = b;
               q2 = -2 * a;
           }
           if(q1 != 0)
           {
               print(q1, q2);
               putchar('+');
           }
           int r = d / (x * x);
           if(a > 0)
           {
               q1 = x;
               q2 = 2 * a;
           }
           else
           {
               q1 = x;
               q2 = -2 * a;
           }
           int g = __gcd(q1, q2);
           q1 /= g;
           q2 /= g;
           if(q2 == 1)
               if(q1 == 1)
                   printf("sqrt(%d)", r);
               else
                   printf("%d*sqrt(%d)", q1, r);
           else if(q1 == 1)
               printf("sqrt(%d)/%d", r, q2);
           else
               printf("%d*sqrt(%d)/%d", q1, r, q2);
       }
   }
   putchar('\n');
   }
   return 0;
}

T4

这道题是一道分层图最短路题。可是我连什么是分层图都不知道……当然,希望 CCF 可以水一下数据,让我输出 -1 得 $10$ 分。

${\color{#52C41A} \texttt{AC}}$ Code

$\tiny{\text{下次一定}}$

总结

这次比赛没有发挥出水平,主要是第二题挂分,只拿到了 $10 \text{pts}$,本来预计 $100 \text{pts}$;其它的题目都在预期之内。我会努力提高代码能力、编程知识、数学知识,并认真听老师讲课,争取以后拿到较好的成绩。预祝各位 AK 【LGR-165-Div.2】洛谷 NOIP 2023 模拟赛,我自己 $100^+$。

posted @ 2023-10-25 22:38  TigerTanWQY  阅读(73)  评论(0)    收藏  举报  来源