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. UI标签库专题三:JEECG智能开发平台 FormValidation(表单提交及验证标签)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhangdaiscott/article/details/28484209  自己定义弹出框提示 ...

  2. [转]GPS经纬度的表示方法及换算

    想要认识GPS中的经纬度,就必须先了解GPS,知道经纬度的来源: 1. GPS系统组成 GPS是 Gloabal Positioning System 的简称,意为全球定位系统,主要由地面的控制站.天 ...

  3. i MySQL 查看约束,添加约束,删除约束

    查看表的字段信息:desc 表名; 查看表的所有信息:show create table 表名; 添加主键约束:alter table 表名 add constraint 主键 (形如:PK_表名) ...

  4. Codeforces Round #326 (Div. 2)

    B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. darwin Stream Server源码分析

    摘要 ​所谓的流式媒体简单的讲就是指人们通过网络实时的收看多媒体信息:如音频流.视频流等.与流式媒体对应的传统工作方式是下载+播放模式,即用户首先下载多媒体文件,然后再在本地播放,这种方法的一个主要缺 ...

  6. JavaScript-Tool:Ext JS

    ylbtech-JavaScript-Tool:Ext JS extjs是一种软件.自动生成行号,支持checkbox全选,动态选择显示哪些列,支持本地以及远程分页,可以对单元格按照自己的想法进行渲染 ...

  7. BZOJ3990 排序

    题目:www.lydsy.com/JudgeOnline/problem.php?id=3990 这题很不错. 刚开始时无从下手,想了好多$O((2^n)log(2^n))$ 的idea,但是都不行. ...

  8. Design with the User in Mind--从用户角度进行设计

    Back to Human Interface Design Design with the User in Mind 从用户角度进行设计 The success of a Mac app depen ...

  9. 4种java复制文件的方式

    尽管Java提供了一个可以处理文件的IO操作类,但是没有一个复制文件的方法.复制文件是一个重要的操作,当你的程序必须处理很多文件相关的时候.然而有几种方法可以进行Java文件复制操作,下面列举出4中最 ...

  10. Ruby主要方法

         方法定义        def hello(name) ...  end                                                函数名 参数 作用 备 ...