首页 > 其他分享 >Educational Codeforces Round 146 (Rated for Div. 2)

Educational Codeforces Round 146 (Rated for Div. 2)

时间:2023-04-07 22:26:55浏览次数:40  
标签:146 Educational Rated int read while ch && getchar

A. Coins

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}


void solve() {
    int n = read() , k = read();
    if( n % 2 == 0 ) printf("YES\n");
    else if( k & 1 ) printf("YES\n");
    else printf("NO\n");
    return;
}

int32_t main() {
    for( int t = read() ; t ; t -- )
        solve();
    return 0;
}

B. Long Legs

枚举\(m\),\(m\)确定了答案是$m-1+\left \lceil \frac x m \right \rceil + \left \lceil \frac y m \right \rceil $

至于枚举的范围,感觉是玄学,大家随便搞的都能过

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}


void solve() {
    int x = read(), y = read() , res = x + y;
    for( int i = 1 , n = sqrt(x) + sqrt(y) + 2 ; i <= n ; i ++ )
        res = min( res , ( x + i - 1 ) / i + ( y + i - 1 ) / i + i - 1 );
    cout << res << "\n";
}

int32_t main() {
    for (int t = read(); t; t--)
        solve();
    return 0;
}

C. Search in Parallel

访问次数越多的放的位置越靠前,所以直接贪心一下就好了

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

void solve() {
    int n = read(), s1 = read(), s2 = read(), t1 = s1, t2 = s2;
    vector<pair<int, int>> p;
    vector<int> a, b;
    for (int i = 1, x; i <= n; i++)
        x = read(), p.emplace_back(x, i);
    sort(p.begin(), p.end(), greater<pair<int, int>>());
    for( auto [  w , i ] : p ){
        if( t1 < t2 ) a.push_back(i) , t1 += s1;
        else b.push_back(i) ,t2 += s2;
    }
    printf("%lld" , a.size() );
    for( auto i : a ) printf(" %lld", i );
    printf("\n%lld" , b.size() );
    for( auto i : b ) printf(" %lld", i );
    printf("\n");
    return;
}

int32_t main() {
    for (int t = read(); t; t--)
        solve();
    return 0;
}

D. Balancing Weapons

枚举一下上届\(r\),然后算一下下届\(r-k\),然后二分查找一下有多少个\(p_i\)在\([r-k,r]\)之间,在区间之外都都是要操作的。

现在其实就是要看区间外的能否通过操作移动进来,首先如果\(f_i \le k+1\)就一定可以移动进进一个宽度为\(k\)的区间,否则就要看是否满足\(\left \lfloor \frac{r}{f} \right \rfloor f \ge r-k\),这个式子可以化成\(k \ge r - \left \lfloor \frac{r}{f} \right \rfloor f = r \mod f\)。其实不难想出已经在区间内的\(p_i\)也是满足刚才的条件。所以只要判断一下所有的\(f\)时候满足即可,不用区分是区间内对应的还是区间外对应的。

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

int calc(vector<int> &a, int l, int r) {
    return upper_bound(a.begin(), a.end(), r) -
           lower_bound(a.begin(), a.end(), l);
}

void solve() {
    int n = read(), k = read();
    vector<int> f(n), d(n), a(n);
    for (auto &i: f) i = read();
    for (auto &i: d) i = read();
    for (int i = 0; i < n; i++) a[i] = f[i] * d[i];
    sort(f.begin(), f.end());
    f.resize(unique(f.begin(), f.end()) - f.begin());
    reverse(f.begin(), f.end());
    while (f.size() && f.back() <= k + 1) f.pop_back();
    sort(a.begin(), a.end());
    int res = n, r = k + 1;
    for (auto v: a) {
        for (r = max(v, r); r <= v + k; r++) {
            bool flag = true;
            for (auto u: f)
                if (r % u > k) {
                    flag = false;
                    break;
                }
            if (flag) res = min(res, n - calc(a, r - k, r));
        }
    }
    cout << res << "\n";
    return;
}

int32_t main() {
    for (int t = read(); t; t--)
        solve();
    return 0;
}

标签:146,Educational,Rated,int,read,while,ch,&&,getchar
From: https://www.cnblogs.com/PHarr/p/17297514.html

相关文章

  • Educational Codeforces Round 124 (Rated for Div. 2)
    题目链接C核心思路其实还是得根据样例,首先我们先自己分析出来。现根据边地数目来分析。我们其实不难发现四个端点必须得连上边。边数为2.那么只有两条竖线。方案数是一种边数为3,那么就一条竖线还有就是一把叉这里交换位置就是两条了。还有就是平行四边形和一条斜线,也是可以......
  • cf-edu-146b
    题目链接:https://codeforces.com/contest/1814/problem/B只有残缺的思路,还不足以解决这道题。完整思路:对于一个数x来说,如果一个数a除以它的余数为y,商为z,所需步数为y+z+(x-1),那么反过来(x变为它的商,z为除数,所需步数依然是不变的,可以举几个例子看看,易得。),所以我们只需要枚举\(n^(......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)(持续更新)
    Preface唉难得熬夜打一把还天天掉分,苦路西这把状态奇差,CD两个傻逼题都写的很慢,然后做E的时间太少最后又是经典比赛结束才调出来虽然很想骂傻逼室友打游戏鬼叫的超级响导致我注意力很难集中,不过终究还是自己抗干扰水平不够,不能怨天尤人A.BeautifulSequence傻逼题,显然若一个......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)-C
    参考了佬的c题题解思路,感觉很巧妙,记录一下https://zhuanlan.zhihu.com/p/618685370#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=2*100010;inta[N];voidsolve(){ intn,c,d; cin>>n>>c>>d; set<int>se......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)- Make It Permutation
    题目链接:Problem-C-Codeforces  #include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;#defineendl"\n"intmain(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);intT=1;cin>>T;while(......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)
    题目链接C核心思路其实这个操作无非就两种:插入和删除。我们可以把重复的元素都先删除,因为这肯定是每个操作必须要做的。我们可以从最基础的情况出发也就是怎么构造出来\(1\sima[i]\)的序列呢。肯定是吧\(i\simn\)之后的序列都删除吧,然后把前面缺少的再补上去吧。所以我们......
  • P6146 [USACO20FEB]Help Yourself G 题解
    题目链接先按左端点从小到大排序。设\(f(i)\)表示前\(i\)条线段的所有子集的复杂度之和。考虑从\(f(i-1)\)转移到\(f(i)\),即考虑新加进来第\(i\)条线段的过程。第\(i\)条线段加进来所新产生的贡献分两种:设除了第\(i\)条线段选中的线段集合为\(S\),则若\(S\)......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!) A-E
    从C题开始写好了MakeItPermutation首先我们分析假如我们确定了要选择一个长度为n的序列,该怎么计算代价很明显一个是算保留多少个一个是算要加多少个,然后如果我们算完了选择长度n-1的序列那么更新答案的时候只需要看n这个数字是否存在就可以了,然后更新一下删掉多少个数字......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)(CF1810)A~D题题解
    今天采用的是新格式。CF1810ABeautifulSequence点击查看原题点击查看思路如果一个数字的值\(v\),不大于当前的位置\(p\),那我们可以通过删除\(p-v\)个数字,使它们两个对应上。比如\([1,7,2,5,3]\)中的\(3\),其数值为\(3\),位置为\(5\),数值\(3\)小于等于\(......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!) A-D题解
    题目地址A-BeautifulSequence题意:给出一个数组,问是否存在任意一个子区间,存在i,使得ai=iSolution直接比较当前的数和i的大小就行了,当前为x,如果要求答案存在,必须有i>=xvoidsolve(){ intn;cin>>n; intflag=0; for(inti=1;i<=n;i++) { intx;cin>>x; if(i>=x) {......