Replay


Dup4:

  • 啥都不会? 只能看着两位聚聚A题?

X:

  • 模拟题不会写, 日常摔锅
  • u, v分不清, 日常演员
  • 又是自己没理清楚就抢键盘上机导致送了一万个罚时, 日常背锅

A:迷宫

Solved.

考虑所有人从1号点排队出发,所有人都回到自己位置的时间

让深度大的先走,这样就不会产生堵塞

那么每个人的时间就是 在1号点的等待时间+深度

取最大值即可

 #include<bits/stdc++.h>
using namespace std; #define N 100010
int n, a[N];
vector <int> G[N]; int deep[N], fa[N];
void DFS(int u)
{
for (auto v : G[u]) if (v != fa[u])
{
deep[v] = deep[u] + ;
fa[v] = u;
DFS(v);
}
} int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) G[i].clear();
for (int i = ; i <= n; ++i) scanf("%d", a + i);
for (int i = , u, v; i < n; ++i)
{
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
deep[] = ; DFS();
vector <int> vec;
for (int i = ; i <= n; ++i) if (a[i]) vec.push_back(i);
sort(vec.begin(), vec.end(), [](int a, int b) { return deep[a] > deep[b]; });
int res = ;
int cnt = ;
for (auto it : vec)
{
res = max(res, cnt + deep[it]);
++cnt;
}
printf("%d\n", res);
}
return ;
}

C:斐波那契数列

Solved.

斐波那契数列$前n项和的通项是$

$Fib_n \& (Fib_n - 1) = Fib_n - lowbit(Fib_n)$

$S_n = 2 \cdot a_n + a_{n - 1} - 1$

打表找规律发现

后面那部分是

$1 1 2 1 1 8 1 1 2 1 1 16 1 1 2 1 1 8 1 1 2 1 1\cdots$

有对称性,可以递归求和

 #include <bits/stdc++.h>
using namespace std; #define ll long long
const ll MOD = (ll); int t; ll R;
struct node
{
ll a[][];
node operator * (const node &other) const
{
node res; memset(res.a, , sizeof res.a);
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
for (int k = ; k < ; ++k)
res.a[i][j] = (res.a[i][j] + a[i][k] * other.a[k][j] % MOD + MOD) % MOD;
return res;
}
}; ll a[][] =
{
, ,
, ,
}; ll b[][] =
{
, ,
, ,
}; node qpow(ll n)
{
node base;
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
base.a[i][j] = a[i][j];
node res;
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
res.a[i][j] = b[i][j];
while (n)
{
if (n & ) res = res * base;
base = base * base;
n >>= ;
}
return res;
} ll qpow(ll base, ll n)
{
ll res = ;
while (n)
{
if (n & ) res = (res * base) % MOD;
base = (base * base) % MOD;
n >>= ;
}
return res;
} ll pos[], num[], sum[];
ll solve(ll now)
{
if (now <= ) return ;
if (now == ) return ;
if (now == ) return ;
if (now == ) return ;
if (now == ) return ;
if (now == ) return ;
int id = upper_bound(pos + , pos + , now) - pos - ;
if (pos[id] == now) return (sum[id] + num[id]) % MOD;
return ((solve(now - pos[id]) + solve(pos[id])) % MOD);
} int main()
{
pos[] = ;
for (int i = ; i <= ; ++i) pos[i] = pos[i - ] << ;
num[] = ;
for (int i = ; i <= ; ++i) num[i] = (num[i - ] << ) % MOD;
sum[] = ;
for (int i = ; i <= ; ++i) sum[i] = ((sum[i - ] << ) % MOD + num[i - ]) % MOD;
scanf("%d", &t);
while (t--)
{
scanf("%lld", &R);
ll need = ;
if (R == ) need = ;
else if (R == ) need = ;
else if (R == ) need = ;
else need = (2ll * qpow(R - ).a[][] % MOD + qpow(R - ).a[][] % MOD - + MOD) % MOD;
//cout << R << " " << need << " " << solve(R) << "\n";
printf("%lld\n", (need - solve(R) % MOD + MOD) % MOD);
}
return ;
}

D:二次函数

Solved.

枚举哪两个式子相等,做三次

考虑二元一次方程的根,令$y相同,则有$

$x_1 = -\frac{a_1 \pm \sqrt{4 \cdot y + a_1^2 - 4 \cdot b_1}}{2}$

$x_2 = -\frac{a_2 \pm \sqrt{4 \cdot y + a_2^2 - 4 \cdot b_2}}{2}$

考虑根号下一定是一个平方数

那么令$T^2 = 4 \cdot y + a_1^2 - 4 \cdot b_1$

$t^2 = 4 \cdot y + a_2^2 - 4 \cdot b_2$

$T^2 - t^2 = (T + t) \cdot (T - t) = a_1^2 - 4 \cdot b_1 - a_2^2 + 4 \cdot b_2$

$枚举差值的因数分解,得到T 和 t 再判断是否可以$

$再特判 差值为0 和 差值为1的情况$

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define pll pair <ll, ll>
int t;
ll a[], b[]; pll res;
bool solve(ll a1, ll b1, ll a2, ll b2)
{
ll t1 = (a1 * a1 - * b1);
ll t2 = (a2 * a2 - * b2);
ll gap = abs(t1 - t2);
if (gap == )
{
if ((t1 & ) == (t2 & ))
{
res.first = ;
res.second = -(a2 - a1) / ;
return true;
}
else
return false;
}
if (gap == )
{
if ((t1 & ) != (t2 & ))
{
if (t1 > t2 && ((a1 & ) == ))
{
res.first = -(a1 + ) / ;
res.second = -a2 / ;
return true;
}
else if (t1 < t2 && ((a2 & ) == ))
{
res.first = -a1 / ;
res.second = -(a2 + ) / ;
return true;
}
else return false;
}
}
for (int i = ; i * i < gap; ++i) if (gap % i == && (i + gap / i) % == )
{
ll T = (i + gap / i) / ;
ll t = (gap / i - i) / ;
if (t1 < t2) swap(T, t);
if ((T + a1) % == && (t + a2) % == )
{
res.first = -((T + a1) / );
res.second = -((t + a2) / );
return true;
}
}
return false;
} void work()
{
for (int i = ; i < ; ++i)
for (int j = i + ; j < ; ++j)
{
if (solve(a[i], b[i], a[j], b[j]))
{
if (i == )
{
printf("%lld %lld %lld\n", res.first, j == ? res.second : , j == ? : res.second);
}
else
printf("0 %lld %lld\n", res.first, res.second);
return;
}
}
} int main()
{
scanf("%d", &t);
while (t--)
{
for (int i = ; i < ; ++i) scanf("%lld%lld", a + i, b + i);
work();
}
return ;
}

E:线性探查法

Solved.

拓扑排序?

 #include<bits/stdc++.h>

 using namespace std;

 const int MAXN = 1e6 + ;
const int maxn = 1e3 + ; struct Edge{
int to, nxt;
Edge(){}
Edge(int to, int nxt): to(to), nxt(nxt){}
}edge[MAXN << ]; struct node{
int val;
int index;
node(){}
node(int val, int index):val(val), index(index){}
bool operator < (const node &other) const{
return val > other.val;
}
}brr[maxn]; int n;
int arr[maxn];
int head[maxn], tot;
int du[maxn]; void Init()
{
tot = ;
memset(head, -, sizeof head);
memset(du, , sizeof du);
} void addedge(int u,int v)
{
edge[tot] = Edge(v, head[u]); head[u] = tot++;
} void solve()
{
priority_queue<node>q;
for(int i = ; i < n; ++i) if(du[i] == )
{
q.push(brr[i]);
}
int tot = ;
while(!q.empty())
{
node st = q.top();
q.pop();
arr[tot++] = st.val;
int u = st.index;
for(int i = head[u]; ~i; i = edge[i].nxt)
{
int v = edge[i].to;
--du[v];
if(du[v] == ) q.push(brr[v]);
}
}
} int main()
{
while(~scanf("%d" ,&n))
{
Init();
for(int i = ; i < n; ++i)
{
int x;
scanf("%d", &x);
int now = i;
int pre = x % n;
brr[i] = node(x, i);
while(now != pre)
{
now = (now - + n) % n;
addedge(now, i);
du[i]++;
}
}
solve();
for(int i = ; i <= n; ++i) printf("%d%c", arr[i], " \n"[i == n]);
}
return ;
}

F:逆序对!

Solved.

考虑两个位置的数对有多少个数异或会让他们对答案产生贡献

如果$a > b 那么从高位到地位找到第一位不同的数 这一位要放0,其他位任意的比m小的数$

$a < b 同理$

复杂度$O(n^2logn)$

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 1010
const ll MOD = (ll);
ll Bit[], res;
int n, m, b[N]; void solve(ll a, ll b)
{
for (int i = ; i >= ; --i)
{
int n1 = ((a >> i) & ), n2 = ((b >> i) & );
if (n1 != n2)
{
ll tmp1 = m >> (i + );
ll tmp2 = m & (Bit[i] - );
ll sum = ;
if((m >> i) & )
sum = (tmp1 * Bit[i] % MOD + tmp2 + ) % MOD;
else
sum = (tmp1 * Bit[i]) % MOD;
if (a < b) res = (res + sum) % MOD;
else res = (res + m - sum + MOD) % MOD;
return ;
}
}
} int main()
{
Bit[] = ;
for (int i = ; i <= ; ++i) Bit[i] = (Bit[i - ] << );
while (scanf("%d%d", &n, &m) != EOF)
{
res = ;
for (int i = ; i <= n; ++i) scanf("%d", b + i);
for (int i = ; i <= n; ++i) for (int j = i + ; j <= n; ++j)
solve(b[i], b[j]);
printf("%lld\n", res);
}
return ;
}

G:抢红包机器人

Solved.

至少存在一个机器人,枚举这一位机器人

那么它前面所有账号都是机器人,并且这种关系是传递的,DFS即可

u, v 傻傻分不清楚可还行

 #include<bits/stdc++.h>

 using namespace std;

 const int INF = 0x3f3f3f3f;

 const int MAXN = 1e6 + ;
const int maxn = 1e2 + ; struct Edge{
int to, nxt;
Edge(){}
Edge(int to, int nxt):to(to), nxt(nxt){}
}edge[MAXN << ]; int n, m;
int head[maxn], tot;
int vis[maxn];
int arr[maxn]; void Init()
{
tot = ;
memset(head, -, sizeof head);
} void addedge(int u,int v)
{
edge[tot] = Edge(v, head[u]); head[u] = tot++;
} void DFS(int u)
{
for(int i = head[u]; ~i; i = edge[i].nxt)
{
int v = edge[i].to;
if(vis[v]) continue;
vis[v] = ;
DFS(v);
}
} int main()
{
while(~scanf("%d %d", &n, &m))
{
Init();
for(int i = , k; i <= m; ++i)
{
scanf("%d", &k);
for(int j = ; j <= k; ++j)
{
scanf("%d", arr + j);
}
for(int u = k; u >= ; --u)
{
for(int v = u - ; v >= ; --v)
{
addedge(arr[u], arr[v]);
}
}
}
int ans = INF;
for(int i = ; i <= n; ++i)
{
memset(vis, , sizeof vis);
vis[i] = ;
DFS(i);
int sum = ;
for(int j = ; j <= n; ++j) sum += vis[j];
ans = min(ans, sum);
}
printf("%d\n", ans);
}
return ;
}

J:强壮的排列

Solved.

打了个表? Comet OJ 支持512Kb  感人

CCPC-Wannafly Winter Camp Day7 (Div2, onsite)的更多相关文章

  1. 2019 CCPC-Wannafly Winter Camp Day7(Div2, onsite)

    solve 6/11 补题: A.迷宫 Code:zz Thinking:zz kk 把每个节点的深度都处理出来,同一深度的点的冲突度为 (x-1),x为同层次点数减一. 然后冲突度不断下传(冲突度为 ...

  2. 2020 CCPC Wannafly Winter Camp Day1 C. 染色图

    2020 CCPC Wannafly Winter Camp Day1 C. 染色图 定义一张无向图 G=⟨V,E⟩ 是 k 可染色的当且仅当存在函数 f:V↦{1,2,⋯,k} 满足对于 G 中的任 ...

  3. CCPC Wannafly Winter Camp Div2 部分题解

    Day 1, Div 2, Prob. B - 吃豆豆 题目大意 wls有一个\(n\)行\(m\)列的棋盘,对于第\(i\)行第\(j\)列的格子,每过\(T[i][j]\)秒会在上面出现一个糖果, ...

  4. CCPC-Wannafly Winter Camp Day5 (Div2, onsite) Sorting(线段树)

    题目链接 题意 对序列进行三种操作: 1.区间求和. 2.将区间小于等于$x$的数不改变相对顺序的前提下放到$x$左边,用同样规则将比$x$大的放到右边. 3.将区间大于$x$的数不改变相对顺序的前提 ...

  5. CCPC-Wannafly Winter Camp Day8 (Div2, onsite)

    咕咕咕.    camp补题. 传送门:https://www.zhixincode.com/contest/29/problems A.Aqours 题意:有一棵有根树,根节点为1,给出每个结点的父 ...

  6. CCPC-Wannafly Winter Camp Day3 (Div2, onsite)

    Replay Dup4: 没想清楚就动手写? 写了两百行发现没用?想的还是不够仔细啊. 要有莽一莽的精神 X: 感觉今天没啥输出啊, 就推了个公式?抄了个板子, 然后就一直自闭A. 语文差,题目没理解 ...

  7. 2019 CCPC-Wannafly Winter Camp Day1 (Div2, onsite)

    solve:4/11 补题:6/11 A 机器人 补题:zz 这是一道分类讨论的题目,有一个规律就是如果必须要从第一个区到第二个区,那么最多转区两次(1到2一次,2到1一次),然后分类讨论即可,只要细 ...

  8. Wannafly Winter Camp Day8(Div1,onsite) E题 Souls-like Game 线段树 矩阵乘法

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog @ Problem:传送门  Portal  原题目描述在最下面.  简单的 ...

  9. CCPC-Wannafly Winter Camp Day1 (Div2, onsite) A B C E F I J

    A 机器人 链接:https://www.cometoj.com/contest/7/problem/A?problem_id=92 思路: 分两大类讨论: 1. B区没有点: (1)点都在起点左边 ...

随机推荐

  1. docker 配置文件:/etc/docker/daemon.json

    /etc/docker/daemon.json 是 docker 的配置文件,默认是没有的,需要我们手动创建,可配置项如下: [root@localhost ~]$ vim /etc/docker/d ...

  2. C# string.Format("{0:C3}", 2)

  3. php 连接mongdb的类

    <?php/** * php 连接mongdb的类的封装 * @author 李秀然 */ class mongdb{ private $host;//"mongodb://admin ...

  4. delphi 获取网卡信息(支持多网卡)

    delphi 获取网卡信息(支持多网卡) unit LGetAdapterInfo; interface uses Windows, SysUtils, Classes; const MAX_HOST ...

  5. Docker 使用指南 (三)—— 网络配置

    版权声明:本文由田飞雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/95 来源:腾云阁 https://www.qclou ...

  6. 【BZOJ4099】Trapped in the Haybales Gold STL

    [BZOJ4099]Trapped in the Haybales Gold Description Farmer John has received a shipment of N large ha ...

  7. mysql load data导入脚本

    # !/bin/bash ############中文说明###################### #本程序的一些提示需要中文支持,如系统没有安装中文包,请先安装:yum -y groupinst ...

  8. Spring项目对JDBC的支持和基本使用

    欢迎查看Java开发之上帝之眼系列教程,如果您正在为Java后端庞大的体系所困扰,如果您正在为各种繁出不穷的技术和各种框架所迷茫,那么本系列文章将带您窥探Java庞大的体系.本系列教程希望您能站在上帝 ...

  9. 转载:SQL Server编程基本语法

    一.定义变量 --简单赋值 declare @a int print @a --使用select语句赋值 ) select @user1='张三' print @user1 ) print @user ...

  10. MP3 ID3信息编辑器(附源码)

    练习WPF时写的编辑MP3 ID3信息的小工具,方便对歌曲的统一管理,同时增加了调用豆瓣音乐API获取专辑信息的功能:1.主界面: 2.没有ID3 信息的MP3歌曲: 3.点击自动获取,从豆瓣音乐获取 ...