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

Educational Codeforces Round 26

时间:2023-02-28 19:34:45浏览次数:49  
标签:Educational idx int cin Codeforces ++ 26 using include

Educational Codeforces Round 26

https://codeforces.com/contest/837

E公式推导看明白了,但是因子求解部分的代码还不是很懂,所以还没有补

A. Text Volume

#include <bits/stdc++.h>

using namespace std;

int main () {
    int n;
    string s;
    cin >> n;
    getchar ();
    getline (cin, s);
    int ans = 0, len = 0;
    for (int i = 0; i < s.size (); i++) {
        if (s[i] == ' ')    ans = max (ans, len), len = 0;
        else if (s[i] >= 'A' && s[i] <= 'Z')    len++;
    }
    ans = max (ans, len);
    cout << ans;
}

B. Flag of Berland

#include <bits/stdc++.h>

using namespace std;
const int N = 105;
char a[N][N], idx[] = {'R', 'B', 'G'};
int n, m;

bool check (int model) {
    map<char, vector<int>> mp;
    if (model) { //横
        for (int i = 1; i <= n; i++) {
            for (int j = 2; j <= m; j++) {
                if (a[i][j] != a[i][j-1])   return false;
            }
            mp[a[i][1]].push_back (i);
        }
    }
    else {
        for (int j = 1; j <= m; j++) {
            for (int i = 2; i <= n; i++) {
                if (a[i][j] != a[i-1][j])   return false;
            }
            mp[a[1][j]].push_back (j);
        }        
    }
    set<int> s;
    for (int i = 0; i < 3; i++)     s.insert (mp[idx[i]].size ());
    if (s.size () != 1)     return false;
    //检查是否连续
    int nn = *s.begin ();
    for (int i = 0; i < 3; i++) {
        for (int j = 1; j < nn; j++) {
            if (mp[idx[i]][j] - mp[idx[i]][j-1] != 1)   return false;
        }
    }
    return true;
}

int main () {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    if (check (0) || check (1))    cout << "YES\n";
    else    cout << "NO\n";
}

C. Two Seals

#include <bits/stdc++.h>

using namespace std;
const int N = 105;
int x[N], y[N], a, b, n, ans;

int main () {
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)   cin >> x[i] >> y[i];
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            //if (x[i] > a || x[j] > a || y[i] > b || y[j] > b)   break;
            int s = x[i] * y[i] + x[j] * y[j];
            if (x[i] + x[j] <= a && max (y[i], y[j]) <= b)  ans = max (ans, s);
            if (x[i] + x[j] <= b && max (y[i], y[j]) <= a)  ans = max (ans, s);
            if (y[i] + y[j] <= a && max (x[i], x[j]) <= b)  ans = max (ans, s);
            if (y[i] + y[j] <= b && max (x[i], x[j]) <= a)  ans = max (ans, s);
            if (x[i] + y[j] <= a && max (y[i], x[j]) <= b)  ans = max (ans, s);
            if (x[i] + y[j] <= b && max (y[i], x[j]) <= a)  ans = max (ans, s);
            if (y[i] + x[j] <= a && max (x[i], y[j]) <= b)  ans = max (ans, s);
            if (y[i] + x[j] <= b && max (x[i], y[j]) <= a)  ans = max (ans, s);
        }
    }
    cout << ans << endl;
}

//n^2暴力选即可

D. Round Subset

线性dp小题。把一个维度塞进数组,另一个作为值

// LUOGU_RID: 103242598
#include <bits/stdc++.h>
#define ll long long
#define vi vector<ll>

using namespace std;
const int N = 205, M = 30 * N;
ll cnt2[N], cnt5[N];
int n, k;
ll f[N][M][2]; //f[j][k]: 选了j个数,其中有k个5时, 2的数量

int main () {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        while (x % 2 == 0)   x /= 2, cnt2[i] ++;
        while (x % 5 == 0)   x /= 5, cnt5[i] ++;
        //cout << cnt2[i] << ' ' << cnt5[i] << endl;
    }
    //cout << log (1e18) / log (5) << ' ' << log (1e18) / log(2) << endl;
    memset (f, -1, sizeof f);
    f[0][0][0] = f[0][0][1] = 0;
    for (int i = 1; i <= n; i++) {
        int t = (i & 1);
        for (int j = 0; j <= min(k, i); j++) {
            for (int k = 0; k < j * 30; k++) {
                if (!j || k < cnt5[i] || f[j-1][k-cnt5[i]][t] == -1)   continue;
                f[j][k][t^1] = max (f[j][k][t^1], f[j-1][k-cnt5[i]][t] + cnt2[i]);
            }
        }
        //f.swap (tmp);
        for (int j = 0; j <= min(k, i); j++) {
            for (int k = 0; k < j * 30; k++) {
                f[j][k][t] = f[j][k][t^1];
            }
        }
    }
    ll ans = 0;
    for (ll i = 0; i < 30 * n; i++) { //cnt5
        //cout << i << ' ' << f[n][k][i] << endl;
        ans = max (ans, min (i, f[k][i][n&1]));
    }
    cout << ans << endl;
}

//min(cnt2, cnt5)

E. Vasya's Function

F. Prefix Sums

G. Functions On The Segments

标签:Educational,idx,int,cin,Codeforces,++,26,using,include
From: https://www.cnblogs.com/CTing/p/17165661.html

相关文章

  • Codeforces Round #854 by cybercats (Div. 1+2) 1799 A~G 题解
    点我看题A.RecentActions注意到只有编号大于n的博客会被更新,所以每当有一个之前没被更新的过的博客被更新时,当前列表中最下面的就会被挤掉。如果这次更新的博客之前已......
  • 1326. 灌溉花园的最少水龙头数目 (Hard)
    问题描述1326.灌溉花园的最少水龙头数目(Hard)在x轴上有一个一维的花园。花园长度为n,从点0开始,到点n结束。花园里总共有n+1个水龙头,分别位于[0,1,...,......
  • Educational Codeforces Round 112 (Rated for Div
    EducationalCodeforcesRound112(RatedforDiv.2)CodeForces-1555DSayNotoPalindromes如果一个字符串中不包含长度2以上的回文子串,我们就说这个字符串是漂亮......
  • 26. Laravel 广播 – 公有广播
    Laravel广播–公有广播配套视频地址:https://www.bilibili.com/video/av78577184配置配置驱动"pusher","redis","log","null"//.envnpminstall-......
  • 梦想Android版CAD控件(安卓CAD二次开发,安卓CAD控件)2023.02.26更新
    下载地址:https://www.mxdraw.com/ndetail_40240.html1. 增加willBeReturnStart事件2. 增加使用OpenGL缓存3. 优化界面响应时间4. 修改在个别图纸上大量的小对象图块,缩......
  • Codeforces Round #776 (Div
    CodeforcesRound#776(Div.3)CodeForces-1650DTwistthePermutation给定你数组a:123...n,一共有n次操作,每次操作可以把\(a_i\)移到最左边,然后对\(i+1\)位以......
  • 【2023-02-26】懂得硬朗
    20:00人生是花,而爱便是花的蜜。                                          ......
  • CodeForces-483D Interesting Array 线段树拆位
    让你构造一个数列,满足m种限制条件,每种限制条件是l,r,x,要求构造的序列区间[l,r] 与运算的值结果为x。注意到如果某一位上&运算的结果为1的话,该区间内所有元素都要是1先......
  • Codeforces Beta Round #19 D. Points 线段树+set
    给你一个笛卡尔坐标系,现在要支持三种操作,第一种操作是添加一个点(x,y),第二种操作是删除一个点(x,y),第三种操作是查询严格在点(x,y)右上角的点中,横坐标最小的点,如果有多......
  • 2023/02/26(日)从中国到达日本
    晚上日本时间7点降落到成田机场,接受日本的入境PCR检查,虽然是通过唾液检查,相对时间较短,但是和孩子们走的比较慢,排在队尾的位置,大约等待了两个小时,才完成检测,然后出关,坐电......