CF Round #580(div2)题解报告

T1 T2

水题,不管

T3

构造题,证明大约感性理解一下

我们想既然存在解

\(|a[n + i] - a[i]| = 1\)

这是必须要满足的

既然这样,那么图必须是这样的

\(-\),是相邻的两个数中的较小的一个,\(+\)是相邻的两个数中较大的

这样分配是肯定有解的

但是当n时偶数的时候,手玩一下就会发现,不可能满足+-交替,所以无解

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
const int N = 5e5 + 3;
int a[N];
int n;
int main(){
n = read();
if(n & 1){
int now = 0;
for(int i = 1;i <= n;++i){
if(!now) a[i] = i * 2 - 1,a[i + n] = i * 2;
else a[i] = i * 2,a[i + n] = i * 2 - 1;
now ^= 1;
}
printf("YES\n");
for(int i = 1;i <= 2 * n;++i) printf("%d ",a[i]);
}
else printf("NO\n");
return 0;
}

T4

分位考虑

这道题的关键在于给你张图,求最小环

由于点数和边数特别少,所以直接爆搜就好了

但是考虑多项式做法

最小环的本质是对于边\((u,v)\),去掉边后\((u,v)\)的最短路径\(+1\)

这可以在floyd的过程中搞一搞

当然,这是在边有边权的前提下

这道题目直接枚举每一条边然后bfs就好了

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
using namespace std;
inline LL read(){
LL v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
const int N = 2e5 + 3;
LL a[N];
int n,ans;
int xx[65],yy[65];
int tot,rt;
struct edge{
int to;
int from;
int nxt;
}e[N << 1];
int head[N];
int deep[N],fa[N];
int book[N];
int vis[N];
inline void add(int x,int y){
e[++tot].to = y;
e[tot].nxt = head[x];
e[tot].from = x;
head[x] = tot;
}
inline void dfs(int x,int dep){
// book[x] = 1;
vis[x] = 1;
for(int i = head[x];i;i = e[i].nxt){
int y = e[i].to;
if(y == rt && dep > 2) ans = min(ans,dep);
else if(!vis[y]) dfs(y,dep + 1);
}
vis[x] = 0;
}
int main(){
//freopen("A.in","r",stdin);
//freopen("A.out","w",stdout);
n = read();
for(int i = 1;i <= n;++i) a[i] = read();
for(int i = 0;i <= 62;++i){
int sum = 0;
for(int j = 1;j <= n;++j){
if(a[j] & (1ll << i)){
if(!xx[i]) xx[i] = j;
else if(!yy[i]) yy[i] = j;
sum++;
if(sum == 3){
printf("3\n");
return 0;
}
} }
if(sum == 2) add(xx[i],yy[i]),add(yy[i],xx[i]);//printf("%d %d\n",xx[i],yy[i]);
}
ans = INF;
for(int i = 1;i <= n;++i){
dfs(rt = i,1);
if(ans == 3){
printf("3\n");return 0;
}
}
if(ans > n) printf("-1\n");
else printf("%d\n",ans);
return 0;
}

CF Round #580(div2)题解报告的更多相关文章

  1. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  2. CF1169(div2)题解报告

    CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...

  3. CF round #622 (div2)

    CF Round 622 div2 A.简单模拟 B.数学 题意: 某人A参加一个比赛,共n人参加,有两轮,给定这两轮的名次x,y,总排名记为两轮排名和x+y,此值越小名次越前,并且对于与A同分者而言 ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. CF Round #687 Div2 简要题解

    题面 A 可以发现,最远的几个人一定是 \((1, 1), (1, m), (n, 1), (n, m)\) 中的一个,直接计算即可. B 注意到颜色数量很少,直接暴力枚举最终的颜色后模拟即可. C ...

  6. Codeforces Round#704 Div2 题解(A,B,C,D,E)

    FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...

  7. A. Alyona and Numbers(CF ROUND 358 DIV2)

    A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. CodeForces round 967 div2 题解(A~E)

    本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...

  9. Codeforces Round #407 div2 题解【ABCDE】

    Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...

随机推荐

  1. sql标签和include标签的使用

    <sql>用来封装SQL语句, <include>用来调用<sql>封装的语句 代码片段: <sql id="select"> SE ...

  2. 洛谷2254 BZOJ1499 瑰丽华尔兹题解

    洛谷链接 BZ链接 一个很容易想到的做法就是用f[i][j][t]表示t时刻在i,j处的可以滑动的最大值 f[i][j][t]=max(f[i][j][t-1],f[*i][*j][t-1]),这样大 ...

  3. css面试题总结(转)

    转自此网页http://www.cnblogs.com/YangqinCao/p/5721810.html. 1.两栏布局,左边栏宽度固定,适应父元素高度变化 首先分析两栏布局, 两栏布局两种常见方法 ...

  4. 登录注册beta版

    注册 login_count = 0 username_inp = input('请输入用户名:') while login_count < 3: pwd_inp = input('请输入密码: ...

  5. Libevent:1前言

    一:libevent概述: libevent是一个用来编写快速.可移植.非阻塞IO程序的库,它的设计目标是:可移植性.高效.可扩展性.便捷. libevent包含下列组件: evutil:对不同平台下 ...

  6. docker查看运行容器详细信息

    使用docker ps命令可以查看所有正在运行中的容器列表, 使用docker inspect命令我们可以查看更详细的关于某一个容器的信息. $ docker inspect 容器id/image

  7. Uva 568 【大整数】

    UVa568 题意:求N!(N<=10000)的最后一位非0数. 10000以内5^5 = 3125最多可以影响后5位.所以直接保存后五位就行. #include<iostream> ...

  8. P4930「FJ2014集训」采药人的路径

    题目:P4930「FJ2014集训」采药人的路径 思路: 这篇不算题解,是让自己复习的,什么都没说清楚. 很久没有写点分治了,以前为了赶课件学的太急,板子都没打对就照着题解写题,导致学得很不扎实. 这 ...

  9. AIDL基本用法

    1. AIDL有什么用?用TA到目的是什么? 2. 怎么用AIDL? 1. AIDL有什么用? 1.1. 为了提高代码执行速度,将部分逻辑封入C/C++代码中  1.2. 为了调用这部分代码,使用JN ...

  10. Python多版本pip安装库的问题

    引 机器上总是会有Python2.7的版本和Python3.x的版本,今天接触到一台服务器上面有Python2.7和Python3.4,想在Python3.4下安装一个TensorFlow,但不管怎么 ...