好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

CodeforcesRound#267(Div.2)水了一发真.记录_html/css_WEB-IT

闲着没事就水了一发DIV2,本来想新注册一个小小号来着。结果验证码一直显示不出来。于是就用小号做。

结果rank44,但是没有rating.


以下均不解释题意了。


A:O(n)脑残模拟。

Code:

#include  int main() {    int n, a, b;    scanf("%d", &n);    int res = 0;    while(n--) {        scanf("%d%d", &a, &b);        if (a + 2  

B:注意到两个数相异或后得出的结果的二进制表达中1的位数就是不同的个数。反正怎么做都行,O(nlogn)水。

Code:

#include  #include  #include  #include  #include using namespace std;#define M 1010int a[M];int count(int x) {    int res = 0;    for(; x; x -= x & -x)        ++res;    return res;}int main() {    int n, m, k;    scanf("%d%d%d", &n, &m, &k);    register int i, j;    int S = (1  

C:显然是dp,设f[i][j]表示第i段的结尾为j时的最优值,显然f[i][j]=max{f[i-1][k]+sum[j]-sum[j-m]}(0

不过这样是O(k*n^2),可能超时。

我们发现每一阶段的转移能用到的最优状态都是上一阶段的前缀最优值,于是dp时直接记录下来用来下面的转移,这样就不用枚举了,变为O(k*n)水过。

貌似卡内存,用了滚动数组。

#include  #include  #include  #include  #include using namespace std;#define N 5010long long a[N];long long dp[2][N], sav[2][N];int main() {    int n, m, num;    scanf("%d%d%d", &n, &m, &num);    register int i, j, k;    for(i = 1; i  

D:各种坑爹。我们事实上想要找出一个单词能够通过一系列变换得到的最小答案是多少,不过可能存在环形转移,不能直接做。

于是求出SCC后缩点,每个节点的初始答案等于节点所有内部节点的最优值。然后在DAG上dp即可。

反正就是很恶心。

注意答案可能爆int.

#include  #include  #include  #include  #include  #include #include  using namespace std;#define N 100010#define E 100010int sav[N];    map  M;inline void low(string &s) {    int len = s.length();    for(int i = 0; i  = 'A' && s[i]  > s;        low(s);        if (!M[s]) {            M[s] = ++id;            S[id].get(s);        }        sav[i] = M[s];    }        int m;    scanf("%d", &m);    int x, y;    for(i = 1; i  > a >> b;        low(a), low(b);        if (!M[a]) {            M[a] = ++id;            S[id].get(a);        }        x = M[a];        if (!M[b]) {            M[b] = ++id;            S[id].get(b);        }        y = M[b];        if (x != y)            addedge(x, y);    }        for(i = 1; i  


E:待填坑。

查看更多关于CodeforcesRound#267(Div.2)水了一发真.记录_html/css_WEB-IT的详细内容...

  阅读:35次