2024CCPC郑州邀请赛个人题解

2024CCPC郑州邀请赛个人题解

题目PDF

GYM

题解火车头

#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <bitset>
#include <cmath>
#include <numeric>

#define endl '\n'

#define ft first
#define sd second

#define yes cout << "yes\n"
#define no cout << "no\n"

#define Yes cout << "Yes\n"
#define No cout << "No\n"

#define YES cout << "YES\n"
#define NO cout << "NO\n"

#define pb push_back
#define eb emplace_back

#define all(x) x.begin(), x.end()
#define unq_all(x) x.erase(unique(all(x)), x.end())
#define sort_all(x) sort(all(x))
#define reverse_all(x) reverse(all(x))

#define INF 0x7fffffff
#define INFLL 0x7fffffffffffffffLL

#define RED cout << "\033[91m"
#define GREEN cout << "\033[92m"
#define YELLOW cout << "\033[93m"
#define BLUE cout << "\033[94m"
#define MAGENTA cout << "\033[95m"
#define CYAN cout << "\033[96m"
#define RESET cout << "\033[0m"

// 红色
#define DEBUG1(x)                     \
    RED;                              \
    cout << #x << " : " << x << endl; \
    RESET;

// 绿色
#define DEBUG2(x)                     \
    GREEN;                            \
    cout << #x << " : " << x << endl; \
    RESET;

// 蓝色
#define DEBUG3(x)                     \
    BLUE;                             \
    cout << #x << " : " << x << endl; \
    RESET;

// 品红
#define DEBUG4(x)                     \
    MAGENTA;                          \
    cout << #x << " : " << x << endl; \
    RESET;

// 青色
#define DEBUG5(x)                     \
    CYAN;                             \
    cout << #x << " : " << x << endl; \
    RESET;

// 黄色
#define DEBUG6(x)                     \
    YELLOW;                           \
    cout << #x << " : " << x << endl; \
    RESET;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<string, ll> psl;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pss> vpss;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

typedef queue<int> qi;
typedef queue<ll> ql;
typedef queue<pii> qpii;
typedef queue<pll> qpll;
typedef queue<psi> qpsi;
typedef queue<psl> qpsl;

typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef priority_queue<string> pqs;
typedef priority_queue<pii> pqpii;
typedef priority_queue<psi> pqpsi;
typedef priority_queue<pll> pqpl;
typedef priority_queue<psi> pqpsl;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<ll, ll> mll;
typedef map<ll, bool> mlb;
typedef map<char, int> mci;
typedef map<char, ll> mcl;
typedef map<char, bool> mcb;
typedef map<string, int> msi;
typedef map<string, ll> msl;
typedef map<int, bool> mib;

typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> uml;
typedef unordered_map<char, int> umci;
typedef unordered_map<char, ll> umcl;
typedef unordered_map<string, int> umsi;
typedef unordered_map<string, ll> umsl;

template <typename T>
inline void read(T &x)
{
    T f = 1;
    x = 0;
    char ch = getchar();
    while (0 == isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (0 != isdigit(ch))
        x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
    x *= f;
}

template <typename T>
inline void write(T x)
{
    if (x < 0)
    {
        x = ~(x - 1);
        putchar('-');
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

A.Once In My Life

image-20240514215527125

样例

输入
3
1 6
12345678 9
233 2
输出
1234567896
404
9217006

解题思路

N = k × n N=k\times n N=k×n,考虑乘法的性质,为了使得我们在构造时一定能构造出 1 ∼ 9 1\sim9 19 d d d,我们可以选择 N = 123456789 d x x x x x x x x N=123456789dxxxxxxxx N=123456789dxxxxxxxx这种形式来进行构造,为了使得 k k k对最终结果影响最小,我们可以令 N = ( 1234567890 + d ) × 1 0 ⌈ l o g 10 n ⌉ N=(1234567890+d)\times 10^{\lceil log_{10}n\rceil} N=(1234567890+d)×10log10n。即使 k k k上下浮动,也可以保证前 10 10 10位数字出现。

所以 k = ⌈ N n ⌉ k=\lceil \frac Nn\rceil k=nN

题解

*#####################################BEGIN#####################################*/

void solve()
{
    ll n, d;
    cin >> n >> d;
    ll N = (1234567890 + d) * ll(pow(10, ceil(log10(n))));
    cout << (N + n - 1) / n << endl;
}

int main()
{
    ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    int _ = 1;
    std::cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}

/*######################################END######################################*/

D.距离之比

image-20240514202113554

image-20240514202407819

样例

输出
2
2
0 0
0 1
3
1 1
2 3
5 8
输入
1.000000000000
1.371988681140

解题思路

我们设 d x = ∣ x i − x j ∣ , d y = ∣ y i − y j ∣ dx=|x_i-x_j|,dy=|y_i-y_j| dx=xixjdy=yiyj

D ( θ ) = ∣ P i P j ∣ 1 ∣ P i P J ∣ 2 = d x + d y d x 2 + d y 2 = sin ⁡ ( θ ) + ∣ cos ⁡ ( θ ) ∣ D(\theta)=\frac{|P_iP_j|_1}{|P_iP_J|_2}=\frac {dx+dy}{\sqrt{dx^2+dy^2}}=\sin(\theta)+|\cos(\theta)| D(θ)=PiPJ2PiPj1=dx2+dy2 dx+dy=sin(θ)+cos(θ)

A A A为直线 P Q PQ PQ x x x轴的交点, θ = ∠ P A x , 0 ≤ θ ≤ π 2 \theta = \angle PAx ,0 \le \theta \le \frac {\pi}{2} θ=PAx,0θ2π

观察公式可以发现,当 θ = π 4 \theta=\frac \pi4 θ=4π θ = 3 π 4 \theta=\frac {3\pi} 4 θ=43π时, D ( θ ) D(\theta) D(θ)取得最大值为 2 \sqrt{2} 2 ,且 D ( θ ) D(\theta) D(θ)为正弦函数,其函数图像如下:

image-20240514214108135

所以当 θ \theta θ越接近 π 4 \frac \pi4 4π 3 π 4 \frac {3\pi} 4 43π D ( θ ) D(\theta) D(θ)越大,因此,我们应该寻找 ∠ P A x \angle PAx PAx π 4 \frac \pi 4 4π 3 π 4 \frac {3\pi} 4 43π差值最小的两个点 P , Q P,Q P,Q

因此,我们可以将所有点绕原点旋转 4 5 ∘ 45^\circ 45,那么在 x x x轴上任意两个相邻的点,它们构成的直线与 x x x轴夹角一定相较于,它们与其它点构成的直线与 x x x轴的夹角,更接近 4 5 ∘ 45^\circ 45;在 y y y轴上任意两个相邻的点,它们构成的直线与 x x x轴夹角一定相较于,它们与其它点构成的直线与 x x x轴的夹角,更接近 13 5 ∘ 135^\circ 135

所以,我们只需要先处理出所有点绕原点旋转 4 5 ∘ 45^\circ 45后的位置,然后对它们的横坐标和纵坐标分别排序,然后枚举相邻两个的 D D D并跟新答案就行。

时间复杂度为 O ( n l o g n ) O(nlogn) O(nlogn)

题解

/*#####################################BEGIN#####################################*/

#define x first
#define y second

// 注:不能使用cmath中的cos和sin函数,精度不够
const ld cos45 = sqrt(2) / 2;
const ld sin45 = sqrt(2) / 2;

ld D(pdd a, pdd b)
{
    return (abs(a.x - b.x) + abs(a.y - b.y)) / sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void solve()
{
    int n;
    cin >> n;
    vector<pdd> points(n);
    // 记录旋转后的点和原始下标
    vector<pair<pdd, int>> rotate(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%Lf%Lf", &points[i].x, &points[i].y);
        // 逆时针旋转45度
        // 坐标变换公式
        // x`= x*cos45 - y*sin45
        // y`= x*sin45 + y*cos45
        rotate[i].ft.x = points[i].x * cos45 - points[i].y * sin45;
        rotate[i].ft.y = points[i].x * sin45 + points[i].y * cos45;
        rotate[i].sd = i;
    }
    ld ans = 0.0;
    // 按横坐标排序
    sort(all(rotate));
    // 枚举相邻两个点的D
    for (int i = 1; i < n; i++)
    {
        ans = max(ans, D(points[rotate[i - 1].sd], points[rotate[i].sd]));
    }
    // 按纵坐标排序
    sort(all(rotate), [](pair<pdd, int> a, pair<pdd, int> b)
         { return a.ft.y < b.ft.y; });
    // 枚举相邻两个点的D
    for (int i = 1; i < n; i++)
    {
        ans = max(ans, D(points[rotate[i - 1].sd], points[rotate[i].sd]));
    }

    printf("%.12Lf\n", ans);
}

int main()
{
    // ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    int _ = 1;
    std::cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}

/*######################################END######################################*/

B,F,G,H,J,K,L,M都会补,只不过最近期末考没啥时间了。

  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值