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 + ;
char str[maxn];
void work() {
scanf("%s", str + );
int lenstr = strlen(str + );
for (int i = ; i <= lenstr; ++i) {
theList.push_back(str[i]);
}
// for (list<char> :: iterator it = theList.begin(); it != theList.end(); ++it) {
// cout << *it;
// }
int ans = ;
while (theList.size() > ) {
if (theList.size() == && 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 & ) {
cout << "First" << endl;
} else cout << "Second" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

那么就需要快速找到有多少东西能拿,一般情况下,能拿的东西是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 + ;
char str[maxn];
void work() {
scanf("%s", str + );
int lenstr = strlen(str + );
lenstr -= ;
if (str[] == str[strlen(str + )]) lenstr--;
if (lenstr & ) {
cout << "First" << endl;
} else cout << "Second" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

AtCoder - 2153 An Ordinary Game list模拟 || 博弈的更多相关文章

  1. atcoder C - Snuke and Spells(模拟+思维)

    题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...

  2. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE 【模拟+博弈】

    题目:戳这里 题意:A和B博弈,三种操作分别是x:加a,y:减b,z:取相反数.当x或y或z为0,说明该操作不可取,数据保证至少有一个操作可取,给定一个区间(l,k)和原始数字m,如果A和B在n次操作 ...

  4. Atcoder Beginner Contest 115 D Christmas 模拟,递归 B

    D - Christmas Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement In some ...

  5. AtCoder 杂题训练

    前言: 因为要普及了,今年没一等就可以退役去学文化课了,所以暑假把历年noip普及组都刷了一遍,离noip还有50+天,想弄点强化训练什么的. 想了想,就这些天学文化课之余有空就把AtCoder之前那 ...

  6. hdu_2147_kiki's game(博弈)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意:给你一个矩阵,从右上走到左下,每次只能向左或向下或向斜下走一格,先走到最后一格的会输,问k ...

  7. hdu-4023-博弈(模拟)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

  8. NOI前训练日记

    向别人学习一波,记点流水帐.17.5.29开坑. 5.29 早晨看了道据说是树状数组优化DP的题(hdu5542),然后脑补了一个复杂度500^3的meet in the middle.然后死T... ...

  9. NOIP 2020 游记

    第一次写比赛游记,请多多指教! I. 考前 由于最近参加了太多太多比赛了,所以没有敲模板题: 考前一周:主要是在做 AtCoder 的题和 xjoi 的模拟赛,相当于恶补了一些套路吧! 考前一天:上午 ...

随机推荐

  1. HTML5 and Websocket

    在HTML5规范中,我最喜欢的Web技术就是正迅速变得流行的WebSocket API.WebSocket提供了一个受欢迎的技术,以替代我们过去几年一直在用的Ajax技术.这个新的API提供了一个方法 ...

  2. 获取Android系统应用信息

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  3. aop+自定义注解

    自定义注解,并且实现,需要两个文件: 自定义注解类: package com.clc.server.annotation; import java.lang.annotation.ElementTyp ...

  4. 阶乘问题(大数阶乘)简单 n! (一个大数与一个小数相乘的算法 、一个大数与一个小数的除法算法 *【模板】 )

    sdut oj 简单n! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给定一个数n(0 <= n <= 150), ...

  5. HDU4292 Food —— 最大流 + 拆点

    题目链接:https://vjudge.net/problem/HDU-4292 Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  6. POJ3621 Sightseeing Cows 最优比率环 二分法

    题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total ...

  7. assign.py

    #链式赋值 m=n=[1,2,3] m[0]=2 print(m,n) #m,n都改变了 x=y='xxx' y='yyy' print(x,y) #只有y 改变 #序列解包 x,y,z=1,2,3 ...

  8. BZOJ_5311_贞鱼_决策单调性+带权二分

    BZOJ_5311_贞鱼_决策单调性+带权二分 Description 众所周知,贞鱼是一种高智商水生动物.不过他们到了陆地上智商会减半. 这不?他们遇到了大麻烦! n只贞鱼到陆地上乘车,现在有k辆汽 ...

  9. 【NOIP16提高组】换教室

    [题目链接] 点击打开链接 [算法] 概率DP 先跑一遍floyed,求出每个教室之间的最短路径,存在数组dist[][]中,时间复杂度O(V^3) 设计状态,f[i][j][k]表示当前选到第i个教 ...

  10. A. Transformation: from A to B

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...