BestCoder Round #22 【题解】

昨天做了场bc。很是惨烈。

1.一个数二进制翻转过来是多少。easy。orz一分钟秒掉的大神。

code:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
#define INT long long

const int N = 50;
int main()
{
    INT n;
    int T;
    cin >> T;
    while(T -- && cin >> n){
        int arr[N];
        int top = 0;
        while(n){
            arr[top ++] = n % 2;
            n = n / 2;
        }
        INT ans = 0;
        for(INT i = top - 1, k = 1; i >= 0; i --, k = k * 2){
            ans += arr[i] * k;
        }
        cout << ans << endl;
    }
    return 0;
}

2.是hack阶段最high的一题,我们房间最后留下1个。- -。

题目意思:1的个数有a1个,2的个数有a2个,3的个数有a3个,4的个数有a4个。问你所有的数能不能组成x(x为任意数)个等差数列(可以为常数数列),且每个等差数列的长度不小于3。

自己yy了一个思路,后来发现是错的 - -。(错的也太离谱了)

题解看了以后。

我们知道 只可能出现123,234,1234和常数数列这四种。

而且如果 123 234 1234任一出现次数>=3的时候,都可以把他化成常数数列。所以 我们就可以枚举他们三种出现0-2的情况。就ok了。

code:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int a1, a2, a3, a4;
bool solve()
{
    for(int i = 0; i < 3; i ++){
        for(int j = 0; j < 3; j ++){
            for(int k = 0; k < 3; k ++){
                int cnt1 = i + k;
                int cnt2 = i + j + k;
                int cnt3 = i + j + k;
                int cnt4 = j + k;
                int x1 = a1 - cnt1;
                int x2 = a2 - cnt2;
                int x3 = a3 - cnt3;
                int x4 = a4 - cnt4;
                if((x1 == 0 || x1 >= 3) && (x2 == 0 || x2 >= 3) && (x3 == 0 || x3 >= 3) && (x4 == 0 || x4 >= 3))
                    return true;
            }
        }
    }
    return false;
}

int main()
{
//    freopen("1.txt", "r", stdin);
    int T;
    scanf("%d", &T);
    while(T --){
        scanf("%d %d %d %d", &a1, &a2, &a3, &a4);
        if(solve()) puts("Yes");
        else puts("No");
    }
    return 0;
}

3题是一个物理奥赛题。最后弄到一个公式。提交了一发,out of contest。 - -。final test 后竟然ac了。

不过真心捉急捉急的物理知识。(表示物理已经忘光了)。

code:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

const double g = 9.8;
double h, v0;
int main()
{
    int T;
    scanf("%d", &T);
    while(T --){
        scanf("%lf %lf", &h, &v0);
        double ans = v0 * sqrt(v0 * v0 + 2.0 * g *h ) / g;
        printf("%.2lf\n", ans);
    }
    return 0;
}

4题,听说是一个莫队算法。表示只听说过,还是需要学习的。。。!!!


ps;

1.平常比赛还是这样,debug太多。这绝对是一个问题,很值的注意的一个问题。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值