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 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
随机推荐
- AI中台——智能聊天机器人平台的架构与应用(分享实录)
内容来源:宜信技术学院第3期技术沙龙-线上直播|AI中台——智能聊天机器人平台 主讲人:宜信科技中心AI中台团队负责人王东 导读:随着“中台”战略的提出,目前宜信中台建设在思想理念及架构设计上都已经取 ...
- java基础知识总结,绝对经典
写代码: 1,明确需求.我要做什么? 2,分析思路.我要怎么做?1,2,3. 3,确定步骤.每一个思路部分用到哪些语句,方法,和对象. 4,代码实现.用具体的java语言代码把思路体现出来. 学习新技 ...
- 递归&分治&贪心
递归 Recursion:通过函数体来进行的循环. 思路简单但效率低(建立函数的副本,消耗大量时间和内存).能用迭代就不用递归.递推公式+递推终止条件. 计算n阶乘,递归实现 def Factoria ...
- nginx在线与离线安装
1.场景描述 项目要部署到新的服务器上,需要安装nginx,刚好安全部门通知了nginx存在安全漏洞(Nginx整数溢出漏洞,nginx1.13.2之后的版本无问题),就下载最新的nginx进行了安装 ...
- 分享一个非常好用又好看的终端工具--Hyper (支持windows、MacOS、Linux)
分享一个非常好用又好看的终端工具--Hyper 官网地址: https://hyper.is/ 打开官网,选择对应版本安装即可:(可能网络原因,无法下载, 可以从我分享的链接下载 链接: https: ...
- SonarQube系列二、分析dotnet core/C#代码
[前言] 本系列主要讲述sonarqube的安装部署以及如何集成jenkins自动化分析.netcore项目.目录如下: SonarQube系列一.Linux安装与部署 SonarQube系列二.分析 ...
- mysql注意事项
注意事项: 1.查询条件内需要使用时间的,不要使用数据库函数now(),都使用应用服务器传入: 2.所有id为mysql自增的,需要使用创建时间排序,都使用order by id desc;或者根据查 ...
- Spring入门(九):运行时值注入
Spring提供了2种方式在运行时注入值: 属性占位符(Property placeholder) Spring表达式语言(SpEL) 1. 属性占位符 1.1 注入外部的值 1.1.1 使用Envi ...
- 自定义GroupBox
public partial class mGroupBox : GroupBox { private Color _TitleBackColor = Color.Black; private Fon ...
- UWP实现吸顶的Pivot
话不多说,先上效果 这里使用了一个ScrollProgressProvider.cs,我们这篇文章先解析一下整体的动画思路,以后再详细解释这个Provider的实现方式. 结构 整个页面大致结构是 & ...