Codeforces Round #575 (Div. 3)

本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧......

这次赛中A了三题

下面是本蒟蒻的题解

A.Three Piles of Candies

这题没啥好说的,相加除2就完事了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll q;
    scanf("%lld",&q);
    while(q--)
    {
        ll a,b,c;
        scanf("%lld %lld %lld",&a,&b,&c);
        printf("%lld\n",(a+b+c)/2);
    }
    return 0;
 } 

B.Odd Sum Segments

题意大概就是把长度为n的数组分成k段,每段的总和为奇数,若可以则输出YES和和每段的右边界,否则输出NO。

偶数对结果没有影响,所以只用考虑奇数。记录奇数的个数,只要每段中含有奇数个奇数就行。

那么往前面的k-1段中各放一个奇数,再把剩下的奇数放在最后一段,判断最后一段中的奇数个数是否为奇数,判断后打印前面的奇数位置和n即可。(讲的不太清楚...)

代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e6+5;
ll a[maxn];
int main() {
    ll q;
    scanf("%lld",&q);
    while(q--) {
        ll n,k;
        scanf("%lld %lld",&n,&k);
        ll cnt=0;
        for(ll i=1; i<=n; i++) {
            scanf("%lld",&a[i]);
            if(a[i]%2==1)
                cnt++;
        }
        if(cnt>=k&&(cnt-(k-1))%2==1/*判断最后一堆中的奇数个数是否为偶数*/) {
            printf("YES\n");
            ll cnt2=0;
            for(ll i=1; i<=n; i++) {
                if(cnt2>=k-1)break;
                if(a[i]%2==1) {
                    printf("%lld ",i);
                    cnt2++;
                }
                }
                printf("%lld\n",n);
        } else
            printf("NO\n");

    }
    return 0;
}

C.Robot Breakout

大概就是纯模拟吧,对于每个机器人,记录它能到达的x,y的上下界,然后取个交集,输出交集的左边界。

代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e5+5;
const ll INF=1e5;
ll a[maxn][4];//储存可达状态 ,a[i][0]为x的下界,a[i][1]为x的上界,a[i][2]为y的下界,a[i][3]为y的上界
int main()
{
    ll q;
    scanf("%lld",&q);
    while(q--)
    {
        ll n,x,y,f1,f2,f3,f4;
        scanf("%lld",&n);
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld%lld%lld%lld%lld%lld",&x,&y,&f1,&f2,&f3,&f4);
            a[i][0]=a[i][1]=x;//上下界都标记为x
            a[i][2]=a[i][3]=y;//同理
            if(f1)a[i][0]=-INF;
            if(f2)a[i][3]=INF;
            if(f3)a[i][1]=INF;
            if(f4)a[i][2]=-INF;
        }
        /*for(int i=1;i<=n;i++)
        {
            cout<<a[i][0]<<" "<<a[i][1]<<" "<<a[i][2]<<" "<<a[i][3]<<endl;
        }*/
        ll xmax=INF,xmin=-INF,ymax=INF,ymin=-INF;
        bool flag =true;
        for(ll i=1;i<=n;i++)
        {
            if(a[i][0]>xmax||a[i][1]<xmin||a[i][2]>ymax||a[i][3]<ymin)
            {
                printf("0\n");
                flag=false;
                break;
            }
            if(xmax>a[i][1])xmax=a[i][1];
            if(xmin<a[i][0])xmin=a[i][0];
            if(ymax>a[i][3])ymax=a[i][3];
            if(ymin<a[i][2])ymin=a[i][2];
        }
        if(flag)
        {
            printf("1 %lld %lld\n",xmin,ymin);
        }

    }
    return 0;
 } 

后面的题目赛中没做出来(果然还是我太菜了555)

下午补了题晚上再把个人的题解放上来

原文地址:https://www.cnblogs.com/wgqqq/p/11243637.html

时间: 2024-10-09 08:57:45

Codeforces Round #575 (Div. 3)的相关文章

Codeforces Round #575 (Div. 3) D1. RGB Substring (easy version)

Codeforces Round #575 (Div. 3) D1 - RGB Substring (easy version) The only difference between easy and hard versions is the size of the input. You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'. You are also given a

Codeforces Round #575 (Div. 3)记录

Codeforces Round #575 (Div. 3)记录 错过了上分的机会,上次不小心打了个div. 2结果直接掉了100多分. 我绿了,也变弱了.找下场Div. 3上上分吧. A 随便写了. 我的思路是三个东西先排序,一个人先拿最少的,另一个人拿次少的. 然后看剩下的能不能填补相差,如果能的话继续左右两边各补,补到剩1或0为止. 其实上面说这么多,答案就等于\(\lfloor \frac{a+b+c}{2} \rfloor\). 我是sb B 这些数与大小无关,我们直接统计有多少个奇数

【Codeforces Round #575 (Div. 3) 】 RGB Substring (hard version) ( FFT)

D2. RGB Substring (hard version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions is the size of the input. You are given a string ss cons

Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)

C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output n robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental,

Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)

B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a consisting of n integers a1,a2,-,an. You want to split it into exactly k non-empty non-intersecting

Codeforces Round #575 (Div. 3) (A. Three Piles of Candies)(数学)

A. Three Piles of Candies time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as poss

Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)

传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在“RGBRGBRGBRGB........(以RGB为循环节,我们称这个串为str)”里面也是一个子串,这个子串的长度是k 可是有可能s字符串中找不到,那么这个时候就可以改变s字符串中某些位置的字母来完成任务.问最少需要改变多少个字母 题解: 主要看暴力的姿势对不对.在上一道的D1上面,我是对s字符串的每一个位置进行‘R’,‘G’,‘B’的枚举,因为如果这个子串也是str的子串的话

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿