传送门

题意

t组样例

n个学生,

x最多交换次数

a交换的第一个位置

b交换的第二个位置

最多是交换n-1次,不懂的话可以找个数列自己模拟一下;

然后其他的就是abs(a-b)+x;两个位置之间的距离加上次数(即变化的距离)

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int MAXN = 1e6 + 10;

signed main(){
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--){
        int n, x, a, b;
        cin >> n >> x >> a >> b;
        int max = n - 1;
        int tmp = abs(a - b);
        cout << min(n - 1, tmp + x) << endl;
    }
    return 0;
}

传送门

题意

T组样例

每次给出x,y

1.x 是偶数,可以变成3/2 * x;

2.x > 1,可以执行x - 1

如果x 是偶数并且大于1,可以选择任何一个操作(我也搞不懂他为什么要这么说,x的范围大于1,又是偶数,那么x min不就是2嘛。。。。)

操作可以执行任意次,也可以不执行

x 1 2 3 4
y 1 1,2,3, 1,2,3 3,2,1,6,5,4,9,…

输出YES的情况

如果x是1的话,那么y只能是1

如果x是2的话,x可以执行操作1,2;

执行1,那么就是3,然后只能是执行2,变成2,

执行2,那么就是1

如果x是3,x可以执行2,变成2,那么同上,1,2,3

如果x是4的话,x可以执行操作1,2;

执行1,那么就是6,

然后再是执行1,变成9,执行2,变成8,执行1,变成12.。。。

执行2,那么就是3,然后执行2,变成2,然后执行2,变成1,

这一步的时候,其实都取到了,所以我们特判一下就可以了

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int MAXN = 1e6 + 10;

signed main(){
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--){
        int a, b;
        cin >> a >> b;
        if (a == 1){
            if (a == b)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        } else if (a == 2 || a == 3){
            if (b == 2 || b == 3 || b == 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        } else
            cout << "YES" << endl;
    }
    return 0;
}

传送门

说一下这个题吧,让人爱恨不得,刚开始的时候,看了一眼。然后理解了能分成几个子集QAQ,至于为什么,看到了括号,然后就这样了



今晚和王队讨论的时候,说起了这个题,原来是求相同的两个数之间的最短的距离,数据范围2e5;

所以呢,写了写2333

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
int vis[maxn], a[maxn];
int len;
signed main(){
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T, n;
    cin >> T;
    while (T--){
        memset(vis,0,sizeof(vis));
        cin >> n;
        if (n == 1){
            cin >> a[1];
            cout << "-1" << endl;
        }
        else {
            len = 0x3f3f3f3f;
            for (int i = 1; i <= n; i++) {
                cin >> a[i];

                if (vis[a[i]])
                    len = min(len, i - vis[a[i]] + 1);
                vis[a[i]] = i;
            }
            if (len != 0x3f3f3f3f)//预防1 2 3 4 5这种情况
                cout << len << endl;
            else
                cout << "-1" << endl;
        }

    }
    return 0;
}

cf 76 div2的更多相关文章

  1. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  2. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

  3. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  4. CF#581 (div2)题解

    CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...

  5. [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)

    题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...

  6. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

  7. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  8. CF R303 div2 C. Woodcutters

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. CF 192 Div2

    A.Cakeminator 暴搞之,从没有草莓覆盖的行.列遍历 char map[30][30]; int vis[30][30]; int hang[30],lie[30]; int main() ...

随机推荐

  1. DVWA全级别之XSS(Reflected)、XSS(Stored)【跨站脚本攻击】

    XSS XSS,全称Cross Site Scripting,即跨站脚本攻击,某种意义上也是一种注入攻击,是指攻击者在页面中注入恶意的脚本代码,当受害者访问该页面时,恶意代码会在其浏览器上执行,需要强 ...

  2. E. Vus the Cossack and a Field (求一有规律矩形区域值) (有一结论待证)

    E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...

  3. biquad filter实现

    原始频谱: LPF: HPF: 代码: #include<stdio.h> #include<stdlib.h> #include<errno.h> #includ ...

  4. Visual Studio 2017:SQLite/SQL Server Compact ToolBox使用

    1.首先是下载安装插件:SQLite/SQL Server Compact Toolbox,也可以从工具-->扩展和更新-->联机-->搜索:SQLite/SQL Server Co ...

  5. IntelliJ IDEA 2017.3尚硅谷-----显示行号和方法分隔符

  6. CDH安装错误集锦

      CDH安装过程中出现的错误 1.iptables: /sbin/iptables 不存在 我是因为误删将 /sbin/下的文件删除了. 解决方法: yum install iptables 2.c ...

  7. Nuxt项目文件目录结构解释

    |-- .nuxt // Nuxt自动生成,临时的用于编辑的文件,build |-- assets // 用于组织未编译的静态资源入LESS.SASS 或 JavaScript |-- compone ...

  8. FloatingActionButton 实现类似 闲鱼 App 底部导航凸起按钮

    一.Flutter FloatingActionButton 介绍 FloatingActionButton 简称 FAB,可以实现浮动按钮,也可以实现类似闲鱼 app 的地步凸起导航   child ...

  9. Python - Git for windows 下使用 交互式命令行

    1. 概述 尝试在 windows 环境的 git 命令行使用 python3 的交互模式 2. 环境 OS win10 1905 git 2.20.1 mintty 2.9.4 python 3.7 ...

  10. 【资源分享】Half-Life(半条命)中英版

    *----------------------------------------------[下载区]----------------------------------------------* ...