Codeforces 893 A B 比赛 思维


  题目链接:http://codeforces.com/contest/893

  A:Chess For Three

  题目描述:一共有三个人在玩游戏,1号和2号先玩,3号看着,输的那个和看的那个换。然后给一个序列表示每一局赢的人是谁,问合不合法。

  解题思路: 模拟

  代码:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iterator>
using namespace std;

const int maxn = 105;
int a[maxn];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }    
    int spec = 3;
    int b1 = 1, b2 = 2;
    for(int i = 1; i <= n; i++) {
        if(a[i] != b1 && a[i] != b2) {
            cout << "NO" << endl;
            return 0;
        }    
        if(a[i] == b1) {
            swap(b2, spec);
        }
        else {
            swap(b1, spec);
        }
    }
    cout << "YES" << endl;
    return 0;
}
View Code

  B:Beautiful Divisors

  题目描述:定义一个“美丽数”表示二进制下可以表示成连续k+1个1和连续k个0,然后对于每一个n求出他因子里面的美丽数最大是多少,因为1是美丽数,所以一定有解。

  解题思路: 先预处理出来所有的美丽数, 再从美丽数中从大到小找是否为因子

  代码:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

const int maxn = 1e4;
int cnt = 0;
int bea[maxn];
void table() {
    int k = 1;
    int temp = 1;
    while(temp <= 100000) {
        bea[cnt++] = temp;
        k++;
        temp = (pow(2,k)-1)*(pow(2,k-1)); 
    }    
}

int main() {
    table();
    int n;
    cin >> n;
    int res = 1;
    for(int i = cnt-1; i >= 0; i--) {
        if(n >= bea[i] && n % bea[i] == 0) {
            res = bea[i];
            break;
        }
    }
    cout << res << endl;
    return 0;
}
View Code

  思考: 是两道水题, 剩下的C, D也是可以做的, 自己做了C, D都挂掉了, 下一篇博客里面说明情况

优质内容筛选与推荐>>
1、【转一篇出处不明的文章】 Windows多线程通信方式
2、035-R树(一)
3、Problem P(方格移动)
4、seq2seq
5、python 十进制转换成任意进制


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn