zoukankan      html  css  js  c++  java
  • 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都挂掉了, 下一篇博客里面说明情况

  • 相关阅读:
    发送短信验证(防刷新)
    JsRender 学习总结
    JsRender (js模板引擎)
    jQuery中ready与load事件的区别
    web端图片文件直传
    2018面对对象_作业三
    2018面对对象_作业二
    2018面对对象_作业一
    2018寒假作业_4(自我总结)
    2018寒假作业_3(电梯版本二)
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7911236.html
Copyright © 2011-2022 走看看