srm 543

欢迎点这里阅读QvQ

250



A,B(A,B4×1012) 之间所有数的XOR

Solution

转换成1B 异或和异或1A 异或和,容易发现当n21 2n100,1,2,3 特判即可

Code

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
LL gao(LL x) {
    LL t = 0;
    for (int i = 40; i >= 0; --i) {
        LL p = 1ll << i;
        if (x == 3 || !x) return t;
        if (x == 2) return t + 3;
        if (x == 1) return t + 1;
        if (p <= x) {
            if ((x - p + 1) & 1)    t += p;
            x ^= p;
        }
    }
    return t;
}
struct EllysXors {
    long long getXor(long long L, long long R) {
        return gao(R) ^ gao(L - 1);
    }
};

500


Description

在一个横座标轴上有若干个垂直的线段.每个线段之间的距离为width[i] ,现在让你从最左线段的左下角运动到最右线段的右上角
线段之间的运行速度为speed[i],在线段上垂直运动的速度为walk 线段之间只能从整数座标点运动到整数座标点, 每个线段的高度都是一个定值length
请问最快多久可以到达目的地
length100000

Solution

很容易想到dp,dp[i][j]表示过了前i个线段,当前在j的答案,暴力转移复杂度爆炸,容易发现,在每个线段的答案沿高度是单调的,转移时维护上一次转移的位置即可。

Code

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const double inf = 1e20;
double dp[2][100005];
struct EllysRivers {
    double getMin(int length, int walk, vector <int> width, vector <int> speed) {
        int n = width.size();
        for (int i = 0; i <= length; ++i)   dp[0][i] = (double)i / walk;
        for (int i = 1; i <= n; ++i) {
            for (int j = 0; j <= length; ++j)   dp[i & 1][j] = inf;
            int last = 0;
            for (int j = 0; j <= length; ++j)
                for (int k = last; k <= j; ++k) {
                    double t =  dp[(i - 1) & 1][k] + hypot(width[i - 1], j - k) / speed[i - 1];
                    if (t > dp[i & 1][j])   break;
                    dp[i & 1][j] = t;
                    last = k;
                }
        }
        return dp[n & 1][length];
    }
};
发布了86 篇原创文章 · 获赞 7 · 访问量 5万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章