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 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
随机推荐
- 抓取崩溃的log日志
1.下载adb工具包 也就是解锁软件,如果要解锁的话,需确认有fastboot 安装jdk.sdk 2.注意事项 请确保电脑上只连接了一台手机设备(最好只连接一条USB线),同时确保手机已开启USB调 ...
- Confluence未授权模板注入/代码执行(CVE-2019-3396)
--- title: Confluence未授权模板注入/代码执行(CVE-2019-3396) tags: [poc,cve] num :g7y12 --- # 简介 --- Confluence是 ...
- Struts2 中Struts.xml结果页面配置
结果页面的配置: 红色的比较常用
- gcd, exgcd的证明
- Spring文档学习
Spring文档学习 参考Spring Framework Documentation学习 1. IoC 容器 1.1 容器实例化 <beans> <import resource= ...
- @Value注解 和 @Data注解
@Value注解 service层代码 @Service public class HelloServiceImpl implements HelloService { @Autowired priv ...
- HomeKit智能球泡
产品名称: 智能LED灯泡调光调色 接入苹果HomeKit家庭(无需网关).天猫精灵.小爱.小度.Google.ALEXA 产品价格:9.9 本产品是针对HomeKit的产品,没有iphone手机,配 ...
- 分布式ID系列(5)——Twitter的雪法算法Snowflake适合做分布式ID吗
介绍Snowflake算法 SnowFlake算法是国际大公司Twitter的采用的一种生成分布式自增id的策略,这个算法产生的分布式id是足够我们我们中小公司在日常里面的使用了.我也是比较推荐这一种 ...
- JS判断字符串长度,结合element el-input el-form 表单验证(英文占1个字符,中文汉字占2个字符)
首先看看判断字符串长度的几种方法(英文占1个字符,中文汉字占2个字符) 方法一: function strlen(str) { var len = 0; for (var i = 0; i < ...
- vscode 配置 nodejs 开发环境
1.配置 cnpm 镜像 (国内淘宝镜像网速更快) npm install -g cnpm --registry=https://registry.npm.taobao.org 2.配置智能提示 安装 ...