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 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
随机推荐
- Redis 学习笔记(篇七):Redis 持久化
因为 Redis 是内存数据库,它将自己的数据储存在内存里面,所以如果不想办法将储存在内存中的数据库状态保存到磁盘里面,那么一旦服务器进程退出,服务器中的数据也将会丢失,为了解决这个问题,Redis ...
- HttpClientFactory 使用说明 及 对 HttpClient 的回顾和对比
目录 HttpClient 日常使用及坑点: HttpClientFactory 优势: HttpClientFactory 使用方法: 实战用法1:常规用法 1. 在 Startup.cs 中进行注 ...
- 【网站公告】.NET Core 版博客站点第二次发布尝试
在上次发布失败后,很多朋友建议我们改用 k8s ,但我们还是想再试试 docker swarm ,实在不行再改用 k8s . 在改进了 docker swarm 集群的部署后,我们准备今天 17:30 ...
- spring boot 加载自定义log4j 文件路径
spring boot 使用log4j 打印时,需首先去除自带 Logger ,然后加入log4j 依赖 <dependencies> <!-- https://mvnreposit ...
- android ——悬浮按钮及可交互提示
一.悬浮按钮 FloatingActionButton是Design Support中的一个控件,它会默认colorAccent作为按钮的颜色,还可以给按钮一个图标. 这是没有图标的,这是有图标的. ...
- 【JS档案揭秘】第二集 Event loop与执行栈
我时常在思考关于JS的很多知识在工作中有什么用?是否只能存在于面试这种理论性的东西中,对于我们的业务和工作,它们又能扮演怎样的角色.以后在JS档案揭秘的每一期里,都会加入我对于业务的思考,让这些知识不 ...
- C#使用NLOG System.TypeInitializationException,类型初始值设定项引发异常
C#如何使用NLOG,网上有很多介绍,本次使用时遇到一个问题,使用NLOG写日志时,出现初始化异常,基本异常信息如下: System.AggregateException: 发生一个或多个错误. -- ...
- Android开发之输入框EditText介绍
这篇文章主要为大家详细介绍了Android布局之输入框EditText设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 现在先简单介绍一下技术点: 1.如何使用圆角输入框和按钮背景 2.如何实现 ...
- python聚类算法解决方案(rest接口/mpp数据库/json数据/下载图片及数据)
1. 场景描述 一直做java,因项目原因,需要封装一些经典的算法到平台上去,就一边学习python,一边网上寻找经典算法代码,今天介绍下经典的K-means聚类算法,算法原理就不介绍了,只从代码层面 ...
- HOWTO: Avizo/Amira/Pergeos中如何利用Volume Edit
操作非常简单,就是利用Volume Edit取圆柱的同时可以取一个Mask(或称之为ROI,感兴趣区域,蒙板等) 如上图,利用Volume Edit取一个圆柱,然后点击Create Mask创建一个M ...