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
  • 相关阅读:
    pandas常用操作
    python读取文件并写入内容到文件
    《软件工程》学习进度博客13
    01梦断代码读后感1—上帝游戏
    软件工程学习进度博客12
    《软件工程》个人作业5----单词统计
    用户模板和用户场景
    软件工程学习进度博客11
    PHP学习3:简单的流程控制
    《软件工程》个人作业6---找水王
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6542518.html
Copyright © 2011-2022 走看看