zoukankan      html  css  js  c++  java
  • AtCoder

    http://abc048.contest.atcoder.jp/tasks/arc064_b?lang=en

    在vj里面用list模拟水过去了,然后感觉vj不靠谱,上atcoder交,果然tle

    我的思路是这样的,first那个是没有必胜策略的,赢就是赢,随便拿哪一个都是赢。

    所以只需要找到有多少个能拿的就行了。用list模拟下,TLE.

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <bitset>
    #include <list>
    list<char>theList;
    const int maxn = 1e5 + 20;
    char str[maxn];
    void work() {
        scanf("%s", str + 1);
        int lenstr = strlen(str + 1);
        for (int i = 1; i <= lenstr; ++i) {
            theList.push_back(str[i]);
        }
    //    for (list<char> :: iterator it = theList.begin(); it != theList.end(); ++it) {
    //        cout << *it;
    //    }
        int ans = 0;
        while (theList.size() > 2) {
            if (theList.size() == 3 && theList.front() == theList.back()) break;
            list<char> :: iterator itBegin = theList.begin();
            itBegin++;
            list<char> :: iterator itEnd = theList.end();
            itEnd--;
            list<char> :: iterator itBeginPre = theList.begin();
            list<char> :: iterator itBeginNext = itBegin; itBeginNext++;
            bool flag = false;
            while (itBegin != itEnd) {
                if (*itBeginPre == *itBeginNext) {
                    itBeginPre++;
                    itBegin++;
                    itBeginNext++;
                } else {
                    theList.erase(itBegin);
                    flag = true;
                    break;
                }
            }
            if (!flag) break;
            ans++;
        }
    //    cout << ans << endl;
        if (ans & 1) {
            cout << "First" << endl;
        } else cout << "Second" << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        work();
        return 0;
    }
    View Code

    那么就需要快速找到有多少东西能拿,一般情况下,能拿的东西是lenstr - 2个,减去头和尾

    博弈:

    分为两种情况:

    1、头和尾相等,这个时候能拿的东西次数 - 1,

    2、头和尾不等,拿的东西次数不变

    然后判断奇偶性就好。

    那么死锁怎么办?就是像ababa

    这里能拿的个数是0,但是按照上面的,是2.

    看看基本的死锁是:aba,这样,那么再添加2个,可以形成新的死锁ababa

    注意到添加元素的个数必定要是偶数,这个不影响奇偶性。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <bitset>
    #include <list>
    list<char>theList;
    const int maxn = 1e5 + 20;
    char str[maxn];
    void work() {
        scanf("%s", str + 1);
        int lenstr = strlen(str + 1);
        lenstr -= 2;
        if (str[1] == str[strlen(str + 1)]) lenstr--;
        if (lenstr & 1) {
            cout << "First" << endl;
        } else cout << "Second" << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    android view生命周期
    ViewPager 滑动页(四)
    android 中如何获取camera当前状态
    Android LayoutInflater原理分析,带你一步步深入了解View(一)
    仿Twitter登陆移动背景效果
    Android应用性能优化之使用SQLiteStatement优化SQLite操作
    GreenDao官方文档翻译(下)
    高级IO
    linux信号
    LINUX进程
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6542518.html
Copyright © 2011-2022 走看看