Educational Codeforces Round 112 (Rated for Div. 2) A-D

A . P i z z a F o r c e s A. PizzaForces A.PizzaForces
水题,分奇偶两种情况讨论,如果是偶数的话直接/2*5,如果是奇数的话就+1再/2*5。

#include<bits/stdc++.h>
#include<ext/rope>
 
using namespace std;
using namespace __gnu_cxx;

#define int long long
#define IO ios::sync_with_stdio(false);\
           cin.tie(NULL);\
           cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)

void solve()
{
    int n;
    cin >> n;
 
    if(n < 6)
    {
        cout << 15 << '\n';
        return ;
    }
 
    if(n & 1)
    {
        cout << (n + 1) / 2 * 5 << '\n';
    }
    else
    {
        cout << n / 2 * 5 << '\n';
    }
}

signed main(){
    IO
    MULTICASE
    solve();
}

B . T w o T a b l e s B. Two Tables B.TwoTables
分情况讨论即可。

#include<bits/stdc++.h>
#include<ext/rope>
 
using namespace std;
using namespace __gnu_cxx;

#define int long long
#define IO ios::sync_with_stdio(false);\
           cin.tie(NULL);\
           cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
#define NO cout << "-1" << '\n';

void solve()
{
    double W, H, w, h, x1, x2, y1, y2;
    scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &W, &H, &x1, &y1, &x2, &y2, &w, &h);
 
    double ans = 1e9;
    double w1 = x2 - x1, h1 = y2 - y1;
 
    if(w1 + w > W && h1 + h > H)
    {
        NO
        return ;
    }
 
    if(w1 + w <= W)
    {
        if(x2 + w <= W || w <= x1)
        {
            printf("0.000000000\n");
            return ;
        }
        ans = min({ans, w - (W - x2), w - x1});
    }
 
    if(h1 + h <= H)
    {
        if(y2 + h <= H || y1 >= h)
        {
            printf("0.000000000\n");
            return ;
        }
 
        ans = min({ans, h - y1, h - (H - y2)});
    }
 
    printf("%.9lf\n", ans);
    return ;
}
 
signed main(){
    MULTICASE
    solve();
}

C . C o i n R o w s C. Coin Rows C.CoinRows
观察Alice的路线,我们可以看出Bob只能取到第一行的一个后缀或者第二行的一个前缀的硬币总和,枚举Alice向下走的位置,取出后缀和前缀的最大值,由此编程。

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define IO ios::sync_with_stdio(false);\
           cin.tie(NULL);\
           cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
#define NO cout << "-1" << '\n';

const int N = 200000 + 200;
void readarray(int *a, int n)
{
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
}

int a[2][N];
int prefix[N], suffix[N];
 
void solve()
{
    int n;
    cin >> n;
    readarray(a[0], n);
    readarray(a[1], n);
    prefix[0] = 0, suffix[n + 1] = 0;
    for(int i = 1; i <= n; i ++)
    {
        prefix[i] = prefix[i - 1] + a[1][i];
        suffix[n - i + 1] = suffix[n - i + 2] + a[0][n - i + 1];
    }
 
    int ret = 1e18;
    for(int i = 1; i <= n; i ++)
    {
        int ans = max(prefix[i - 1], suffix[i + 1]);
        ret = min(ret, ans);
    }
 
    cout << ret << '\n';
}
 
signed main(){
    IO
    MULTICASE
    solve();
}

D . S a y N o t o P a l i n d r o m e s D. Say No to Palindromes D.SayNotoPalindromes
S S S { A , B , C } \{A,B,C\} {A,B,C}的一个排列,我们只需要构造 S n S^n Sn即可使得这个字符串没有长度大于1的回文串。
像是 A B C A B C A B . . . ∣ B A C B A C B A C B . . . ABCABCAB...|BACBACBACB... ABCABCAB...BACBACBACB...
就不含有长度大于1的字符串。
了解这一点后,我们可以做出这道题。

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define IO ios::sync_with_stdio(false);\
           cin.tie(NULL);\
           cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
#define NO cout << "-1" << '\n';

const int N = 200000 + 200;
int a[6][N];
char t[N];
int b[4] = {0, 0, 1, 2};
void solve()
{
    int n, m;
    cin >> n >> m;
    cin >> t + 1;
 
    int len = strlen(t + 1), tot = 0;
    do
    {
        int j = 1;
        for(int i = 1; i <= len; i ++)
        {
            a[tot][i] = a[tot][i - 1] + (t[i] != ('a' + b[j]));
            j = j % 3 + 1;
        }
        tot ++;
    }while(next_permutation(b + 1, b + 4));
 
    for(int i = 1; i <= m; i ++)
    {
        int l, r;
        cin >> l >> r;
 
        int mi = 1e9;
        for(int j = 0; j < 6; j ++)
        {
            mi = min(mi, a[j][r] - a[j][l - 1]);
        }
 
        cout << mi << '\n';
    }
}
 
main(){
    IO
    solve();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值