标签(空格分隔): 经验 题解

时量 : 2h

概括 :

\[\text{2min t1 }\\
\text{10min t2 (hacked)}\\
\text{30min t3 }\\
\text{over 1h t4(false) }\\
\text{rating down : 30pts}\\
\]
  • t1、t2、t3、t4都是一眼题
  • 最大的收获是在cf不要随意使用memset(t2 hack)
  • t4 错在想当然的把第一个质因子当作最多的了。。。

A

求一个排列\(p_i\),使 \(p_i \ne i\)

\(answer : p_i = i \% n + 1\)

B

找一个数,仅仅出现过一次且最小

$answer : $ 桶子维护即可

C

给出一个序列\(\{a_n\}\)

求一个数\(b\), 两个\(b\)之间删一次,问最小删除次数

\(answer:unique\)一发,求除首尾最小出现个数即可。

D

给一个数\(n\), 求一个序列\(a_i\)

使得\(a_i | a_{i + 1} \&\& \prod\limits_{i = 1} ^ n a_i = n\)

\(answer:\) 找出最多的质因子\(p\)

\(a_{1 \sim n-1}=p,a_n = n / p^{n - 1}\)

E

给定一颗基环树,求树上总简单路径个数(一个路径与它的逆路径只算一次)

\(answer:\)先撸环,对于每个环上点的子树中的路径一定是单一的,其他路径经过环,所以有两个

因此,\(ans=C_n^2 - \sum\limits_{x \in rope} C_{son[x]}^2\)

F

把\({a_n}\)分成三段,第一段的最大值等于第二段的最小值等于第三段的最大值

\(answer:\)因为有三段所以有两个分界点。枚举第一个,二分查找第二个。因为最小值和最大值都有单调性,所以可以二分,具体来说就是如果第二段最小值小了就往右,否则往左,相等时再看第三段最大值,大右小左,没有成立的就输出no。


A

/*************************************************
Copyright: 724033213@qq.com
Author: Jack
*************************************************/
#include <bits/stdc++.h>
#define LL long long
#define il inline
#define rg register
using namespace std;
il void chkmax(int &a, int b) {a = a > b ? a : b;}
il void chkmin(int &a, int b) {a = a < b ? a : b;}
il int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
il void write(int x) {
char c[33] = {0}, tot = 0;
if(x == 0) {putchar('0'); return;}
while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
while(tot) {putchar(c[tot --]);}
return ;
}
int s, t, n, m;
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
cin >> t;
while(t --) {
n = read();
for(int i = 1; i <= n; i ++) {
printf("%d ", i % n + 1);
}
printf("\n");
}
return 0;
}

B

/*************************************************
Copyright: 724033213@qq.com
Author: Jack
*************************************************/
#include <bits/stdc++.h>
#define LL long long
#define il inline
#define rg register
using namespace std;
il void chkmax(int &a, int b) {a = a > b ? a : b;}
il void chkmin(int &a, int b) {a = a < b ? a : b;}
il int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
il void write(int x) {
char c[33] = {0}, tot = 0;
if(x == 0) {putchar('0'); return;}
while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
while(tot) {putchar(c[tot --]);}
return ;
}
const int maxn = 2e5 + 5;
int s, t, n, m;
int a[maxn], vis[maxn];
void work() {
n = read(); m = 1e9; s = -1;
for(int i = 1; i <= n; i ++) vis[(a[i] = read())] = 0;
for(int i = 1; i <= n; i ++) vis[a[i]] ++;
for(int i = 1; i <= n; i ++) if(vis[a[i]] == 1 && a[i] < m) m = a[i], s = i;
printf("%d\n", s);
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
t = read();
while(t --) work();
return 0;
}

C

/*************************************************
Copyright: 724033213@qq.com
Author: Jack
*************************************************/
#include <bits/stdc++.h>
#define LL long long
#define il inline
#define rg register
using namespace std;
il void chkmax(int &a, int b) {a = a > b ? a : b;}
il void chkmin(int &a, int b) {a = a < b ? a : b;}
il int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
il void write(int x) {
char c[33] = {0}, tot = 0;
if(x == 0) {putchar('0'); return;}
while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
while(tot) {putchar(c[tot --]);}
return ;
}
const int maxn = 2e5 + 5;
int s, t, n, m, a[maxn], box[maxn];
void work() {
int ans = 1e9;
n = read();
memset(box, 0, sizeof(box));
for(int i = 1; i <= n; i ++) a[i] = read();
n = unique(a + 1, a + 1 + n) - (a + 1);
if(n == 1) {puts("0"); return ;}
for(int i = 2; i < n; i ++) box[a[i]] ++;
for(int i = 1; i <= n; i ++) chkmin(ans, box[a[i]] + 1);
printf("%d\n", ans);
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
t = read();
while(t --) work();
return 0;
}

D

/*************************************************
Copyright: 724033213@qq.com
Author: Jack
*************************************************/
#include <bits/stdc++.h>
#define int long long
#define il inline
#define rg register
using namespace std;
il void chkmax(int &a, int b) {a = a > b ? a : b;}
il void chkmin(int &a, int b) {a = a < b ? a : b;}
il int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
il void write(int x) {
char c[33] = {0}, tot = 0;
if(x == 0) {putchar('0'); return;}
while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
while(tot) {putchar(c[tot --]);}
return ;
}
const int maxn = 2e5 + 5;
int s, t, n, m;
int p[maxn], c[maxn], ans[maxn], top;
int pr[maxn], vis[maxn], isp[maxn], cnt;
void euler(int n) {
for(int i = 2; i <= n; i ++) {
if(vis[i]) continue;
pr[++ cnt] = i;
for(int j = i; j * i <= n; j ++)
vis[i * j] = 1;
}
}
void work() {
int lb = 0;
m = n = read(); top = 1;
memset(c, 0, sizeof(c));
for(int i = 1; pr[i] * pr[i] <= n; i ++) {
if(n % pr[i] == 0) {
while(m % pr[i] == 0) {
c[i] ++;
if(c[i] > c[lb]) lb = i;
m /= pr[i];
}
}
}
if(lb == 0) {
printf("1\n%lld\n", m);
return ;
}
cout << c[lb] << "\n";
for(int i = 1; i < c[lb]; i ++) {
printf("%lld ", pr[lb]); top *= pr[lb];
}
printf("%lld\n", n / top);
return ;
}
signed main() {
t = read();
euler(2e5);
while(t --) work();
return 0;
}

E

/*************************************************
Copyright: 724033213@qq.com
Author: Jack
*************************************************/
#include <bits/stdc++.h>
#define LL long long
#define il inline
#define rg register
using namespace std;
il void chkmax(int &a, int b) {a = a > b ? a : b;}
il void chkmin(int &a, int b) {a = a < b ? a : b;}
il int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
il void write(int x) {
char c[33] = {0}, tot = 0;
if(x == 0) {putchar('0'); return;}
while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
while(tot) {putchar(c[tot --]);}
return ;
}
int s, t, n, m;
const int maxn = 2e5 + 5;
struct node {
int to, nxt;
} e[maxn << 1];
int head[maxn], tot;
//int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
void add(int x, int y) {
e[++ tot] = {y, head[x]}; head[x] = tot;
}
int dep[maxn], num[maxn], scc[maxn], cnt;
int ring;
void rope(int B, int E) {
if(dep[B] < dep[E]) swap(B, E);
for( ; dep[B] > dep[E]; )
scc[B] = 1, B = num[B];
for( ; B ^ E; )
scc[B] = scc[E] = 1, B = num[B], E = num[E];
scc[B] = 1;
ring = 1;
}
void fnd(int x, int fa) {
// cerr << x << "sadads asd\n";
if(ring == 1) return ;
num[x] = fa; dep[x] = dep[fa] + 1;
for(int i = head[x]; i ; i = e[i].nxt) {
int y = e[i].to;
if(y ^ fa) {
// cout << x << "+" << y << " " << num[y] << "\n";
if(dep[y]) {
// cerr << "sda " << x << " " << y << "\n";
rope(x, y);
ring = 1;
return ;
} else {
fnd(y, x);
}
}
}
}
int son[maxn];
void dfs(int x, int fa) {
son[x] = 1;
for(int i = head[x]; i ; i = e[i].nxt) {
int y = e[i].to;
if((y ^ fa) && !scc[y]) {
dfs(y, x);
son[x] += son[y];
}
}
}
void work() {
LL ans = 0; tot = 0; ring = 0;
n = read();
memset(head, 0, sizeof(head));
for(int i = 1, x, y; i <= n; i ++) {
dep[i] = num[i] = scc[i] = 0;
x = read(), y = read();
add(x, y); add(y, x);
}
ans = 1ll * n * (n - 1);
fnd(1, 0);
for(int i = 1; i <= n; i ++) if(scc[i] == 1) dfs(i, 0), ans -= 1ll * son[i] * (son[i] - 1) / 2;
// for(int i = 1; i <= n; i ++) cout << scc[i] << " "; cout << "\n";
printf("%lld\n", ans);
return ;
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
t = read();
while(t --) work();
return 0;
}

F

/*************************************************
Copyright: 724033213@qq.com
Author: Jack
*************************************************/
#include <bits/stdc++.h>
#define LL long long
#define il inline
#define rg register
using namespace std;
il void chkmax(int &a, int b) {a = a > b ? a : b;}
il void chkmin(int &a, int b) {a = a < b ? a : b;}
il int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
il void write(int x) {
char c[33] = {0}, tot = 0;
if(x == 0) {putchar('0'); return;}
while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
while(tot) {putchar(c[tot --]);}
return ;
}
int s, t, n, m;
const int maxn = 2e5 + 5;
struct node {
int to, nxt;
} e[maxn << 1];
int head[maxn], tot;
//int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
void add(int x, int y) {
e[++ tot] = {y, head[x]}; head[x] = tot;
}
int dep[maxn], num[maxn], scc[maxn], cnt;
int ring;
void rope(int B, int E) {
if(dep[B] < dep[E]) swap(B, E);
for( ; dep[B] > dep[E]; )
scc[B] = 1, B = num[B];
for( ; B ^ E; )
scc[B] = scc[E] = 1, B = num[B], E = num[E];
scc[B] = 1;
ring = 1;
}
void fnd(int x, int fa) {
// cerr << x << "sadads asd\n";
if(ring == 1) return ;
num[x] = fa; dep[x] = dep[fa] + 1;
for(int i = head[x]; i ; i = e[i].nxt) {
int y = e[i].to;
if(y ^ fa) {
// cout << x << "+" << y << " " << num[y] << "\n";
if(dep[y]) {
// cerr << "sda " << x << " " << y << "\n";
rope(x, y);
ring = 1;
return ;
} else {
fnd(y, x);
}
}
}
}
int son[maxn];
void dfs(int x, int fa) {
son[x] = 1;
for(int i = head[x]; i ; i = e[i].nxt) {
int y = e[i].to;
if((y ^ fa) && !scc[y]) {
dfs(y, x);
son[x] += son[y];
}
}
}
void work() {
LL ans = 0; tot = 0; ring = 0;
n = read();
memset(head, 0, sizeof(head));
for(int i = 1, x, y; i <= n; i ++) {
dep[i] = num[i] = scc[i] = 0;
x = read(), y = read();
add(x, y); add(y, x);
}
ans = 1ll * n * (n - 1);
fnd(1, 0);
for(int i = 1; i <= n; i ++) if(scc[i] == 1) dfs(i, 0), ans -= 1ll * son[i] * (son[i] - 1) / 2;
// for(int i = 1; i <= n; i ++) cout << scc[i] << " "; cout << "\n";
printf("%lld\n", ans);
return ;
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
t = read();
while(t --) work();
return 0;
}

[CF1454] Codeforces Round #686 (Div. 3) solution的更多相关文章

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

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

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

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

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

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

  4. Codeforces Round 500 (Div 2) Solution

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

  5. Codeforces Round #607 (Div. 1) Solution

    从这里开始 比赛目录 我又不太会 div 1 A? 我菜爆了... Problem A Cut and Paste 暴力模拟一下. Code #include <bits/stdc++.h> ...

  6. Codeforces Round #578 (Div. 2) Solution

    Problem A Hotelier 直接模拟即可~~ 复杂度是$O(10 \times n)$ # include<bits/stdc++.h> using namespace std; ...

  7. Codeforces Round #525 (Div. 2) Solution

    A. Ehab and another construction problem Water. #include <bits/stdc++.h> using namespace std; ...

  8. Codeforces Round #520 (Div. 2) Solution

    A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...

  9. Codeforces Round #523 (Div. 2) Solution

    A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (sc ...

随机推荐

  1. xml在spring中

    平时用的最多的框架莫过Spring,但就算用了怎么久也一直对Spring配置文件的头部那一堆的XML Schema云里雾里的. 今天就来好好整整.俗话说,岁月是把杀猪刀,说不定哪天又忘了,好记性不如烂 ...

  2. k8s各组件启动时, -v参数指定的日志级别

    k8s 相关组件启动时 -v参数指定的日志级别 --v=0 Generally useful for this to ALWAYS be visible to an operator. --v=1 A ...

  3. STM32入门系列-复位程序

    已经对启动文有了大致了解,再来看看系统在复位过程中做了哪些工作.复位程序如下: 1 ; Reset handler 2 3 Reset_Handler PROC 4 5 EXPORT Reset_Ha ...

  4. drf 权限校验设置与源码分析

    权限校验 权限校验和认证校验必须同时使用,并且权限校验是排在认证校验之后的,这在源码中可以查找到其执行顺序. 权限校验也很重要,认证校验可以确保一个用户登录之后才能对接口做操作,而权限校验可以依据这个 ...

  5. Go语言的互斥锁Mutex

    目录 一.使用方法 二.死锁场景 1.Lock/Unlock不是成对出现 2.锁被拷贝使用 3.循环等待 一.使用方法 Mutext是互斥锁的意思,也叫排他锁,同一时刻一段代码只能被一个线程运行,两个 ...

  6. Charles使用part4——修改网络请求

    Charles提供了Map功能.Rewrite功能.Breakpoints功能,都可以达到修改服务器返回内容的目的,这三者的差异是: Map功能适合长期的将某些请求重定向到另一个网络地址或本地文件   ...

  7. C++代码雨

    闲逛的时候发现了一个很好玩的程序 摘自:https://blog.csdn.net/u012837895/article/details/20849967#comments 效果如下 #include ...

  8. drf JWT认证模块与自定制

    JWT模块 在djangorestframework中,有一款扩展模块可用于做JWT认证,使用如下命令进行安装: pip install djangorestframework-jwt 现在,就让我们 ...

  9. 对比JAVA、Python、C、Go运行时间,我惊呆了!!!

    对比JAVA.Python.C.Go运行时间,我惊呆了!!! 周末在寝室刷完算法,想放松一下,于是做了一个实验:用现在主流的几种编程语言对0 - (10000000 - 1)求和,结果我惊呆了,话不多 ...

  10. css3 渐变 兼容

    .gradient{ background: #000000; background: -moz-linear-gradient(top,  #000000 0%, #ffffff 100%); ba ...