QFNU-ACM 2020.10.30 Trating

A

n如果为偶数,输出n/2个'2',n如果为奇数,n/2-2个,一个3

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<n/2<<endl;
    for(int i=1; i<n-2; i+=2)
    {
        cout<<"2 ";
    }
    if(n%2==0){
        cout<<"2"<<endl;
    }else{
        cout<<"3"<<endl;
    }
    return 0;
}

B

给出三个点的坐标,求能与这三个点组成平行四边形的点

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ture true
int main() {

    int a1,a2,b1,b2,c1,c2;
    cin>>a1>>a2;
    cin>>b1>>b2;
    cin>>c1>>c2;

    cout<<3<<endl;
    cout<<a1+(b1-c1)<<" "<<a2+(b2-c2)<<endl;
    cout<<b1+(c1-a1)<<" "<<b2+(c2-a2)<<endl;
    cout<<c1+(a1-b1)<<" "<<c2+(a2-b2)<<endl;
    return 0;
}

C

共有n个人,编号为1~n。他们每个人属于且仅属于R阵营或N阵营中的一个。现在他们要进行一场投票。轮到某人投票时,可以选择使一人丧失投票权。进行多轮投票,直到只剩下一方阵营的人。

每个人都选择投掉自己后边第一个敌人,

参考大佬代码:

把两个阵营的编号存入队列,比较两个队列开头的元素,模拟

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ture true
int main()
{
    int n;
    string s;
    cin>>n>>s;
    queue<int>qd,qr;
    for(int i=0;i<n;i++){
        if(s[i]=='D'){
            qd.push(i);
        }else{
            qr.push(i);
        }
    }
    while(!qd.empty()&&!qr.empty()){
        if(qd.front()<qr.front()){
            qr.pop();
            qd.push(qd.front()+n);//下一圈
            qd.pop();//用完了出队
        }else{
            qd.pop();
            qr.push(qr.front()+n);
            qr.pop();
        }
    }
    if(qd.empty()){
        cout<<"R"<<endl;
    }else{
        cout<<"D"<<endl;
    }
    return 0;
}

D

判断出发地,与终点是否为一家机场,如果是输出0,不是输出1

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ture true
int main() {

    int n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    if(s[a-1]!=s[b-1]){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

E

让我们考虑以下生成整数序列的算法。一开始我们有一个由一个等于1的元素组成的序列。然后执行(n - 1)步。在每一步中,我们取上一步得到的序列,把它附加到它自身的末尾,并在中间插入我们以前没有用过的最小正整数。例如,第一步后得到序列[1,2,1],第二步后得到序列[1,2,1,3,1,2,1]。任务是在得到的序列中找到索引为k的元素的值(元素从1开始编号),即经过(n - 1)步。

找规律可得,k如果等于2i,输出i+1,否则k- 2i-1,继续循环比较

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ture true
int main() {

    //0 1 1+0 2 2+0 2+1 2+1+0 3
    ll n,m,i,flag=0;
    cin>>n>>m;
    while(flag==0)
    {
        for(i=0;; i++)
        {
            if(m==pow(2,i))
            {
                cout<<i+1<<endl;
                flag=1;
                break;
            }
            else if(m<pow(2,i))
            {
                break;
            }
        }
        m-=pow(2,i-1);
        //cout<<"**"<<i-1<<endl;
    }

    return 0;
}

F

如果n=1,输出-1

n不为1,输出n,n+1,n*(n+1),此时等式一定成立

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ture true
int main()
{
    int n;
    cin>>n;
    if(n==1){
        cout<<"-1"<<endl;
    }else{
    cout<<n<<" "<<n+1<<" "<<n*(n+1)<<endl;
    }


    return 0;
}
原文地址:https://www.cnblogs.com/a-specter/p/13945375.html