CodeForces#287 div.2 题解

本文涵盖了信息技术领域的多个子领域,包括前端开发、后端开发、移动开发等,详细介绍了每个子领域的重要技术和工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A题:

题意:第一行给出两个数n,m,第二行有n个数据,求最少需要多少个数使这几个数的和不小于m,并输出这几个数的从小到大位置。

思路:排序,选择最大的数,并输出。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
struct node{
    int val;
    int num;
    friend bool operator < ( const node& a, const node& b ){
        return a.val < b.val;
    }
}num[10005];
int main()
{
    ios::sync_with_stdio( false );
    int n, m;
    while ( cin >> n >> m ){
        clr ( num, 0 );
        for ( int i = 0; i < n; i ++ ){
            cin >> num[i].val;
            num[i].num = i + 1;
        }
        sort ( num, num + n );
        int cnt = -1;
        for ( int i = 0; i < n; i ++ ){
            if ( m >= num[i].val ){
                m -= num[i].val;
                cnt = i;
            }
        }
        if ( cnt == -1 ){
            cout << "0" << endl;
            continue;
        }
        else{
            cout << cnt + 1 << endl;
            vector<int> tmp;
            for( int i = 0; i <= cnt; i ++ ){
                tmp.push_back( num[i].num );
            }
            sort ( tmp.begin(), tmp.end() );
            cout << tmp[0];
            for ( int i = 1; i < tmp.size(); i ++ ){
                cout << ' ' << tmp[i];
            }
            cout << endl;
        }
    }
    return 0;
}


B题:

题意:给出圆心坐标和圆的半径,以圆上某点旋转,求最少要几步将圆心能移动到指定坐标。

思路:求圆心坐标和指定坐标的距离,求倍数的上界

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);

int main()
{
    ios::sync_with_stdio( false );

    double n;
    double x_1, x_2, y_1, y_2;
    while ( cin >> n >> x_1 >> y_1 >> x_2 >> y_2 ){
        n *= 2;
        double ans = sqrt ( ( x_1 - x_2 ) * ( x_1 - x_2 ) + ( y_1 -y_2 ) * ( y_1 - y_2 ) );
        ans = ( ans + n - 0.0000001 ) / n;
        cout << (int)ans << endl;
    }

    return 0;
}


C题:

题意:每棵树有n层,从根结点(第0层)按LRLRLR的顺序深搜遍历,第n层的第m个节点是第几个遍历到的节点

思路:先自底向上判断路径方向,若为奇数,则是L路径,若为偶数,为R路径,再从顶层开始判断,求是否为正常路径,如果是正常路径,则到下一层(第i层)节点,并且序号+1,若不是正常路径,则序号+(2^(n-i))+1,一直到目标节点。输出结果。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);

int main()
{
    ios::sync_with_stdio( false );

    ll m, n;
    while ( cin >> m >> n ){
        ll tmp = 1;
        ll ans = 0;
        for ( int i = 0; i < m; i ++ ){
            tmp *= 2;
        }
        char s[1000];
        tmp --;
        tmp += n;
        n = tmp;
        m ++;
        ans = 1;
        ll num = 0;
        tmp = n;
        while ( tmp > 1 ){
            if ( tmp & 1 ){
                s[num++] = 'R';
            }
            else{
                s[num++] = 'L';
            }
            tmp /= 2;
        }
        s[num] = '\0';
        char ch = 'L';
        for ( ll i = num - 1; i >= 0; i -- ){
            if ( ch == s[i] ){
                ans ++;
                if ( ch == 'L' ) ch = 'R';
                else ch = 'L';
            }
            else{
                tmp = 1;
                for ( ll j = 0; j < m - ( num - i ); j ++ ){
                    tmp *= 2;
                }
                tmp -= 1;
                ans += tmp;
                ans ++;
            }
        }
        cout << ans - 1 << endl;
    }

    return 0;
}

D题:



E题:


(未完待续)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值