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

时量 : 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. Intellij IDEA创建Maven Web项目(带有webapp文件夹目录的项目)

    每日技术点记录一下https://blog.csdn.net/mawei7510/article/details/83089268

  2. c++ 让你的应用支持相对路径

    std::string GetCurrentExeDir(){ char szPath[1024] = { 0 };#ifdef WIN32 GetModuleFileName(NULL, szPat ...

  3. 枚举的使用(限foton)

    使用: /** * 服务真实性标签 * * @param realRepairs * 真实维修单数 * @param totalRepairs * 总单数 * @return */ public st ...

  4. 庐山真面目之二微服务架构NGINX版本实现

    一.简介          在上一篇文章<庐山真面目之微服务的简介和技术栈>中,我们已经探讨了微服务的来龙去脉,也说了想要实现微服务架构所需要的技术栈,今天我们开始实现一个微服务,当然这个 ...

  5. python3爬虫应用--爬取网易云音乐(两种办法)

    一.需求 好久没有碰爬虫了,竟不知道从何入手.偶然看到一篇知乎的评论(https://www.zhihu.com/question/20799742/answer/99491808),一时兴起就也照葫 ...

  6. SVG--D3--血缘关系树

    最近的工作与可视化有关,有展示血缘关系树的需求 ,类似于这样: 碰巧搜到 D3(用于可视化的js库,作者吕之华),瞬间无法自拔,它的树状图功能基于SVG.js ,暴露的可操作入口也简洁恰当,能帮助你快 ...

  7. c#三角形

    int n = 10; for (int i = 1; i <= n; i++) { Console.Write(new string(' ', n - i)); for (int j = 1; ...

  8. 3.2spring源码系列----循环依赖源码分析

    首先,我们在3.1 spring5源码系列--循环依赖 之 手写代码模拟spring循环依赖 中手写了循环依赖的实现. 这个实现就是模拟的spring的循环依赖. 目的是为了更容易理解spring源码 ...

  9. SpringBoot第七集:异常处理与整合JSR303校验(2020最新最易懂)

    SpringBoot第七集:异常处理与整合JSR303校验(2020最新最易懂) 一.SpringBoot全局异常 先讲下什么是全局异常处理器? 全局异常处理器就是把整个系统的异常统一自动处理,程序员 ...

  10. C#两行代码实现三维地球

    一.             为什么要用三维地球? 三维地球是地理信息技术的一个重要发展方向,相比较二维地图技术,三维地球最大的特点是更直观更形象地表达地理信息和空间上的方位.我们可以在三维气象模拟. ...