[CF1454] Codeforces Round #686 (Div. 3) solution
标签(空格分隔): 经验 题解
时量 : 2h
概括 :
\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的更多相关文章
- Codeforces Round #466 (Div. 2) Solution
从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...
- 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution
对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...
- Codeforces Round #545 (Div. 1) Solution
人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...
- Codeforces Round 500 (Div 2) Solution
从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...
- Codeforces Round #607 (Div. 1) Solution
从这里开始 比赛目录 我又不太会 div 1 A? 我菜爆了... Problem A Cut and Paste 暴力模拟一下. Code #include <bits/stdc++.h> ...
- Codeforces Round #578 (Div. 2) Solution
Problem A Hotelier 直接模拟即可~~ 复杂度是$O(10 \times n)$ # include<bits/stdc++.h> using namespace std; ...
- Codeforces Round #525 (Div. 2) Solution
A. Ehab and another construction problem Water. #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #520 (Div. 2) Solution
A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...
- Codeforces Round #523 (Div. 2) Solution
A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (sc ...
随机推荐
- 转 js调用提交表单。
今天做网银支付的时候,需要做到点击支付的时候提交订单,然后新窗口打开支付界面. 思路1:window.open(''),这个直接被pass了,因为银行的服务一般都是需要post数据的.就算是可以用ge ...
- 浅析软件测试人员如何对JVM进行内存溢出检测
一.什么是JVM,检测JVM的意义 JVM是java virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各 ...
- python打印水仙花数的个人总结
面试过程中,提到python,面试最多的就是让你现场写代码实现水仙花.冒泡.九九乘法表,这些面试方法旨在校验面试者的python基础和思维逻辑. 先从水仙花说起,水仙花是指一个n位正整数(n>= ...
- 编写shell脚本的规范
目录 编写shell脚本的一些规范 解释器 添加脚本版本和注释功能 添加脚本调试 变量命名 全局变量和局部变量 命名规范 函数命名 脚本命名 函数 引用模块或文件 脚本日志 配置文件 其他 编写she ...
- Java学习的第九天
1.双色球联系: 对象的创建和使用 2.静态没太明白. 3.明天学习java 的方法
- 循序渐进VUE+Element 前端应用开发(26)--- 各种界面组件的使用(2)
在我们使用Vue+Element开发前端的时候,往往涉及到很多界面组件的使用,其中很多直接采用Element官方的案例即可,有些则是在这个基础上封装更好利用.更少代码的组件:另外有些则是直接采用第三方 ...
- numpy数组
一.数组创建 基础数组 1.array() array函数可以创建一维或多维数 一维数组 1.arange(起始值,终值,步长) 2.linspace(起始值,终值,元素个数) --创建等步长的数组 ...
- OpenCV计算机视觉学习(10)——图像变换(傅里叶变换,高通滤波,低通滤波)
如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 在数 ...
- shell脚本实现---Zabbix5.0快速部署
shell脚本实现---Zabbix5.0快速部署 zabbix-server快速安装脚本 #!/bin/bash #Zabbix-Server 5.0#author:sunli#mail:sunli ...
- 看得见的成本!1款工具实现K8S资源成本监控可视化
本文来自Rancher Labs 关注我们,第一时间获取技术干货 计算Kubernetes成本的复杂性 采用Kubernetes和基于服务的架构可以为企业带来诸多好处,如团队可以更快地迁移以及应用程序 ...