CodeForces Round 525
A:Ehab and another construction problem
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ; int main(){
int x;
scanf("%d", &x);
for(int i = ; i <= x; ++i)
for(int j = ; j <= x; ++j){
if(i%j == && i*j > x && i/j < x){
cout << i << ' ' << j << endl;
return ;
}
}
cout << - << endl;
return ;
}
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int a[N];
int main(){
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i)
scanf("%d", &a[i]);
sort(a+, a++n);
int val = , b = ;
for(int i = ; i <= m; ++i){
while(b <= n && val >= a[b])
++b;
if(b > n)
puts("");
else {
printf("%d\n", a[b]-val);
val = a[b];
}
}
return ;
}
题意:要求构造一个严格递增序列。
题解:一共最多有n+1次操作,所以我们从后往前每次构造第i个数, 把他构造成对%n之后的余数为(i-1)。 最后再对整个数列%n就好了。
代码:
Copy
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int n;
int a[N];
struct Node{
int op, l, r;
};
vector<Node> ans;
int main(){
scanf("%d", &n);
for(int i = ; i <= n; ++i)
scanf("%d", &a[i]);
int val = ;
for(int i = n; i >= ; --i){
a[i] += val;
int t = a[i]%n;
if(t == i-) continue;
t = (n+(i-) - t);
val += t;
ans.pb({, i, t});
}
ans.pb({, n, n});
printf("%d\n", ans.size());
for(auto it : ans){
printf("%d %d %d\n", it.op, it.l, it.r);
}
return ;
}
D:Ehab and another another xor problem
交互题。
题解:
我们可以通过输出 0 0 来判断 a 和 b的大小。
然后我们考虑ab的二进制。
从高位往地位枚举
将第i位^1之后, 如果 a和b的亦或后的大小没发生改变, 则说明第i位是一样01码的。
将第i位^1之后, 如果 a和b的亦或后的大小发生了变化, 那么就说明第i位的01码是不一样的,并且原来大的那个数第i位是1,记录下这一位的变化, 然后前面这一位考虑进去之后,重新询问接来下的剩下位数的ab大小。
经过上面的操作,我们就确定了不一样的位置的信息,然后在去找同意位置上的信息就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int t, val, f = ;
int ans1, ans2;
int vis[N];
int xx = , yy = ;
int gg(int x, int y){
x ^= xx; y ^= yy;
if(x > y) return ;
if(x ==y) return ;
return -;
}
int main(){
printf("? 0 0\n");
fflush(stdout);
scanf("%d", &t);
f = t;
for(int i = ; i >= && f != ; --i){
int o1 = << i;
int o2 = o1 ^ val;
printf("? %d %d\n", o1, o2);
fflush(stdout);
scanf("%d", &t);
if(f == ){
if(t == -){
val ^= o1;
ans1 ^= o1;
vis[i] = ;
printf("? %d %d\n", , val);
fflush(stdout);
scanf("%d", &f);
}
}
else if(f == -){
if(t == ){
val ^= o1;
ans2 ^= o1;
vis[i] = ;
printf("? %d %d\n", , val);
fflush(stdout);
scanf("%d", &f);
}
}
}
for(int i = ; i >= ; --i){
if(vis[i]) continue;
int o1 = << i;
int o2 = val;
printf("? %d %d\n", o1, o2);
fflush(stdout);
scanf("%d", &t);
if(t == -){
ans1 ^= o1;
ans2 ^= o1;
}
}
printf("! %d %d\n", ans1, ans2);
fflush(stdout);
return ;
}
E:Ehab and a component choosing problem
题意:在一颗树上,每个点都有权值, 你可以选择k个联通块, 使得 所有选得的点的和/k的值最大, 在保证值最大的前提下, k最大。
题解:所有选择的点/k 。 我们考虑这个东西, 肯定就是 这k个块的值都是一样的。并且我们需要保证这值是图中最大的值。
那么我们可以通过dfs找到这个值最大是多少。
然后在通过dfs去check最多有多少个这种块。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 3e5 + ;
int a[N];
vector<int> vc[N];
LL ans = _INF;
LL dfs1(int o, int u){
LL val = a[u];
for(int v : vc[u]){
if(v == o) continue;
val += max(0ll, dfs1(u,v));
}
ans = max(ans, val);
return val;
}
int k = ;
LL dfs2(int o, int u){
LL val = a[u];
for(int v : vc[u]){
if(v == o) continue;
val += max(0ll, dfs2(u,v));
}
if(val == ans) ++k, val = ;
return val;
}
int main(){
int n;
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
for(int i = ,u,v; i < n; ++i){
scanf("%d%d", &u, &v);
vc[u].pb(v); vc[v].pb(u);
}
dfs1(,);
dfs2(,);
cout << 1ll * ans * k << ' ' << k << endl;
return ;
}
F:Ehab and a weird weight formula
题意:给定一棵树,每个节点有权值,并且只有所有权值中,最小值的点只有一个。 并且除了最小值的那个点, 其他的点连向的点中,一定有一个点的 v[u] < v[i]。现在要求你重构这棵树,然后使得
1. 每个点的度数 * v[i] + 2. 对与新图的每条边的{u,v} -> log(dis(u,v)) * min(a[u], a[v]) 所有和最小。
题解:
我们需要证明一个东西,即从权值最小的那个点出发之后, 对于某条链来说,深度越大的点的权值一定大于深度小的点。
假如存在一条链: A -> B -> C -> D
A是其中最小的点。
我们假设 v[B] > v[A], v[C] < v[B]
因为需要满足题目给定的那个条件, 所以 v[D] < v[C]。
那么对于D来说也需要存在一个点的值是小于D的, 但是不存在这种点, 所以这个假设是矛盾的。
我们可以简单证得 从最小点出发, 他的值是递增的。
然后我们倍增跑一下每个点的每层祖先是什么就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 5e5 + ;
int v[N];
LL ans = ;
int anc[N][];
vector<int> vc[N];
void dfs(int o, int u){
anc[u][] = o;
for(int i = ; i < ; ++i) anc[u][i] = anc[anc[u][i-]][i-];
if(o){
LL tmp = INF;
for(int i = ; i < ; ++i){
tmp = min(tmp, 1ll*v[anc[u][i]]*(i+));
}
tmp += v[u];
ans += tmp;
}
for(int v : vc[u]){
if(v == o) continue;
dfs(u, v);
}
}
int main(){
int n;
int rt = ;
scanf("%d", &n);
for(int i = ; i <= n; ++i){
scanf("%d", &v[i]);
if(v[i] <= v[rt]) rt = i;
}
for(int i = ,u,v; i < n; ++i){
scanf("%d%d", &u, &v);
vc[u].pb(v);
vc[v].pb(u);
}
v[] = v[rt];
// cout << "bug" << endl;
dfs(, rt); printf("%lld\n", ans);
return ;
}
CodeForces Round 525的更多相关文章
- Codeforces Round #525 (Div. 2)
Codeforces Round #525 (Div. 2) 哎,忍不住想吐槽一下,又要准备训练,又要做些无聊的事,弄得我都想退出了. 好好的训练不好么???? 只能做出两道水题,其实C题,感觉做出来 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #525 (Div. 2)-A/B/C/E
http://codeforces.com/contest/1088/problem/A 暴力一波就好了. //题解有O(1)做法是 (n-n%2,2) #include<iostream> ...
- Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- Codeforces Round #525 (Div. 2)后俩题
E:https://codeforces.com/contest/1088/problem/E dp+贪心 题目大意:选择一个k并且选择k个连通块,要求sigma a[i]/k最大,k尽量大,对于给定 ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...
- Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task
传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...
- Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数 联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
随机推荐
- 【有容云】PPT | 容器落地之二三事儿
编者注: 本文为10月29日有容云联合创始人兼研发副总裁江松在 Docker Live时代线下系列-广州站中演讲的PPT,本次线下沙龙为有容云倾力打造Docker Live时代系列主题线下沙龙,每月一 ...
- C# 10分钟完成百度语音技术(语音识别与合成)——入门篇
我们已经讲了人脸识别(入门+进阶).图片识别(入门).下面是链接: C# 10分钟完成百度人脸识别——入门篇 C# 30分钟完成百度人脸识别——进阶篇(文末附源码) C# 10分钟完成百度图片提取文字 ...
- javaweb入门-----jsp概念
jsp是什么? JSP:Java Server Pages java服务器端页面 *可以理解为 一个特殊的页面,其中既可以直接定义html标签,又可以定义java代码 *用于简化书写 <% %& ...
- HDP Hive性能调优
(官方文档翻译整理及总结) 一.优化数据仓库 ① Hive LLAP 是一项接近实时结果查询的技术,可用于BI工具以及网络看板的应用,能够将数据仓库的查询时间缩短到15秒之内,这样的查询称之为Int ...
- 并发知识(2)——关于Thread
一些容易混淆的知识点 sleep vs wait sleep是Thread,wait是Object方法 wait和notify只能在同步代码块中调用 wait释放锁资源,sleep不释放锁资源 唤醒条 ...
- linux CPU100%异常排查
1.top查找出占CPU比例最高的进程(5881): 2.查看该进程正在执行的线程: top -H -p 5881 3.将线程转换成16进制 printf ‘%x\n’ 5950 4.查看异常线程执 ...
- HTML/CSS:div居中和div内部元素垂直居中(1)
div居中 div水平和垂直居中,text-align和vertical-align不起作用,因为标签div没有这两个属性,所以再css中设置这两个值不能居中的效果 1. div水平居中:设置marg ...
- Kafka集群配置---Windows版
Kafka是一种高吞吐量的分布式发布订阅的消息队列系统,Kafka对消息进行保存时是通过tipic进行分组的.今天我们仅实现Kafka集群的配置.理论的抽空在聊 前言 最近研究kafka,发现网上很多 ...
- selenium中的setUp,tearDown与setUpClass,tearDownClass的区别
def setUpClass(cls): cls.driver = webdriver.Chrome() cls.driver.maximize_window() def setUp(self): s ...
- 最大层内元素和----leetcode周赛150_1002
题目描述: 给你一个二叉树的根节点 root.设根节点位于二叉树的第 1 层,而根节点的子节点位于第 2 层,依此类推. 请你找出层内元素之和 最大 的那几层(可能只有一层)的层号,并返回其中 最小 ...