其他分享
首页 > 其他分享> > QFNU-ACM 2020.10.30 Trating

QFNU-ACM 2020.10.30 Trating

作者:互联网

CodeForces - 743B

这个题第一次超时了,因为奇数下标可以直接输出1的,应该先判断。第二次wa了因为没用long long

先列举出n<4的这些情况

n  l 

1  1   1

2  3   121

3  7   1213121

4  15 121312141213121

#include<bits/stdc++.h>
#define ll long long
#include<string>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    speed_up;
    ll n,k;
    cin>>n>>k;
    ll l;
    if(k%2==1)
    {
        cout<<1<<endl;//奇数下标一定是1
    }
    else
    {
        while(n>0)
        {
            l=pow(2,n)-1;//找规律发现求l的公式
            if(k==l/2+1)
            {
                cout<<n<<endl;
                break;
            }
            else if(k>l)//如果大于总长的一半就减去总长的一半,这样只需要判断前半段
            {
                k-=l;
                k--;
            }
            else if(k<l)
            {
                n--;//一层一层的往上判断
            }
        }
    }
}

CodeForces - 743C

没想出来,看了一下题解

构造

n=1时没有符合的三个数,是特例

 

 

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

 int main()
{
    speed_up;
    int n;
    cin>>n;
    if(n==1)cout<<-1<<endl;
    else cout<<n+1<<" "<<n*(n+1)<<" "<<n<<endl;
}

 

标签:QFNU,Trating,cout,int,30,cin,long,else,include
来源: https://www.cnblogs.com/SyrupWRLD999/p/13906066.html