Codeforces Round 665 (div2)
2020.8.22
装修完了我的博客,喜欢这个造型,挂上友链就更好了

昨天cf就是一个彻头彻尾的悲剧,本来能上蓝,结果因为在A题耽误时间过多导致掉了30分,不过没关系,这算是一个小波动吧,影响不了什么,现在稳定到每场3题打底了,下场打回来就行了。、
A题. Distance and Axis
这道题我刚跟朋友聊完天,乍一看有些懵,想了半个小时最后才出来。谢谢木下巨佬给的tips,就是首先观察到当OB 变动1,那么差距变动2,所以我们一定是需要一个偶数的差距才能不移动,如果n比m大,那么挪过去就行了,其实很简单,但是当时怎么也想象不出这个动作

#include <bits/stdc++.h>
using namespace std;
#define limit (10000000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int n,kase,m;
int a[limit];
int main() {
#ifdef LOCAL
FOPEN;
#endif
cin>>kase;
while (kase--){
cin>>n>>m;
if(n < m){
cout<<abs(n - m)<<endl;
}else if((n - m) & 1){
cout<<1<<endl;
}else{
cout<<0<<endl;
} }
return 0;
}
AC Code
B题. Ternary Sequence
这道题就是问怎么安排序列使得序列和最大,给出来了规则,那么就看啊,首先肯定是2越多越好,而且只有2,因为无论是1还是0乘积都只可能有0,好的。然后用剩下的1互相抵消,因为避免对方的2和己方1结合扣分,然后用1减0,最后安排不了的才和2结合从答案中减去,就不用管了,反正其余对答案的贡献铁定为0,这个逻辑好绕啊,我昨天不知道是怎么硬着头皮写出来的,代码太丑陋了,但还是过了。听说有人写完79行if else直接关电脑的,

#include <bits/stdc++.h>
using namespace std;
#define limit (10000000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int n,kase,m;
int a,b,c;
int main() {
#ifdef LOCAL
FOPEN;
#endif
cin>>kase;
while (kase--){
int x,y,z;
cin>>x>>y>>z;
cin>>a>>b>>c;
ll ans = 0;
int minn2 = min(z,b);
ans += minn2 * 2;
b -= minn2, z -= minn2;
int minn = min(y,a);
a-=minn,y-=minn;
minn2 = min(z,c);
z -= minn2, c -= minn2;
minn = min(y,b);
y -= minn, b -= minn;
minn = min(a,x);
a -= minn, x -= minn;
ans -= min(y,c) * 2; cout<<ans<<endl; }
return 0;
}
AC Code
C题 Mere Array
这题问的是如果序列里任意两个元素的gcd等于最小值就能交换,问能不能变成非严格上升序列。首先说升序,那么就想到sort一遍拷贝之后的数组,然后比较,那么一个元素能换到其本身应该所处位置的充要条件是这个数字能够整除最小值,所以做法如下,往常的话我今天已经铁蓝了,但A耽误时间太长了,还wa了两次,到C的排名才3k9,今天必须做到d才能不掉分

#include <bits/stdc++.h>
using namespace std;
#define limit (10000000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int n,kase,m;
int a[limit];
int f[limit];
int main() {
#ifdef LOCAL
FOPEN;
#endif
cin>>kase;
while (kase--){
cin>>n;
int minn = INF;
int flag = 1;
rep(i,1,n){
cin>>a[i]; minn = min(minn, a[i]);
f[i] = a[i];
}
sort(f + 1, f + 1 + n);
flag = 0;
rep(i ,1,n){
if(a[i] != f[i] && a[i] % minn != 0){
flag = 1;
cout<<"NO"<<endl;
break;
}
}
if(!flag){
cout<<"YES"<<endl;
}
}
return 0;
}
AC Code
D题. Maximum Distributed Tree
D题是给出一棵树,然后给出若干个乘积为k的质因子,问怎么才能让∑i=1|n-1∑j=i+1|n f(i,j)最大,其中f(u,v)为从u到v的链上的权值,这道题刚开始我觉得可能是树链剖分,直接优先往重链上放prime factor,但是想了下这样做似乎不妥,1e5您打算怎么统计呢?之后队友说是不是可以统计边的使用次数,一语点醒梦中人,使用次数最多的优先安排大prime factor不就好了?那么这个使用次数,通过手动模拟法发现,对于任意一点u,u以上的节点想要走到任意u为根的子树节点,那么必须要经过这条边,次数也就好固定了,是子节点size * (n - 子节点size)。我给每条边打上一个号,从1-n-1,然后开个数组记录,用堆优先选取次数达的,然后考虑n -1小于m的情况,将后面的贡献全给第一个就行了,难得d的思路能这么清晰,然后大草就发生了,数组开小了tle,最后没交上,赛后一发过了????这事儿怎么老发生在我和weeping demon身上?????然后掉了36,下次再打回来就是了

#include <bits/stdc++.h>
using namespace std;
#define limit (500000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int sizes[limit], head[limit<<1] ,cnt; struct node{
int to, next, num;
}edge[limit<<1];
void init(){
memset(head, -1, sizeof(head));
cnt = 0;
}
void add(int u ,int v,int num){
edge[cnt].to = v;
edge[cnt].next = head[u];
edge[cnt].num = num;
head[u] = cnt++;
}
ll dp[limit];
int n;
void dfs(int u, int pre){
sizes[u] = 1;
for(int i = head[u]; ~i; i = edge[i].next){
int v = edge[i].to;
if(v != pre) {
dfs(v, u);
sizes[u] += sizes[v];
dp[edge[i].num] = (sizes[v]) * (n - sizes[v]);
}
}
}
int kase,m;
ll fact[limit];
int main() {
#ifdef LOCAL
FOPEN;
#endif
FASTIO
cin>>kase;
const ll mod = 1e9 + 7;
while (kase--){
cin>>n;
init();
rep(i,1,n-1){
int x,y;
cin>>x>>y;
add(x,y,i);
add(y,x,i);
}
cin>>m;
rep(i,1,m){
cin>>fact[i];
}
sort(fact + 1, fact + 1 + m, greater<>());
dfs(1,1);
priority_queue<ll>q;
rep(i,1,n-1){
q.push(dp[i]);
}
if(n -1 < m){//如果小于
rep(i,n,m){
((fact[1] %= mod) *= (fact[i] %= mod)) %= mod;
}
m = n - 1;
}
ll ans = 0;
rep(i ,1,m){
ans += (q.top() * fact[i]) % mod;
ans %= mod;
q.pop();
}
while (q.size()){
ans += q.top();
ans %= mod;
q.pop();
}
cout<<(ans + mod) % mod<<endl;
}
return 0;
}
AC Code
Codeforces Round 665 (div2)的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round #665 (Div. 2)
Codeforces Round #665 (Div. 2) A. Distance and Axis 如果\(B\)在\(O\)左边,那么只能是定值\(OA\) 如果\(B\)在\(OA\)中间 ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
随机推荐
- 832. Flipping an Image —— weekly contest 84
Flipping an Image Given a binary matrix A, we want to flip the image horizontally, then invert it, a ...
- 3.6 栈 ADT - 3.7 队列 ADT
3.6 栈 ADT 栈是限制插入和删除只能在一个位置上进行的表,叫做栈的顶部.对栈的基本操作有进栈和出栈,进栈在顶部插入元素,出栈删除最后插入的元素. 栈是一个表,因此任何实现表的方法都能实现栈.显然 ...
- 通过Portwigge的Web安全漏洞训练平台,学习SSRF
前言 Portswigger是Burpsuite的官网,也是一个非常好的漏洞训练平台.其Web安全靶场地址为:https://portswigger.net/web-security/ 该靶场的训练内 ...
- leetcode24:word-ladder-ii
题目描述 给定两个单词(初始单词和目标单词)和一个单词字典,请找出所有的从初始单词到目标单词的最短转换序列: 每一次转换只能改变一个单词 每一个中间词都必须存在单词字典当中 例如: 给定的初始单词st ...
- JVM常用调优工具介绍
前言 王子在之前的JVM文章中已经大体上把一些原理性问题说清楚了,今天主要是介绍一些实际进行JVM调优工作的工具和命令,不会深入讲解,因为网上资料很多,篇幅可能不长,但都是实用的内容,小伙伴们有不清楚 ...
- CentOS 8.x 下尝试安装.Net 5 的运行时
1.背景 看着不管是群里还是公众号里这几天最热闹就是.Net 5.0 正式版的发布.C#9. 当然要开发.net 5.0 的项目就需要把VisualStudio升级的v16.8.0版本了.升级后自带着 ...
- 内网渗透 day5-msf本地提权(windows)
msf本地提权 目录 1. 利用uac提权 1 2. 绕过uac认证 2 3. 利用windows本地提权漏洞进行提权 4 1. 利用uac提权 前提与目标机建立会话连接 seach local/as ...
- VirtualBox上桥接方式安装CentOS之后借助宿主上网
VirtualBox上桥接方式安装CentOS之后借助宿主上网: 修改centos文件: 1 vi /etc/sysconfig/network-scripts/ifcfg-eth0 增加以下几项: ...
- WIN10下安装python3.7.2出现“尝试创建C:\Users\XX\AppData\Roaming\Microsoft\Installer时出错”
WIN10下安装python3.7.2出现"尝试创建C:\Users\XX\AppData\Roaming\Microsoft\Installer时出错" 1.右键点击安装包以管理 ...
- deepin 20安装后系统没有声音解决方案(亲测有效)
打开终端: sudo vi /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT原有配置后面添加 snd_hda_intel.dmic_detect=0 即GRUB ...