当前位置:网站首页>2022杭电多校第一场(K/L/B/C)
2022杭电多校第一场(K/L/B/C)
2022-08-02 22:15:00 【蛀牙牙乐】
K. Random
可以粗略的看作每个数的概率都是1/2
这种取模方法需要注意 : ll te = (mod + 1) / 2; 1ll * (n - m) * te % mod;
int t;
cin >> t;
ll te = (mod + 1) / 2;
while(t--){
ll n, m;
cin >> n >> m;
cout << 1ll * (n - m) * te % mod << endl;
}
或者更好理解的:
ll qpow(ll a, ll b) {
int ans = 1;
a = (a % p + p) % p;
for (; b; b >>= 1) {
if (b & 1) ans = (a * ans) % p;
a = (a * a) % p;
}
return ans;
}
int main() {
ll mm = qpow(2, p - 2);
int t;
cin >> t;
while(t--){
ll n, m;
cin >> n >> m;
cout << (n - m) * mm % p << endl;
}
return 0;
}
L. Alice and Bob
博弈论
总结:
- 从更明显,更好入手的地方考虑;例如:Alice只需要有0就可以赢,问题就转化成了:如何将数转化成含0的
- 转化必胜态,由基础必胜到更大范围
- (也许能从很怪的地方入手,例如:0 2-Alice赢)
来自知乎 - 每日一棵splay - https://zhuanlan.zhihu.com/p/543760351
关键在于构造出0
int t;
cin >> t;
while (t--){
int n;
cin >> n;
for (int i = 0; i <= n; ++i){
cin >> a[i];
}
for (int i = n; i > 0; i--){
a[i - 1] += a[i] / 2;
}
if (a[0])
cout << "Alice" << endl;
else
cout << "Bob" << endl;
}
B. Dragon slayer
dij写到一半发现不对…总结:
- 不限定方向随便走:只用限定上下左右四个方向就行
- 感觉31以内都可以二进制枚举
二进制枚举选择删去哪些墙
int n, m, k;
int xs, ys, xt, yt;
int dx[] = {
0, 0, 1, -1};
int dy[] = {
1, -1, 0, 0};
bool g[35][35];
bool vis[35][35];
struct node
{
int x1, y1, x2, y2;
}wall[35];
int lowbit(int x){
return x & (-x);
}
void add(int k){
if(wall[k].x1 > wall[k].x2)
swap(wall[k].x1, wall[k].x2);
if(wall[k].y1 > wall[k].y2)
swap(wall[k].y1, wall[k].y2);
for (int i = wall[k].x1; i <= wall[k].x2; ++i){
for (int j = wall[k].y1; j <= wall[k].y2; ++j){
g[i][j] = true;
}
}
}
void del(int k){
if(wall[k].x1 > wall[k].x2)
swap(wall[k].x1, wall[k].x2);
if(wall[k].y1 > wall[k].y2)
swap(wall[k].y1, wall[k].y2);
for (int i = wall[k].x1; i <= wall[k].x2; ++i){
for (int j = wall[k].y1; j <= wall[k].y2; ++j){
g[i][j] = false;
}
}
}
bool bfs(){
queue<PII> q;
q.push({
xs, ys});
re(vis);
vis[xs][ys] = true;
while(!q.empty()){
int x = q.front().first, y = q.front().second;
q.pop();
if(x == xt && y == yt)
return true;
for (int i = 0; i < 4; ++i){
int xx = x + dx[i], yy = y + dy[i];
if(xx >= 0 && xx < n && yy >= 0 && yy < m && !vis[xx][yy] && !g[xx][yy]){
q.push({
xx, yy});
vis[xx][yy] = true;
}
}
}
return false;
}
int main()
{
int t;
cin >> t;
while (t--){
cin >> n >> m >> k;
n *= 2, m *= 2;
cin >> xs >> ys >> xt >> yt;
xs = xs * 2 + 1, ys = ys * 2 + 1, xt = xt * 2 + 1, yt = yt * 2 + 1;
for (int i = 0; i <= n; ++i){
for (int j = 0; j <= m; ++j){
g[i][j] = false;
}
}
for (int i = 0; i < k; ++i){
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
wall[i] = {
x1 * 2, y1 * 2, x2 * 2, y2 * 2};
}
int ans = 0;
for (int i = 0; i < (1 << k); ++i){
int cnt = 0;
for (int j = i; j; j -= lowbit(j))
++cnt;
if(cnt <= ans)
continue;
for (int j = 0; j < k; ++j){
if(i >> j & 1)
add(j);
}
if(bfs())
ans = cnt;
for (int j = 0; j < k; ++j){
if(i >> j & 1)
del(j);
}
}
cout << k - ans << endl;
}
return 0;
}
C. Backpack
总结:
(点击跳转至原链接)
bitset<1030>f[2][1030];//f[i][j]前i个物品得到异或值位j的所有的体积状态 不要开太大了,会超时
int main() {
IOS;
int t;
scanf("%d", &t);
while(t--){
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < 1024; ++i)
f[0][i].reset();
f[0][0].set(0);
for (int i = 1; i <= n; ++i){
int v, w;
scanf("%d %d", &v, &w);
for (int j = 0; j < 1024; ++j){
f[i & 1][j] = f[(i & 1) ^ 1][j] | (f[(i & 1) ^ 1][j ^ w] << v);//左移v == 减v
//相当于滚动数组
/* bitset<N> f[N],g[N]; f[0][0] = 1; for(int j=0;j<=1023;j++) g[j]=f[j];赋值上一维 for(int j=1023;j>=0;j--) { f[j]|=g[j^w]<<v; } cout << f[i][m] */
}
}
bool flag = true;
for (int i = 1023; i >= 0; --i){
if(f[n & 1][i][m]) {
printf("%d\n", i);
flag = false;
break;
}
}
if(flag)
printf("-1\n");
}
return 0;
}
边栏推荐
猜你喜欢
Shunted Self-Attention via Multi-Scale Token Aggregation
00 -- jieba分词
In-depth study TypeScript TypeScript 】 【 class (under)
No-code development platform form styling steps introductory course
centos7安装mysql8
Software testing pen questions 1 (with answers)
【使用pyside2遇到的问题】This application failed to start because no Qt platform plugin could be initialized.
HCIP(17)
Rebound shell principle and implementation
微信小程序(一)
随机推荐
H.265视频流媒体播放器EasyPlayer.js集成时出现“SourceBuffer ”报错,该如何解决?
【Unity】Unity开发进阶(六)UnityEvent使用与源码解析
go exec 包
软件测试笔试题1(附答案)
Towards a General Purpose CNN for Long Range Dependencies in ND
图像识别从零写出dnf脚本关键要点
Image recognition from zero to write DNF script key points
CTF命令执行题目解题思路
【TypeScript】深入学习TypeScript类(下)
js function anti-shake and function throttling and other usage scenarios
执子手,到永恒
VMware workstation 程序启动慢
Learn more TypeScript 】 【 TypeScript modular
TDengine 在中天钢铁 GPS、 AIS 调度中的落地
GameStop NFT 市场分析
创建型模式 - 简单工厂模式StaticFactoryMethod
基于STM32的FLASH读写实验含代码(HAL库)
centos7安装mysql5.7步骤(图解版)
go 序列化与反序列化
同样月薪6K,为什么同事跳槽月薪翻倍,而你只涨了1000?