2021.01.23 Rating赛 补题&解题报告

A

题目大意:给出每位医生的s,d,每位医生只有在si, si + di, si + 2di, ....工作,按顺序访问医生,一天只能访问一位,求访问完所有医生需要多少天

解题思路:按顺序模拟,先输入医生的总人数,第一个医生的s,d,while循环模拟每一天,如果天数符合,输入下一个医生的s,d,直到所有医生都访问完。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum=0,s,d,t=0;
    cin>>n;
    cin>>s>>d;
    while(1){
        t++;
        if(t>=s&&(t-s)%d==0){
            n--;
            if(n==0){
                break;
            }
            cin>>s>>d;
        }
    }
    cout<<t<<endl;
    return 0;
}

B

题目大意:给出n个人,开始第一个与第二个打,数大的继续跟下一个打,数小的去队伍后边,直到有人连续赢了k局,输出这个人的值

解题思路:如果k>=n,则一定打了一圈以上,则输出最大的一个,

k<n,将所有人放到队列里模拟,找符合条件的那一个

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,i,maxx=-1,a;
    cin>>n>>k;
    queue<long long> q;
    for(i=0; i<n; i++)
    {
        cin>>a;
        q.push(a);
        maxx=max(a,maxx);
    }
    if(n<=k)
    {
        cout<<maxx<<endl;
    }
    else
    {
        long long x,y,x1=0,y1=0;
        x=q.front();
        q.pop();
        y=q.front();
        q.pop();

        while(x1<k&&y1<k)
        {
            if(x>y)
            {
                q.push(y);
                y=q.front();
                q.pop();
                y1=0;
                x1++;
            }else if(x<y)
            {
                q.push(x);
                x=q.front();
                q.pop();
                x1=0;
                y1++;
            }
        }
        if(x1==k)
        {
            cout<<x<<endl;
        }
        if(y1==k)
        {
            cout<<y<<endl;
        }
    }
    return 0;
}

C

位运算的化简

(呜呜呜比赛的时候就没看懂题目QAQ)

(位运算理解的不够深入XD)

参考大佬代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    a = 0,b = 1023;
    int n;
    scanf("%d",&n);
    char s[100];
    int num;
    while(n--)
    {
        scanf("%s%d",s,&num);
        if(s[0] == '|')
        {
            a |= num;
            b |= num;
        }
        else if(s[0] == '&')
        {
            a &= num;
            b &= num;
        }
        else if(s[0] == '^')
        {
            a ^= num;
            b ^= num;
        }
    }
    int num_and = 0,num_or = 0,num_xor = 0;
    num_and = a | b;//0->0,1->1,可以与上b二进制表示中1的部分
    num_or = a & b;//0->1,1->1,两个二进制中都是1的部分
    num_xor = a & (b ^ 1023);//0->1,1->0,两个二进制中都变成1的部分
    printf("3\n");
    printf("| %d\n",num_or);
    printf("& %d\n",num_and);
    printf("^ %d\n",num_xor);
    return 0;
}
View Code

 

posted @ 2021-01-24 22:43  一只幽灵飘过  阅读(70)  评论(0编辑  收藏  举报