A. Salem and Sticks

签.

 #include <bits/stdc++.h>
using namespace std; #define N 1010
int n, a[N]; int work(int x)
{
int res = ;
for (int i = ; i <= n; ++i)
res += max(, abs(x - a[i]) - );
return res;
} int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%d", a + i);
int Min = (int)1e9, pos = -;
for (int i = ; i <= ; ++i)
{
int tmp = work(i);
if (tmp < Min)
{
Min = tmp;
pos = i;
}
}
printf("%d %d\n", pos, Min);
}
return ;
}

B. Zuhair and Strings

签.

 #include <bits/stdc++.h>
using namespace std; #define N 200010
int n, k;
char s[N]; int work(char c)
{
int res = ;
int tmp = ;
for (int i = ; i <= n; ++i)
{
if (s[i] != c) tmp = ;
else
{
++tmp;
if (tmp == k)
{
++res;
tmp = ;
}
}
}
return res;
} int main()
{
while (scanf("%d%d", &n, &k) != EOF)
{
scanf("%s", s + );
int res = ;
for (int i = 'a'; i <= 'z'; ++i)
res = max(res, work(i));
printf("%d\n", res);
}
return ;
}

C. Ayoub and Lost Array

签.

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 200010
const ll MOD = (ll)1e9 + ;
int n, l, r;
ll a[], f[N][]; int main()
{
while (scanf("%d%d%d", &n, &l, &r) != EOF)
{
memset(a, , sizeof a);
while (l % && l <= r)
{
a[l % ]++;
++l;
}
while (r % && l <= r)
{
a[r % ]++;
--r;
}
if (l <= r)
{
++a[];
int tmp = (r - l) / ;
a[] += tmp;
a[] += tmp;
a[] += tmp;
}
memset(f, , sizeof f);
f[][] = ;
for (int i = ; i <= n; ++i)
{
f[i][] = (f[i - ][] * a[] % MOD + f[i - ][] * a[] % MOD + f[i - ][] * a[] % MOD) % MOD;
f[i][] = (f[i - ][] * a[] % MOD + f[i - ][] * a[] % MOD + f[i - ][] * a[] % MOD) % MOD;
f[i][] = (f[i - ][] * a[] % MOD + f[i - ][] * a[] % MOD + f[i - ][] * a[] % MOD) % MOD;
}
printf("%lld\n", f[n][]);
}
return ;
}

D. Kilani and the Game

签.

 #include <bits/stdc++.h>
using namespace std; #define N 1010
int n, m, p;
char G[N][N];
int s[];
struct node
{
int x, y, step;
node () {}
node (int x, int y, int step) : x(x), y(y), step(step) {}
};
queue <node> q[];
bool stop()
{
for (int i = ; i <= p; ++i) if (!q[i].empty())
return false;
return true;
} int Move[][] =
{
-, ,
, ,
,-,
, ,
};
bool ok(int x, int y)
{
if (x < || x > n || y < || y > m || G[x][y] != '.') return false;
return true;
} void BFS(int id, int cnt)
{
while (!q[id].empty())
{
int x = q[id].front().x;
int y = q[id].front().y;
int step = q[id].front().step;
//printf("%d %d %d %d\n", x, y, id, step);
if (step / s[id] >= cnt) return;
q[id].pop();
for (int i = ; i < ; ++i)
{
int nx = x + Move[i][];
int ny = y + Move[i][];
if (ok(nx, ny))
{
G[nx][ny] = id + '';
q[id].push(node(nx, ny, step + ));
}
}
}
} int main()
{
while (scanf("%d%d%d", &n, &m, &p) != EOF)
{
for (int i = ; i <= p; ++i) scanf("%d", s + i);
for (int i = ; i <= n; ++i) scanf("%s", G[i] + );
for (int i = ; i <= p; ++i) while (!q[i].empty()) q[i].pop();
for (int i = ; i <= n; ++i) for (int j = ; j <= m; ++j) if (isdigit(G[i][j]))
q[G[i][j] - ''].push(node(i, j, ));
int cnt = ;
while ()
{
for (int i = ; i <= p; ++i) BFS(i, cnt);
++cnt;
if (stop()) break;
}
int ans[];
memset(ans, , sizeof ans);
for (int i = ; i <= n; ++i) for (int j = ; j <= m; ++j) if (isdigit(G[i][j]))
++ans[G[i][j] - ''];
//for (int i = 1; i <= n; ++i) printf("%s\n", G[i] + 1);
for (int i = ; i <= p; ++i) printf("%d%c", ans[i], " \n"[i == p]);
}
return ;
}

E. Helping Hiasat

Upsolved.

题意:

两种操作

  • 更改自己的handle
  • 伙伴查询handle

如果一个伙伴在每次查询时显示的都是自己名字,那么他就会开心

问 最多可以让多少人开心

思路:

法一:

一张图的最大独立集是选出一个点集,使得任意两点不相邻

一张图的最大团是选出一个点集,使得任意两点之间有边相连

一张无向图的补图的最大图就是原图的最大独立集

我们发现这道题两个1之间的所有点都是不能一起happy的,那我们给他们两两之间连上边

然后求补图的最大团即可

 #include <bits/stdc++.h>
using namespace std; #define N 110
int n, m, t;
int g[N][N];
int dp[N];
int stk[N][N];
int mx; map <string, int> mp;
int get(string s)
{
if (mp.find(s) != mp.end()) return mp[s];
else mp[s] = t++;
return mp[s];
} int DFS(int n, int ns, int dep)
{
if (ns == )
{
mx = max(mx, dep);
return ;
}
int i, j, k, p, cnt;
for (i = ; i < ns; ++i)
{
k = stk[dep][i];
cnt = ;
if (dep + n - k <= mx)
return ;
if (dep + dp[k] <= mx)
return ;
for (j = i + ; j < ns; ++j)
{
p = stk[dep][j];
if (g[k][p])
stk[dep + ][cnt++] = p;
}
DFS(n, cnt, dep + );
}
return ;
} int clique(int n)
{
int i, j, ns;
for (mx = , i = n - ; i >= ; --i)
{
for (ns = , j = i + ; j < n; ++j)
{
if (g[i][j])
stk[][ns++] = j;
}
DFS(n, ns, );
dp[i] = mx;
}
return mx;
} vector <int> vec;
void add()
{
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (auto u : vec) for (auto v : vec)
g[u][v] = g[v][u] = ;
vec.clear();
} int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
t = ;
mp.clear();
for (int i = ; i < m; ++i) for (int j = ; j < m; ++j) g[i][j] = ;
[]()
{
int op; char s[];
for (int nn = ; nn <= n; ++nn)
{
scanf("%d", &op);
if (op == )
add();
else
{
scanf("%s", s + );
vec.push_back(get(s + ));
}
}
}();
add();
for (int i = ; i < m; ++i) g[i][i] = ;
//for (int i = 1; i <= m; ++i) for (int j = 1; j <= m; ++j) printf("%d %d %d\n", i, j, g[i][j]);
printf("%d\n", clique(m));
}
return ;
}

法二:

$m = 40, 可以折半状压,再合起来$

考虑妆压的时候要从子集转移到超集,可以通过$dp上去$

$vp的时候想到折半状压,但是当时是枚举子集来转移,复杂度大大增加..$

 #include <bits/stdc++.h>
using namespace std; #define N 50
#define M 1100010
int n, m, t;
int G[N][N]; map <string, int> mp;
int get(string s)
{
if (mp.find(s) != mp.end()) return mp[s];
else mp[s] = ++t;
return mp[s];
} vector <int> vec;
void add()
{
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (auto u : vec) for (auto v : vec)
G[u][v] = ;
vec.clear();
} int f[M], g[M];
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
t = ; mp.clear();
memset(G, , sizeof G);
int op; char s[N];
for (int nn = ; nn <= n; ++nn)
{
scanf("%d", &op);
if (op == ) add();
else
{
scanf("%s", s + );
vec.push_back(get(s + ));
}
}
add();
for (int i = ; i <= m; ++i)
G[i][i] = ;
int s1 = m / , s2 = m - s1;
for (int i = ; i < ( << s1); i <<= ) f[i] = ;
for (int i = ; i < ( << s2); i <<= ) g[i] = ;
f[] = g[] = ;
for (int i = ; i < ( << s1); ++i)
{
for (int j = ; j < s1; ++j) if (!((i >> j) & ))
{
int flag = ;
for (int k = ; k < s1; ++k) if (((i >> k) & ) && G[k + ][j + ])
{
flag = ;
break;
}
f[i | ( << j)] = max(f[i | ( << j)], f[i] + flag);
}
}
for (int i = ; i < ( << s2); ++i)
{
for (int j = ; j < s2; ++j) if (!((i >> j) & ))
{
int flag = ;
for (int k = ; k < s2; ++k) if (((i >> k) & ) && G[s1 + k + ][s1 + j + ])
{
flag = ;
break;
}
g[i | ( << j)] = max(g[i | ( << j)], g[i] + flag);
}
}
int res = ;
for (int i = ; i < ( << s1); ++i)
{
int s3 = ( << s2) - ;
for (int j = ; j < s1; ++j) if ((i >> j) & )
{
for (int k = ; k < s2; ++k) if (G[j + ][s1 + k + ] && ((s3 >> k) & ))
s3 ^= ( << k);
}
res = max(res, f[i] + g[s3]);
}
printf("%d\n", res);
}
return ;
}

法三:

为什么随机也行啊,能不能证明啊,喵喵喵..

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 50
int n, m, t;
int G[N][N], a[N];
ll f[N]; map <string, int> mp;
int get(string s)
{
if (mp.find(s) != mp.end()) return mp[s];
else mp[s] = ++t;
return mp[s];
} vector <int> vec;
void add()
{
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (auto u : vec) for (auto v : vec)
G[u][v] = ;
vec.clear();
} int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
t = ; mp.clear();
memset(G, , sizeof G);
int op; char s[N];
for (int nn = ; nn <= n; ++nn)
{
scanf("%d", &op);
if (op == ) add();
else
{
scanf("%s", s + );
vec.push_back(get(s + ));
}
}
add();
for (int i = ; i <= m; ++i)
G[i][i] = ;
int res = ;
for (int i = ; i <= m; ++i) a[i] = i;
for (int i = ; i <= m; ++i)
{
f[i] = ;
for (int j = ; j <= m; ++j) if (G[i][j])
f[i] |= (1ll << (j - ));
}
for (int t = ; t <= ; ++t)
{
random_shuffle(a + , a + + m);
ll g = ; int tmp = ;
for (int i = ; i <= m; ++i) if (((g >> (a[i] - )) & 1ll) == )
{
g |= f[a[i]];
++tmp;
}
res = max(res, tmp);
}
printf("%d\n", res);
}
return ;
}

Codeforces Round #533 (Div. 2) Solution的更多相关文章

  1. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  2. Codeforces Round #466 (Div. 2) Solution

    从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...

  3. 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution

    对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...

  4. Codeforces Round #545 (Div. 1) Solution

    人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...

  5. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  6. Codeforces Round 500 (Div 2) Solution

    从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...

  7. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】

    传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...

  8. Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】

    传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...

  9. Codeforces Round #533(Div. 2) C.Ayoub and Lost Array

    链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...

随机推荐

  1. 【RF库Collections测试】combine lists

    Arguments: [ *lists ]Combines the given `lists` together and returns the result. The given lists are ...

  2. Redis(五)-- Java API

    一.pox.xml <dependencies> <dependency> <groupId>redis.clients</groupId> <a ...

  3. ARM、MCU、DSP、FPGA、SOC各是什么?区别是什么?(转)

    ARM ARM处理器是Acorn计算机有限公司面向低预算市场设计的第一款RISC微处理器.更早称作Acorn RISC Machine.ARM处理器本身是32位设计,但也配备16位指令集,一般来讲比等 ...

  4. JS时间格式化函数

    Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, //month & ...

  5. 非旋转Treap

    Treap是一种平衡二叉树,同时也是一个堆.它既具有二叉查找树的性质,也具有堆的性质.在对数据的查找.插入.删除.求第k大等操作上具有期望O(log2n)的复杂度.     Treap可以通过节点的旋 ...

  6. log4j和commons- logging(好文整理转载)

    一 :为什么同时使用commons-logging和Log4j?为什么不仅使用其中之一? Commons-loggin的目的是为 “所有的Java日志实现”提供一个统一的接口,它自身的日志功能平常弱( ...

  7. ./configure

    ./configure --prefix=/usr/local/scws --prefix选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr/local/bin,库文件默认放在/ ...

  8. mysql 使用如下三种方式应用where条件,从好到坏

    在索引中使用where条件过滤不匹配的记录,这是在存储引擎层完成的: ​使用索引覆盖扫描(explain语句中的Extra列中出现Using index)来返回记录.直接从索引中过滤掉不需要的记录并返 ...

  9. VMware Fusion 5虚拟机怎样与MAC共享文件

    刚刚在Macbook Pro中安装了VMware Fusion 5虚拟机,虚拟机里装了Windows7,在虚拟机的设置里也设置了共享MAC的几个文件夹,以便与MAC交换文件,但是在Windows7里怎 ...

  10. 使用DBMS_SUPPORT包

    DBMS_SUPPORT包从Oracle7.2引入,主要功能用以提供更完整的用户session跟踪信息,这个包可以通过运行 dbmssupp.sql 和 prvtsupp.plb 两个脚本来创建.该脚 ...