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

Educational Codeforces Round 122 (Rated for Div. 2)

时间:2023-09-30 12:55:46浏览次数:35  
标签:Educational Rated val int vi Codeforces cin solve using

A. Div. 7

#include<bits/stdc++.h>

using namespace std;

void solve(){
    int n , a , b , c ;
    cin >> n;
    c = n % 10 , n /= 10;
    b = n % 10 , n /= 10;
    a = n % 10 , n /= 10;
    int res , val = 100;
    for( int i = 0 ; i <= 9 ; i ++ ){
        if( a != 0 and i == 0 ) continue;
        if( a == 0 and i != 0 ) continue;
        for( int j = 0 ; j <= 9 ; j ++ ){
            if( a == 0 and j == 0 ) continue;
            for( int k = 0 , x , y ; k <= 9 ; k ++ ){
                x = i * 100 + j * 10 + k;
                if( x % 7 != 0 ) continue;
                y = ( i != a ) + ( j != b ) + ( k != c );
                if( y < val  ) val = y , res = x;
            }
        }
    }
    cout << res << "\n";
    return ;
}

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


    int t;
    for( cin >> t ; t ; t -- )
        solve();
    return 0;
}

B. Minority

选整个序列操作可能对最优,如果01数量相同,少选一位就好了。

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;


void solve() {
    string s;
    cin >> s;
    int a = 0, b = 0;
    for (auto i: s)
        if (i == '0') a++;
        else b++;
    if( a == b ) cout << a - 1 << "\n";
    else cout << min( a , b ) << "\n";
    return;
}

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

C. Kill the Monster

\(k\)不大,直接枚举出增加生命值的次数,然后\(O(1)\)计算出双发把对方击败所需要的次数

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;

void solve() {
    int hc, dc, hm, dm, k, w, a;
    cin >> hc >> dc >> hm >> dm >> k >> w >> a;

    for( int i = 0 , x , y ; i <= k ; i ++ ){
        x = ( hc + i * a + dm - 1 ) / dm;
        y = ( hm + dc + ( k - i) * w - 1 ) / ( dc + ( k - i) * w );
        if( x >= y ){
            cout << "YES\n";
            return ;
        }
    }
    cout << "NO\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    for (cin >> t; t; t--)
        solve();
    return 0;
}

D. Make Them Equal

预处理出从\(1\)向后转移所需要的最小次数。然后每次统计一下答案就好了。

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int inf = 1e18;

using vi = vector<int>;

const int N = 1e3;
vi val(N + 1, inf);

void solve() {
    int n, k;
    cin >> n >> k;
    vi b(n), c(n);
    for (auto &i: b) cin >> i, i = val[i];
    for (auto &i: c) cin >> i;
    k = min( k , accumulate(b.begin(), b.end(), 0ll));
    vi f(k + 1);
    for (int i = 0; i < n; i++) {
        for (int j = k; j >= b[i]; j--)
            f[j] = max(f[j], f[j - b[i]] + c[i]);
    }
    cout << *max_element(f.begin(), f.end()) << "\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    val[1] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1, t; j <= i; j++) {
            t = i / j;
            if (i + t > N) continue;
            val[i + t] = min(val[i + t], val[i] + 1);
            if (t == 1) break;
        }
    }
    int t;
    for (cin >> t; t; t--)
        solve();
    return 0;
}

标签:Educational,Rated,val,int,vi,Codeforces,cin,solve,using
From: https://www.cnblogs.com/PHarr/p/17737743.html

相关文章

  • Educational Codeforces Round 155 (Rated for Div. 2)
    Preface这天晚上这场因为不明原因(玩CCLCC中)就没有打,只能赛后补一下这场的EF都不算难初看都有做法,但好家伙E写挂两发,F写个根号做法直接T到天上去了A.Rigged!签到题,对于所有的\(e_i\gee_1\)的\(i\),求出\(S=\maxs_i\),根据\(S+1\)和\(s_1\)的大小关系判断即可#include<cstdio......
  • Codeforces Round 695 (Div. 2)
    练习笔记:A:https://codeforces.com/contest/1467/problem/A一开始以为是987654321.....交了两发WA。慢慢想想就是如果说我是第二个号码放8就是98901234....交了就是AC B:https://codeforces.com/contest/1467/problem/BB啊,暴力打出来对于每个i,他在可能是a[i-1]-1,a[i-1]......
  • 加训日记 Day5——codeforces round 899 再战div2
    Day5,9.25,codeforcesround899div2  ·事实证明自己的思维和手速都还不够快,晚上还晚来了一点  ·B题属实是,上来就想着并查集(菜鸡是这样的)然后发现不会写捏  ·思考了很久(看数据量)感觉是枚举暴力,但是又想不到怎么去枚举  ·一题遗憾离场  ·顺理成章的-26......
  • Problem - 616C - Codeforces
    Problem-616C-CodeforcesC.TheLabyrinth如果是直接对\(*\)去跑dfs或者bfs的话无疑是会超时的既然如此,那我们可以去对\(.\)跑搜索,将各个连通的\(.\)块标号并计算出连通块内的点的数量,然后去遍历\(*\)的时候只需要上下左右跑一下计算即可啊,在\(bfs\)或\(dfs\)的时......
  • CF957 Codeforces Round 472 (rated, Div. 2, based on VK Cup 2018 Round 2)
    CF957ATritonicIridescence如果原序列中有两个相同的字符,显然不合法。如果开头或者结尾为?,或者有两个连续的?,或者一个?两边的字符不同显然合法。否则一定不合法。#include<iostream>#include<cstdio>usingnamespacestd;constintN=105;intn;chars[N];intma......
  • CF992 Codeforces Round 489 (Div. 2)
    CF992ANastyaandanArray答案为非零数的个数。#include<iostream>#include<cstdio>#include<map>usingnamespacestd;constintN=100005;intn;inta[N];map<int,int>cnt;intmain(){ scanf("%d",&n); for(inti=1;i<=n;i+......
  • CF1008 Codeforces Round 497 (Div. 2)
    CF1008ARomaji直接模拟。#include<iostream>#include<cstdio>#include<cstring>usingnamespacestd;constintN=105;intn;chars[N];intmain(){ scanf("%s",s+1); n=strlen(s+1); for(inti=1;i<=n;i++) if(s[i]!='a......
  • CF996 Codeforces Round 492 (Div. 2) [Thanks, uDebug!]
    CF996AHittheLottery直接贪心尽可能的分配到\(k_5\),剩下的依次分配给\(k_4,k_3,k_2,k_1\)。#include<iostream>#include<cstdio>usingnamespacestd;intn;intk[6];intmain(){ scanf("%d",&n); k[5]=n/100,n%=100; k[4]=n/20,n%=20; k[3]=n/1......
  • CF1011 Codeforces Round 499 (Div. 2)
    CF1011AStages每次记下上一个选的位置,贪心能填就填。#include<iostream>#include<cstdio>usingnamespacestd;constintN=55;intn,k;chars[N];intcnt[27];intmain(){ scanf("%d%d",&n,&k); scanf("%s",s+1); for(inti=1;i<=n......
  • CF1020 Codeforces Round 503 (by SIS, Div. 2)
    CF1020ANewBuildingforSIS分类讨论\(a,b\)两个端点的几种情况就好了,特判\(t_a=t_b\)的情况。#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>usingnamespacestd;intn,h,a,b,k;voidsolve(){ intta,fa,tb,fb; scanf(&qu......