AtCoder - 2153 An Ordinary Game list模拟 || 博弈
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模拟 || 博弈的更多相关文章
- atcoder C - Snuke and Spells(模拟+思维)
题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- 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次操作 ...
- Atcoder Beginner Contest 115 D Christmas 模拟,递归 B
D - Christmas Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement In some ...
- AtCoder 杂题训练
前言: 因为要普及了,今年没一等就可以退役去学文化课了,所以暑假把历年noip普及组都刷了一遍,离noip还有50+天,想弄点强化训练什么的. 想了想,就这些天学文化课之余有空就把AtCoder之前那 ...
- hdu_2147_kiki's game(博弈)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意:给你一个矩阵,从右上走到左下,每次只能向左或向下或向斜下走一格,先走到最后一格的会输,问k ...
- hdu-4023-博弈(模拟)
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submis ...
- NOI前训练日记
向别人学习一波,记点流水帐.17.5.29开坑. 5.29 早晨看了道据说是树状数组优化DP的题(hdu5542),然后脑补了一个复杂度500^3的meet in the middle.然后死T... ...
- NOIP 2020 游记
第一次写比赛游记,请多多指教! I. 考前 由于最近参加了太多太多比赛了,所以没有敲模板题: 考前一周:主要是在做 AtCoder 的题和 xjoi 的模拟赛,相当于恶补了一些套路吧! 考前一天:上午 ...
随机推荐
- js中的连等==和全等===
===是没有强制类型转换的,和其他大部分语言的==是一样的.而js中==是有类型转换的. 比如说"true"==true就是错的,Boolean("false" ...
- jquery和CSS3带倒影的3D万花筒旋转动画特效效果演示
<!DOCTYPE html> <html> <head> <title></title> <meta charset='utf-8' ...
- mini_magick
https://github.com/minimagick/minimagick class https://www.rubydoc.info/github/minimagick/minimagic ...
- UIBarButtonSystemItem 各种款式
- YTU 2420: C语言习题 不等长字符串排序
2420: C语言习题 不等长字符串排序 时间限制: 1 Sec 内存限制: 128 MB 提交: 460 解决: 239 题目描述 在主函数中输入n(n<=10)个不等长的字符串.用另一函 ...
- Opencv与dlib联合进行人脸关键点检测与识别
前言 依赖库:opencv 2.4.9 /dlib 19.0/libfacedetection 本篇不记录如何配置,重点在实现上.使用libfacedetection实现人脸区域检测,联合dlib标记 ...
- 【转】设置cocos2dx 屏幕分辨率
[转载连接:]http://www.cnblogs.com/onlycxue/p/3500026.html 做手机上的软件首先要考虑的就是屏幕分辨率怎么解决.coco2dx已经有了很好的解决方法. 用 ...
- Keepalived + HAProxy 搭建【第二篇】Keepalived 的安装与配置
第一步:准备 1. 简介 本文搭建的是利用 Keepalived 实现 HAProxy 的热备方案,即两台主机上的 HAProxy 实例同时运行,其中全总较高的实例为 MASTER,MASTER出现异 ...
- 09_多线程下载_获取文件长度&计算下载范围
package com.itheima.multiThreadDownload; //import java.net.MalformedURLException; import java.io.Ran ...
- mysite-exampleservice和mysite-vsg
可能找到了这两个nova安装的地方,下午分析 搜素site_name test 这条线 cord-compute-maas-playbook这条线 这个可以作为验证