首页 > 其他分享 >Educational Codeforces Round 100

Educational Codeforces Round 100

时间:2023-09-15 17:34:33浏览次数:42  
标签:Educational int Codeforces long -- solve startX using 100

B. Find The Array

对于条件二来说,1 是万金油的存在,所以我们只需要把奇数位置或偶数位置全部变成 1 即可。因为要求差值小于\(\frac s 2\),所以我可以求出奇偶位的和修改较小值即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int, int>;

constexpr int inf = 1e9;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for( auto &i : a ) cin >> i;
    int x = 0 , y = 0 , t ;
    for( int i = 0 ; i < n ; i ++ ){
        if( i & 1 ) x += a[i];
        else y += a[i];
    }
    t = x <= y;
    for( int i = 0 ; i < n ; i ++ ){
        if( (i&1) == t ) cout << "1 ";
        else cout << a[i] << " ";
    }
    cout << "\n";
    return ;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    for( cin >> t ; t ; t -- )
        solve();

    return 0;
}

C. Busy Robot

模拟即可,要注意满足要求的判定条件。

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int inf = 1e18;


void solve() {
    int n;
    cin >> n;
    vector<int> t(n + 2), x(n + 2);
    for (int i = 1; i <= n; i++)
        cin >> t[i] >> x[i];
    t[n + 1] = inf;
    int startT = 0, endT = 0, startX = 0, endX = 0, res = 0;
    for (int i = 1; i <= n; i++) {
        if (t[i] >= endT) {
            startX = endX, endX = x[i];
            startT = t[i], endT = startT + abs(endX - startX);
            if (endT <= t[i + 1]) {
                res++;
            }
        } else {
            int d = (endX - startX) / abs(endX - startX);
            int lx = startX + d * (t[i] - startT), rx = startX + d * (min( endT , t[i + 1]) - startT);
            if (lx > rx) swap(lx, rx);
            if (((x[i] > startX) == (endX > startX)) and lx <= x[i] and x[i] <= rx) {
                res++;
            }
        }
    }
    cout << res << "\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    int t;
    cin >> t;
    for (; t; t--)
        solve();

    return 0;
}

D. Pairs

这道题其实可以贪心的做,只要求出\(x\)的最大值和最小值即可。现在的问题是如何求出最值?其实一个比较简单的做法是,直接进行贪心的匹配,优先给较小值匹配一个更大的数,这样就可以知道\(x\)的最大值。反过来操作就是最小值。

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int, int>;
using vi = vector<int>;
#define mp make_pair
constexpr int inf = 1e18;

void solve() {
    int n;
    cin >> n;
    vi v(2 * n + 1);
    for (int i = 1, x; i <= n; i++)
        cin >> x, v[x] = 1;
    int l = 0, r = n;
    for (int i = 1, cnt = 0; i <= n * 2; i++) {
        if (v[i]) {
            if (cnt) cnt--;
            else l++;
        } else cnt++;
    }
    for (int i = n * 2, cnt = 0; i >= 1; i--) {
        if (v[i]) {
            if (cnt) cnt--;
            else r--;
        } else cnt++;
    }
    cout << r - l + 1 << "\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    for (cin >> t; t; t--)
        solve();

    return 0;
}

标签:Educational,int,Codeforces,long,--,solve,startX,using,100
From: https://www.cnblogs.com/PHarr/p/17705567.html

相关文章

  • DW1000的PLL失锁问题
    DW1000的PLL失锁问题说明​ 许多DW1000用户在研发测试过程中读取芯片状态寄存器时,会发现芯片上述的两个PLL_LL位出现了置位情况。通过阅读旁边的说明可以了解到,该位置位说明PLL出现了失锁情况,芯片运行可能出现了故障。但对于失锁是什么意思,故障要怎么排查,这个故障会影响什么?很......
  • codeforces图论合集
    CyclicOperations给定一个数组$a$,每次构造一个数组$\spacel\space$长度为$\spacek\space$,数组$\spacea\space$与$\spacel\space$转换关系如下:$a_{l_1}\tol_2\space,\spacea_{l_2}\tol_3\space,\spacea_{l_3}\tol_4\space,\space...\space,\spacea_{l_n}\tol_1$......
  • Codeforces Round 897 (Div. 2) 考试总结
    前言这次打得很好,相较于div3的脑残题和签到题来说,div2的思维难度更加的大。同时还有除传统题外,其他的题型出现。比如交互题等。这次能在考场上想出三道较于之前是有很大的进步的。赛时实况:ABCDE1E2F√√√××××赛后改题情况:ABCDE1E2F......
  • 综合实力再获认可!巨杉数据库蝉联2023「Cloud 100 China」榜单
    巨杉数据库凭借在分布式文档型数据库领域的技术实力及商业市场拓展方面的优异表现再度荣登「Cloud100China」榜单,体现了业界对其在基础设施平台领域的高度认可。近日,由靖亚资本和崔牛会联合主办的2023「Cloud100China」榜单发布暨线下峰会在上海举办,本次评选活动由国内外Clou......
  • Codeforces 1868C/1869E Travel Plan 题解 | 巧妙思路与 dp
    题目链接:TravelPlan题目大意:\(n\)个点的完全二叉树,每个点可以分配\(1\simm\)的点权,定义路径价值为路径中最大的点权,求所有路径的价值和。对于任意长度(这里主要指包括几个节点)的路径\(t\),最大点权不超过\(k\)的方案数有\(k^t\)个,因此最大点权恰好为\(k\)的方案数有......
  • Codeforces Round 781 (Div. 2) B. Array Cloning Technique
    给一个长度为\(n\)的数组\(a\)。开始只有一份所给\(a\)的副本。你可以做以下两种操作:选择任意一个副本并且克隆它,然后将会多出一个克隆副本。交换两个元素,他们属于任意两个副本(可能是同一个)。需要判断最小操作数,使有一个副本的所有元素相同。观察一:只需要在开始的副本......
  • Codeforces Round 787 (Div. 3) B. Make It Increasing
    给一个长为\(n\)的数组\(a_1,a_2,\cdots,a_n\quad(0\leqa_i\leq10^9)\)。可以执行以下操作任意次:选择任意一个\(a_i\)并且执行\(a_i=\lfloor\frac{a_i}{2}\rfloor\)。输出最小操作次数,使得数组所有元素变为严格递增。观察:数组一些位置变小,将数组变为严......
  • 特斯拉100G数据泄露事件:系内部员工违规操作
    近日,特斯拉向其员工以及美国执法部门通报了“100G数据泄露事件”的具体规模及原因。这起今年5月份发生的大规模数据泄露事件影响了逾7.5万人,其中包括与员工相关的各种敏感信息,而这一切竟然源自“内部员工的不法行为”。内部员工违规致使泄露事件调查显示,两名特斯拉前员工违反了特斯......
  • Codeforces Round 791 (Div. 2) A. AvtoBus
    已知有\(n\)个轮子,会有一个车队车来换轮,且恰好使用完这些轮子。只知道这些车中有\(4\)轮车和\(6\)轮车。你需要估计这个车队最少可能有多少车和最多可能有多少车,或判断这是完全不可能的。观察:\(4x+6y=n\),由裴蜀定理,当\(2\midn\)有解且\(2x+3y=\frac{n}{2}\)......
  • Codeforces Round 897 (Div. 2)
    目录写在前面ABCDE1/E2F写在最后写在前面比赛地址:https://codeforces.com/contest/1867。简略题解。还好没掉分。A令原数列中第\(k\)大对应\(k\)即可。///*By:Luckyblock*/#include<bits/stdc++.h>#defineLLlonglongconstintkN=4e4+10;//============......